From 5b56e6d3bb5d50888b8d36050162b14169a1095e Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Mon, 18 Sep 2023 09:11:20 -0700 Subject: [PATCH] Enabale native view configs in bridgeless mode in OSS (#39476) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39476 This diff enables native view config interop layer in bridgeless mode by default for OSS. It also removes redundant `enableNativeViewConfigsInBridgelessMode` JS feature flag. Changelog: [General][Added] - Native view config interop layer enabled in bridgeless mode. Differential Revision: D49318325 fbshipit-source-id: f07e691a16d5c65032ad1002faecf1d1afa219c0 --- .../react-native/Libraries/AppDelegate/RCTAppDelegate.mm | 1 + .../Libraries/ReactNative/BridgelessUIManager.js | 9 ++++++--- .../Libraries/ReactNative/ReactNativeFeatureFlags.js | 5 ----- .../react/defaults/DefaultNewArchitectureEntryPoint.kt | 3 +++ 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index d16b85ce9e979f..9896d5249912b3 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -87,6 +87,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( if (enableBridgeless) { #if RCT_NEW_ARCH_ENABLED + RCTSetUseNativeViewConfigsInBridgelessMode(YES); [self createReactHost]; [self unstable_registerLegacyComponents]; [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; diff --git a/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js b/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js index 815fe7137fcaf0..e7ed59ef8d01c0 100644 --- a/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js +++ b/packages/react-native/Libraries/ReactNative/BridgelessUIManager.js @@ -14,7 +14,6 @@ import type {RootTag} from '../Types/RootTagTypes'; import {unstable_hasComponent} from '../NativeComponent/NativeComponentRegistryUnstable'; import NativeUIManager from './NativeUIManager'; -import ReactNativeFeatureFlags from './ReactNativeFeatureFlags'; let cachedConstants = null; @@ -23,6 +22,10 @@ const errorMessageForMethod = (methodName: string): string => methodName + "' is not available in the new React Native architecture."; +function nativeViewConfigsInBridgelessModeEnabled(): boolean { + return global.RN$LegacyInterop_UIManager_getConstants !== undefined; +} + function getCachedConstants(): Object { if (!cachedConstants) { cachedConstants = global.RN$LegacyInterop_UIManager_getConstants(); @@ -36,7 +39,7 @@ function getCachedConstants(): Object { const UIManagerJS = { ...NativeUIManager, getViewManagerConfig: (viewManagerName: string): mixed => { - if (ReactNativeFeatureFlags.enableNativeViewConfigsInBridgelessMode()) { + if (nativeViewConfigsInBridgelessModeEnabled()) { return getCachedConstants()[viewManagerName]; } else { console.error( @@ -51,7 +54,7 @@ const UIManagerJS = { return unstable_hasComponent(viewManagerName); }, getConstants: (): Object => { - if (ReactNativeFeatureFlags.enableNativeViewConfigsInBridgelessMode()) { + if (nativeViewConfigsInBridgelessModeEnabled()) { return getCachedConstants(); } else { console.error(errorMessageForMethod('getConstants')); diff --git a/packages/react-native/Libraries/ReactNative/ReactNativeFeatureFlags.js b/packages/react-native/Libraries/ReactNative/ReactNativeFeatureFlags.js index 01a56fb5098b58..95d15e6e2f968c 100644 --- a/packages/react-native/Libraries/ReactNative/ReactNativeFeatureFlags.js +++ b/packages/react-native/Libraries/ReactNative/ReactNativeFeatureFlags.js @@ -54,10 +54,6 @@ export type FeatureFlags = {| * Enables use of setNativeProps in JS driven animations. */ shouldUseSetNativePropsInFabric: () => boolean, - /** - * Enables native view configs in brdgeless mode. - */ - enableNativeViewConfigsInBridgelessMode: () => boolean, /** * Enables a hotfix for forcing materialization of views with elevation set. */ @@ -74,7 +70,6 @@ const ReactNativeFeatureFlags: FeatureFlags = { enableAccessToHostTreeInFabric: () => false, shouldUseAnimatedObjectForTransform: () => false, shouldUseSetNativePropsInFabric: () => false, - enableNativeViewConfigsInBridgelessMode: () => false, shouldForceUnflattenForElevation: () => false, }; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt index e3aa9aebae05e4..9308a3cb440de8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt @@ -34,6 +34,9 @@ object DefaultNewArchitectureEntryPoint { ReactFeatureFlags.enableFabricRenderer = fabricEnabled ReactFeatureFlags.unstable_useFabricInterop = fabricEnabled ReactFeatureFlags.enableBridgelessArchitecture = bridgelessEnabled + if (bridgelessEnabled) { + ReactFeatureFlags.useNativeViewConfigsInBridgelessMode = true + } this.privateFabricEnabled = fabricEnabled this.privateTurboModulesEnabled = turboModulesEnabled