Add ReactRootViewTagGenerator (#43882)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/43882

Changelog: [General][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.

Reviewed By: javache

Differential Revision: D55772580

fbshipit-source-id: 88f5e15011ef89c522746fb2a62753c7b5a75cb9
This commit is contained in:
Christoph Purrer
2024-04-08 08:23:34 -07:00
committed by Facebook GitHub Bot
parent 15ff82f811
commit 7dec625eca
4 changed files with 41 additions and 2 deletions
@@ -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);
}
@@ -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
@@ -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
@@ -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