From aba11daff8ca2247ee7de1c24147601c46c65c2e Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 9 Mar 2021 10:35:30 -0800 Subject: [PATCH] Integrate global.__nativeComponentRegistry__hasComponent into NativeComponentRegistry.js Summary: This diff creates a new unstable method (unstable_hasComponent) to expose `global.__nativeComponentRegistry__hasComponent` into NativeComponentRegistry.js changelog: [internal] internal Reviewed By: yungsters Differential Revision: D26716903 fbshipit-source-id: 52ff63b2779f41770b292cfc0b9022b1669d59fe --- .../NativeComponentRegistry.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Libraries/NativeComponent/NativeComponentRegistry.js b/Libraries/NativeComponent/NativeComponentRegistry.js index f44372dc7af..0dce50704b5 100644 --- a/Libraries/NativeComponent/NativeComponentRegistry.js +++ b/Libraries/NativeComponent/NativeComponentRegistry.js @@ -22,6 +22,8 @@ import * as React from 'react'; let getRuntimeConfig; +let componentNameToExists: Map = new Map(); + /** * Configures a function that is called to determine whether a given component * should be registered using reflection of the native component at runtime. @@ -134,3 +136,22 @@ 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; +}