From 2f1cd040739cd47dc5afe91fa8f63dcb6a8fec3f Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Wed, 17 Apr 2024 06:14:35 -0700 Subject: [PATCH] Try static view config if native view config is not available (#44065) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44065 React Native will try to use static view config if native view config is not available. This will allow Fabric-only native components in Bridge mode. Changelog: [General][Added] - Add support for Fabric-only native components in Bridge mode. Reviewed By: cortinico Differential Revision: D56062759 fbshipit-source-id: e562700695c14c88d11056aec1e66f8aa10a3957 --- .../NativeComponent/NativeComponentRegistry.js | 17 ++++++++++++----- .../ReactNative/getNativeComponentAttributes.js | 9 +++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js index f071f3e6133..f088d2ac7fe 100644 --- a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js +++ b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js @@ -62,14 +62,21 @@ export function get( let viewConfig; if (native) { - viewConfig = getNativeComponentAttributes(name); + viewConfig = + getNativeComponentAttributes(name) ?? + createViewConfig(viewConfigProvider()); } else { - viewConfig = createViewConfig(viewConfigProvider()); - if (viewConfig == null) { - viewConfig = getNativeComponentAttributes(name); - } + viewConfig = + createViewConfig(viewConfigProvider()) ?? + getNativeComponentAttributes(name); } + invariant( + viewConfig != null, + 'NativeComponentRegistry.get: both static and native view config are missing for native component "%s".', + name, + ); + if (verify) { const nativeViewConfig = native ? viewConfig diff --git a/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js b/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js index d768a648718..209884d959b 100644 --- a/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js +++ b/packages/react-native/Libraries/ReactNative/getNativeComponentAttributes.js @@ -19,17 +19,14 @@ const matricesDiffer = require('../Utilities/differ/matricesDiffer'); const pointsDiffer = require('../Utilities/differ/pointsDiffer'); const sizesDiffer = require('../Utilities/differ/sizesDiffer'); const UIManager = require('./UIManager'); -const invariant = require('invariant'); const nullthrows = require('nullthrows'); function getNativeComponentAttributes(uiViewClassName: string): any { const viewConfig = UIManager.getViewManagerConfig(uiViewClassName); - invariant( - viewConfig != null && viewConfig.NativeProps != null, - 'requireNativeComponent: "%s" was not found in the UIManager.', - uiViewClassName, - ); + if (viewConfig == null) { + return null; + } // TODO: This seems like a whole lot of runtime initialization for every // native component that can be either avoided or simplified.