mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
4/5 Minor: Move unstable_hasComponent out of NativeComponentRegistry
Summary: Without moving this, we would get this warning about a require cycle on the next diff, because DummyUIManager and LazyUIManager both need unstable_hasComponent. ``` (NOBRIDGE) WARN Require cycle: react-native-github/Libraries/NativeComponent/NativeComponentRegistry.js -> react-native-github/Libraries/ReactNative/UIManager.js -> react-native-github/Libraries/ReactNative/DummyUIManager.js -> react-native-github/Libraries/NativeComponent/NativeComponentRegistry.js Require cycles are allowed, but can result in uninitialized values. Consider refactoring to remove the need for a cycle. ``` Changelog: [Internal] Reviewed By: philIip, RSNara Differential Revision: D33511566 fbshipit-source-id: fd8c9732408d08ab17335273f86168bf30747929
This commit is contained in:
1 parent
7c63e0d5bc
commit
a620d7dc85
2 files changed
+27
-19
No files matched your search
@@ -152,22 +152,3 @@ export function unstable_hasStaticViewConfig(name: string): boolean {
|
||||
};
|
||||
return !native;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unstable API. Do not use!
|
||||
*
|
||||
* This method returns if the component with name received as a parameter
|
||||
* is registed in the native platform.
|
||||
*/
|
||||
export function unstable_hasComponent(name: string): boolean {
|
||||
let hasNativeComponent = componentNameToExists.get(name);
|
||||
if (hasNativeComponent == null) {
|
||||
if (global.__nativeComponentRegistry__hasComponent) {
|
||||
hasNativeComponent = global.__nativeComponentRegistry__hasComponent(name);
|
||||
componentNameToExists.set(name, hasNativeComponent);
|
||||
} else {
|
||||
throw `unstable_hasComponent('${name}'): Global function is not registered`;
|
||||
}
|
||||
}
|
||||
return hasNativeComponent;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
|
||||
let componentNameToExists: Map<string, boolean> = new Map();
|
||||
|
||||
/**
|
||||
* Unstable API. Do not use!
|
||||
*
|
||||
* This method returns if the component with name received as a parameter
|
||||
* is registed in the native platform.
|
||||
*/
|
||||
export function unstable_hasComponent(name: string): boolean {
|
||||
let hasNativeComponent = componentNameToExists.get(name);
|
||||
if (hasNativeComponent == null) {
|
||||
if (global.__nativeComponentRegistry__hasComponent) {
|
||||
hasNativeComponent = global.__nativeComponentRegistry__hasComponent(name);
|
||||
componentNameToExists.set(name, hasNativeComponent);
|
||||
} else {
|
||||
throw `unstable_hasComponent('${name}'): Global function is not registered`;
|
||||
}
|
||||
}
|
||||
return hasNativeComponent;
|
||||
}
|
||||
Reference in new issue
Block a user