Skip to content

Commit

Permalink
Add ReactRootViewTagGenerator (#43882)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #43882

Changelog: [Added] Add ReactRootViewTagGenerator

This copies over a modified version of the [react-native-windows](https://github.com/microsoft/react-native-windows/blob/main/vnext/Microsoft.ReactNative/Modules/ReactRootViewTagGenerator.h) implementation so it can be shared with other C based platforms

This also updates the outdated comment about the non existing ReactIOSTagHandles JS module.

Differential Revision: D55772580
  • Loading branch information
christophpurrer authored and facebook-github-bot committed Apr 4, 2024
1 parent fd3ef7b commit 0925e9b
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
3 changes: 2 additions & 1 deletion packages/react-native/React/Modules/RCTUIManagerUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block)

NSNumber *RCTAllocateRootViewTag(void)
{
// Numbering of these tags goes from 1, 11, 21, 31, ..., 100501, ...
// Keep in sync with ReactRootViewTagGenerator.h - see that file for an explanation on why the
// increment here is 10.
static _Atomic int64_t rootViewTagCounter = 0;
return @(atomic_fetch_add_explicit(&rootViewTagCounter, 1, memory_order_relaxed) * 10 + 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ package com.facebook.react.uimanager
/** Incremental counter for React Root View tag. */
public object ReactRootViewTagGenerator {

// Keep in sync with ReactIOSTagHandles JS module - see that file for an explanation on why the
// Keep in sync with ReactRootViewTagGenerator.h - see that file for an explanation on why the
// increment here is 10.
private const val ROOT_VIEW_TAG_INCREMENT = 10
private var nextRootViewTag = 1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include "ReactRootViewTagGenerator.h"

#include <atomic>

namespace facebook::react {

constexpr SurfaceId ROOT_VIEW_TAG_INCREMENT = 10;

SurfaceId getNextRootViewTag() noexcept {
// Numbering of these tags goes from 11, 21, 31, ..., 100501, ...
static std::atomic<SurfaceId> nextRootViewTag = 1;
return nextRootViewTag += ROOT_VIEW_TAG_INCREMENT;
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#pragma once

#include <react/renderer/core/ReactPrimitives.h>

namespace facebook::react {

SurfaceId getNextRootViewTag() noexcept;

} // namespace facebook::react

0 comments on commit 0925e9b

Please sign in to comment.