From d2a8222bc6ace67df0522ec84f0792b2306b4a74 Mon Sep 17 00:00:00 2001 From: Soe Lynn Date: Thu, 4 Apr 2024 23:03:47 -0700 Subject: [PATCH] Back out "Update useNativeViewConfigsInBridgelessMode" (#43883) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43883 Changelog: [Internal] Backing out original diff `D55705805` to fix CircleCI Dynamic library test failure Reviewed By: philIip Differential Revision: D55773581 fbshipit-source-id: 2ec1b82241389166c1c31c979106c4ee6ead83fe --- .../Libraries/AppDelegate/RCTAppDelegate.mm | 11 +---------- .../Libraries/AppDelegate/RCTRootViewFactory.mm | 11 +++++++---- packages/react-native/React/Base/RCTConstants.m | 15 +++++++++++++++ .../Modules/{RCTUIManager.mm => RCTUIManager.m} | 7 +++---- .../{RCTComponentData.mm => RCTComponentData.m} | 9 ++++----- .../platform/ios/ReactCommon/RCTInstance.mm | 3 +-- 6 files changed, 31 insertions(+), 25 deletions(-) rename packages/react-native/React/Modules/{RCTUIManager.mm => RCTUIManager.m} (99%) rename packages/react-native/React/Views/{RCTComponentData.mm => RCTComponentData.m} (98%) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 1aa264499b5..2c56734cbf4 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -298,7 +298,6 @@ class RCTAppDelegateBridgelessFeatureFlags : public facebook::react::ReactNativeFeatureFlagsDefaults { public: - RCTAppDelegateBridgelessFeatureFlags(bool fabricEnabled) : _fabricEnabled(fabricEnabled) {} bool useModernRuntimeScheduler() override { return true; @@ -311,20 +310,12 @@ class RCTAppDelegateBridgelessFeatureFlags : public facebook::react::ReactNative { return true; } - bool useNativeViewConfigsInBridgelessMode() override - { - return _fabricEnabled; - } - - private: - bool _fabricEnabled; }; - (void)_setUpFeatureFlags { if ([self bridgelessEnabled]) { - facebook::react::ReactNativeFeatureFlags::override( - std::make_unique(self.fabricEnabled)); + facebook::react::ReactNativeFeatureFlags::override(std::make_unique()); } } diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm index 2d1fd263895..30aa86f91c0 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm @@ -113,9 +113,12 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri initialProperties:(NSDictionary *)initialProperties launchOptions:(NSDictionary *)launchOptions { - NSDictionary *initProps = updateInitialProps(initialProperties, _configuration.fabricEnabled); + NSDictionary *initProps = updateInitialProps(initialProperties, self->_configuration.fabricEnabled); + + if (self->_configuration.bridgelessEnabled) { + // Enable native view config interop only if both bridgeless mode and Fabric is enabled. + RCTSetUseNativeViewConfigsInBridgelessMode(self->_configuration.fabricEnabled); - if (_configuration.bridgelessEnabled) { // Enable TurboModule interop by default in Bridgeless mode RCTEnableTurboModuleInterop(YES); RCTEnableTurboModuleInteropBridgeProxy(YES); @@ -135,8 +138,8 @@ static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabri [self createBridgeIfNeeded:launchOptions]; [self createBridgeAdapterIfNeeded]; - if (_configuration.createRootViewWithBridge != nil) { - return _configuration.createRootViewWithBridge(self.bridge, moduleName, initProps); + if (self->_configuration.createRootViewWithBridge != nil) { + return self->_configuration.createRootViewWithBridge(self.bridge, moduleName, initProps); } return [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps]; diff --git a/packages/react-native/React/Base/RCTConstants.m b/packages/react-native/React/Base/RCTConstants.m index e70edf87822..70e94ca6b65 100644 --- a/packages/react-native/React/Base/RCTConstants.m +++ b/packages/react-native/React/Base/RCTConstants.m @@ -51,3 +51,18 @@ void RCTSetMemoryPressureUnloadLevel(int value) { RCTMemoryPressureUnloadLevel = value; } + +/* + * Use native view configs in bridgeless mode + */ +static BOOL RCTUseNativeViewConfigsInBridgelessMode = NO; + +BOOL RCTGetUseNativeViewConfigsInBridgelessMode(void) +{ + return RCTUseNativeViewConfigsInBridgelessMode; +} + +void RCTSetUseNativeViewConfigsInBridgelessMode(BOOL value) +{ + RCTUseNativeViewConfigsInBridgelessMode = value; +} diff --git a/packages/react-native/React/Modules/RCTUIManager.mm b/packages/react-native/React/Modules/RCTUIManager.m similarity index 99% rename from packages/react-native/React/Modules/RCTUIManager.mm rename to packages/react-native/React/Modules/RCTUIManager.m index ef27952ffee..71c4c669d3a 100644 --- a/packages/react-native/React/Modules/RCTUIManager.mm +++ b/packages/react-native/React/Modules/RCTUIManager.m @@ -9,7 +9,6 @@ #import #import -#import #import "RCTAssert.h" #import "RCTBridge+Private.h" @@ -1151,10 +1150,10 @@ RCT_EXPORT_METHOD(dispatchViewManagerCommand return; } - __weak __typeof(self) weakSelf = self; + __weak typeof(self) weakSelf = self; void (^mountingBlock)(void) = ^{ - __typeof(self) strongSelf = weakSelf; + typeof(self) strongSelf = weakSelf; @try { for (RCTViewManagerUIBlock block in previousPendingUIBlocks) { @@ -1453,7 +1452,7 @@ NSMutableDictionary *RCTModuleConstantsForDestructuredComponent( // lazifyViewManagerConfig function in JS. This fuction uses NativeModules global object that is not available in the // New Architecture. To make native view configs work in the New Architecture we will populate these properties in // native. - if (facebook::react::ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) { + if (RCTGetUseNativeViewConfigsInBridgelessMode()) { moduleConstants[@"Commands"] = viewConfig[@"Commands"]; moduleConstants[@"Constants"] = viewConfig[@"Constants"]; } diff --git a/packages/react-native/React/Views/RCTComponentData.mm b/packages/react-native/React/Views/RCTComponentData.m similarity index 98% rename from packages/react-native/React/Views/RCTComponentData.mm rename to packages/react-native/React/Views/RCTComponentData.m index d7ba21c6989..db6f9711426 100644 --- a/packages/react-native/React/Views/RCTComponentData.mm +++ b/packages/react-native/React/Views/RCTComponentData.m @@ -8,7 +8,6 @@ #import "RCTComponentData.h" #import -#import #import "RCTBridge.h" #import "RCTBridgeModule.h" @@ -281,9 +280,9 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S case _value: { \ __block BOOL setDefaultValue = NO; \ __block _type defaultValue; \ - _type (*convert)(id, SEL, id) = (__typeof(convert))objc_msgSend; \ - _type (*get)(id, SEL) = (__typeof(get))objc_msgSend; \ - void (*set)(id, SEL, _type) = (__typeof(set))objc_msgSend; \ + _type (*convert)(id, SEL, id) = (typeof(convert))objc_msgSend; \ + _type (*get)(id, SEL) = (typeof(get))objc_msgSend; \ + void (*set)(id, SEL, _type) = (typeof(set))objc_msgSend; \ setterBlock = ^(id target, id json) { \ if (json) { \ if (!setDefaultValue && target) { \ @@ -502,7 +501,7 @@ static RCTPropBlock createNSInvocationSetter(NSMethodSignature *typeSignature, S @"baseModuleName" : superClass == [NSObject class] ? (id)kCFNull : RCTViewManagerModuleNameForClass(superClass), }]; - if (facebook::react::ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) { + if (RCTGetUseNativeViewConfigsInBridgelessMode()) { result[@"Commands"] = [self commandsForViewMangerClass:managerClass methods:methods methodCount:count]; result[@"Constants"] = [self constantsForViewMangerClass:managerClass]; } diff --git a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm index b0e5a6d7841..7b30e83c17f 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTInstance.mm @@ -38,7 +38,6 @@ #import #import #import -#import #import #import #import @@ -350,7 +349,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags) }); RCTInstallNativeComponentRegistryBinding(runtime); - if (ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) { + if (RCTGetUseNativeViewConfigsInBridgelessMode()) { installLegacyUIManagerConstantsProviderBinding(runtime); }