From b27fab70c52e613982f07a6a79699ff23afd4e59 Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Mon, 2 Oct 2023 11:10:33 -0700 Subject: [PATCH] Default to native view configs in bridged mode and to static view configs in bridgeless mode (#39704) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39704 Default to native view configs in bridged mode and to static view configs in bridgeless mode. Remove `setRuntimeConfigProvider` calls from RNTester and from the Template. Changelog: [Internal] Reviewed By: RSNara Differential Revision: D49687252 fbshipit-source-id: 140e1c510ba3fbc153978b59c8bb4b4e35bc7571 --- .../NativeComponent/NativeComponentRegistry.js | 14 ++++++++++---- packages/react-native/template/index.js | 9 --------- packages/rn-tester/js/RNTesterAppShared.js | 9 --------- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js index ace5eb38e605cd..46dab04b7723a0 100644 --- a/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js +++ b/packages/react-native/Libraries/NativeComponent/NativeComponentRegistry.js @@ -55,14 +55,20 @@ export function get( ): HostComponent { ReactNativeViewConfigRegistry.register(name, () => { const {native, strict, verify} = getRuntimeConfig?.(name) ?? { - native: true, + native: !global.RN$Bridgeless, strict: false, verify: false, }; - const viewConfig = native - ? getNativeComponentAttributes(name) - : createViewConfig(viewConfigProvider()); + let viewConfig; + if (native) { + viewConfig = getNativeComponentAttributes(name); + } else { + viewConfig = createViewConfig(viewConfigProvider()); + if (viewConfig == null) { + viewConfig = getNativeComponentAttributes(name); + } + } if (verify) { const nativeViewConfig = native diff --git a/packages/react-native/template/index.js b/packages/react-native/template/index.js index cd33b74bb3aa34..a850d031de7911 100644 --- a/packages/react-native/template/index.js +++ b/packages/react-native/template/index.js @@ -6,13 +6,4 @@ import {AppRegistry} from 'react-native'; import App from './App'; import {name as appName} from './app.json'; -if (global.RN$Bridgeless) { - require('react-native/Libraries/NativeComponent/NativeComponentRegistry').setRuntimeConfigProvider( - name => { - // In bridgeless mode, never load native ViewConfig. - return {native: false, strict: false, verify: false}; - }, - ); -} - AppRegistry.registerComponent(appName, () => App); diff --git a/packages/rn-tester/js/RNTesterAppShared.js b/packages/rn-tester/js/RNTesterAppShared.js index 0949aafca08d92..3cd8e9d9afad5a 100644 --- a/packages/rn-tester/js/RNTesterAppShared.js +++ b/packages/rn-tester/js/RNTesterAppShared.js @@ -29,15 +29,6 @@ import {BackHandler, StyleSheet, View, useColorScheme} from 'react-native'; // RNTester App currently uses in memory storage for storing navigation state -if (global.RN$Bridgeless) { - require('react-native/Libraries/NativeComponent/NativeComponentRegistry').setRuntimeConfigProvider( - name => { - // In bridgeless mode, never load native ViewConfig. - return {native: false, strict: false, verify: false}; - }, - ); -} - const RNTesterApp = (): React.Node => { const [state, dispatch] = React.useReducer( RNTesterNavigationReducer,