From 6fc500ee9942e51519545c1ba1026bacad03dc61 Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Tue, 29 Oct 2024 12:42:26 -0700 Subject: [PATCH] hook up useNativeViewConfigsInBridgelessMode feature flag (#47265) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47265 Changelog: [iOS][Breaking] This was originally landed before as part of the effort to coalesce configurations with the feature flag infra, but got reverted due to a build issue. I'm pretty sure it was just because the legacy configuration methods were not cleaned up from the header (RCTConstants.h). I fixed that here. Reviewed By: javache Differential Revision: D65092536 fbshipit-source-id: 5012ba54b0314c487f2ef488c2eb30a3c4133cb5 --- .../Libraries/AppDelegate/RCTAppDelegate.mm | 21 ++++++++++++------- .../AppDelegate/RCTRootViewFactory.mm | 11 ++++------ .../react-native/React/Base/RCTConstants.h | 6 ------ .../react-native/React/Base/RCTConstants.m | 15 ------------- .../{RCTUIManager.m => RCTUIManager.mm} | 7 ++++--- ...RCTComponentData.m => RCTComponentData.mm} | 9 ++++---- .../platform/ios/React-RuntimeApple.podspec | 3 ++- .../platform/ios/ReactCommon/RCTInstance.mm | 3 ++- 8 files changed, 30 insertions(+), 45 deletions(-) rename packages/react-native/React/Modules/{RCTUIManager.m => RCTUIManager.mm} (99%) rename packages/react-native/React/Views/{RCTComponentData.m => RCTComponentData.mm} (98%) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index baca356003be7f..f4d9f3a86b0438 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -34,6 +34,8 @@ #endif #import +using namespace facebook::react; + @interface RCTAppDelegate () @end @@ -224,15 +226,14 @@ - (Class)getModuleClassFromName:(const char *)name #endif } -- (std::shared_ptr)getTurboModule:(const std::string &)name - jsInvoker:(std::shared_ptr)jsInvoker +- (std::shared_ptr)getTurboModule:(const std::string &)name + jsInvoker:(std::shared_ptr)jsInvoker { - return facebook::react::DefaultTurboModules::getTurboModule(name, jsInvoker); + return DefaultTurboModules::getTurboModule(name, jsInvoker); } -- (std::shared_ptr)getTurboModule:(const std::string &)name - initParams: - (const facebook::react::ObjCTurboModule::InitParams &)params +- (std::shared_ptr)getTurboModule:(const std::string &)name + initParams:(const ObjCTurboModule::InitParams &)params { return nullptr; } @@ -306,7 +307,7 @@ - (RCTRootViewFactory *)createRCTRootViewFactory #pragma mark - Feature Flags -class RCTAppDelegateBridgelessFeatureFlags : public facebook::react::ReactNativeFeatureFlagsDefaults { +class RCTAppDelegateBridgelessFeatureFlags : public ReactNativeFeatureFlagsDefaults { public: bool enableBridgelessArchitecture() override { @@ -320,12 +321,16 @@ bool useTurboModules() override { return true; } + bool useNativeViewConfigsInBridgelessMode() override + { + return true; + } }; - (void)_setUpFeatureFlags { if ([self bridgelessEnabled]) { - facebook::react::ReactNativeFeatureFlags::override(std::make_unique()); + ReactNativeFeatureFlags::override(std::make_unique()); } } diff --git a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm index c6818da3a36627..f5490705bed0e9 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTRootViewFactory.mm @@ -161,12 +161,9 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties launchOptions:(NSDictionary *)launchOptions { - 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); + NSDictionary *initProps = updateInitialProps(initialProperties, _configuration.fabricEnabled); + if (_configuration.bridgelessEnabled) { // Enable TurboModule interop by default in Bridgeless mode RCTEnableTurboModuleInterop(YES); RCTEnableTurboModuleInteropBridgeProxy(YES); @@ -190,8 +187,8 @@ - (UIView *)viewWithModuleName:(NSString *)moduleName [self createBridgeAdapterIfNeeded]; UIView *rootView; - if (self->_configuration.createRootViewWithBridge != nil) { - rootView = self->_configuration.createRootViewWithBridge(self.bridge, moduleName, initProps); + if (_configuration.createRootViewWithBridge != nil) { + rootView = _configuration.createRootViewWithBridge(self.bridge, moduleName, initProps); } else { rootView = [self createRootViewWithBridge:self.bridge moduleName:moduleName initProps:initProps]; } diff --git a/packages/react-native/React/Base/RCTConstants.h b/packages/react-native/React/Base/RCTConstants.h index f137800911117e..51a3967d1af17b 100644 --- a/packages/react-native/React/Base/RCTConstants.h +++ b/packages/react-native/React/Base/RCTConstants.h @@ -56,9 +56,3 @@ RCT_EXTERN void RCTSetDispatchW3CPointerEvents(BOOL value); */ RCT_EXTERN int RCTGetMemoryPressureUnloadLevel(void); RCT_EXTERN void RCTSetMemoryPressureUnloadLevel(int value); - -/* - * Use native view configs in bridgeless mode - */ -RCT_EXTERN BOOL RCTGetUseNativeViewConfigsInBridgelessMode(void); -RCT_EXTERN void RCTSetUseNativeViewConfigsInBridgelessMode(BOOL value); diff --git a/packages/react-native/React/Base/RCTConstants.m b/packages/react-native/React/Base/RCTConstants.m index 656f4bde456447..f348841d6ad451 100644 --- a/packages/react-native/React/Base/RCTConstants.m +++ b/packages/react-native/React/Base/RCTConstants.m @@ -54,18 +54,3 @@ 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.m b/packages/react-native/React/Modules/RCTUIManager.mm similarity index 99% rename from packages/react-native/React/Modules/RCTUIManager.m rename to packages/react-native/React/Modules/RCTUIManager.mm index 2d47cafe9e807e..e307fadd4a108c 100644 --- a/packages/react-native/React/Modules/RCTUIManager.m +++ b/packages/react-native/React/Modules/RCTUIManager.mm @@ -9,6 +9,7 @@ #import #import +#import #import "RCTAssert.h" #import "RCTBridge+Private.h" @@ -1154,10 +1155,10 @@ - (void)flushUIBlocksWithCompletion:(void (^)(void))completion 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) { @@ -1438,7 +1439,7 @@ static void RCTMeasureLayout(RCTShadowView *view, RCTShadowView *ancestor, RCTRe // 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 (RCTGetUseNativeViewConfigsInBridgelessMode()) { + if (facebook::react::ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) { moduleConstants[@"Commands"] = viewConfig[@"Commands"]; moduleConstants[@"Constants"] = viewConfig[@"Constants"]; } diff --git a/packages/react-native/React/Views/RCTComponentData.m b/packages/react-native/React/Views/RCTComponentData.mm similarity index 98% rename from packages/react-native/React/Views/RCTComponentData.m rename to packages/react-native/React/Views/RCTComponentData.mm index f743aa88b7bc7c..0c751afd8d1eac 100644 --- a/packages/react-native/React/Views/RCTComponentData.m +++ b/packages/react-native/React/Views/RCTComponentData.mm @@ -8,6 +8,7 @@ #import "RCTComponentData.h" #import +#import #import "RCTBridge.h" #import "RCTBridgeModule.h" @@ -288,9 +289,9 @@ - (RCTPropBlock)createPropBlock:(NSString *)name isShadowView:(BOOL)isShadowView 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) { \ @@ -522,7 +523,7 @@ - (void)setProps:(NSDictionary *)props forView:(id @"baseModuleName" : superClass == [NSObject class] ? (id)kCFNull : RCTViewManagerModuleNameForClass(superClass), }]; - if (RCTGetUseNativeViewConfigsInBridgelessMode()) { + if (facebook::react::ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) { 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/React-RuntimeApple.podspec b/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec index e14016ae6340b1..3a39a550b8ba97 100644 --- a/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec +++ b/packages/react-native/ReactCommon/react/runtime/platform/ios/React-RuntimeApple.podspec @@ -22,7 +22,7 @@ folly_version = folly_config[:version] folly_dep_name = folly_config[:dep_name] boost_config = get_boost_config() -boost_compiler_flags = boost_config[:compiler_flags] +boost_compiler_flags = boost_config[:compiler_flags] header_search_paths = [ "$(PODS_ROOT)/boost", @@ -69,6 +69,7 @@ Pod::Spec.new do |s| s.dependency "React-Mapbuffer" s.dependency "React-jserrorhandler" s.dependency "React-jsinspector" + s.dependency "React-featureflags" if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1" s.dependency "hermes-engine" 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 09ee426ea0af80..e4301e583ebfe1 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 @@ -37,6 +37,7 @@ #import #import #import +#import #import #import #import @@ -327,7 +328,7 @@ - (void)_start }); RCTInstallNativeComponentRegistryBinding(runtime); - if (RCTGetUseNativeViewConfigsInBridgelessMode()) { + if (ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode()) { installLegacyUIManagerConstantsProviderBinding(runtime); }