From b1e92d6e0d3a2b27cbda8ad5d1fdbebcdec9a70b Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Wed, 25 Oct 2023 04:53:10 -0700 Subject: [PATCH] RNTester enable concurrent root when using Fabric (#41166) Summary: RNTester's `AppDelegate` override `prepareInitialProps` method of super class `RCTAppDelegate` https://github.com/facebook/react-native/blob/70acd3f7d9edae9e40cc4603bede9778da281a85/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm#L152, so we missed `concurrentRoot` initial prop. ![image](https://github.com/facebook/react-native/assets/5061845/12af5815-afe6-46f0-8107-54ca443b4962) cc javache cipolleschi ## Changelog: [IOS] [FIXED] - RNTester enable concurrent root when using Fabric Pull Request resolved: https://github.com/facebook/react-native/pull/41166 Test Plan: Warning disappear. Reviewed By: cipolleschi Differential Revision: D50596693 Pulled By: javache fbshipit-source-id: d73a17cd137b3088405f86b739cb0ed7b5a9839e --- .../Libraries/AppDelegate/RCTAppDelegate.h | 2 -- .../Libraries/AppDelegate/RCTAppDelegate.mm | 31 ++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index c92ca300e35e3c..71739d159ff40c 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -101,8 +101,6 @@ * By default, it assigns the rootView to the view property of the rootViewController * If you are not using a simple UIViewController, then there could be other methods to use to setup the rootView. * For example: UISplitViewController requires `setViewController(_:for:)` - * - * @return: void */ - (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController; diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 39f76375ab79e2..82e1911fe12246 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -53,6 +53,19 @@ @interface RCTAppDelegate () < #endif +static NSDictionary *updateInitialProps(NSDictionary *initialProps, BOOL isFabricEnabled) +{ +#ifdef RCT_NEW_ARCH_ENABLED + NSMutableDictionary *mutableProps = [initialProps mutableCopy] ?: [NSMutableDictionary new]; + // Hardcoding the Concurrent Root as it it not recommended to + // have the concurrentRoot turned off when Fabric is enabled. + mutableProps[kRNConcurrentRoot] = @(isFabricEnabled); + return mutableProps; +#else + return initialProps; +#endif +} + @interface RCTAppDelegate () { std::shared_ptr _runtimeScheduler; } @@ -80,10 +93,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( { BOOL enableTM = NO; BOOL enableBridgeless = NO; + BOOL fabricEnabled = NO; #if RCT_NEW_ARCH_ENABLED enableTM = self.turboModuleEnabled; enableBridgeless = self.bridgelessEnabled; + fabricEnabled = [self fabricEnabled]; #endif + NSDictionary *initProps = updateInitialProps([self prepareInitialProps], fabricEnabled); RCTAppSetupPrepareApp(application, enableTM); @@ -91,7 +107,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( if (enableBridgeless) { #if RCT_NEW_ARCH_ENABLED // Enable native view config interop only if both bridgeless mode and Fabric is enabled. - RCTSetUseNativeViewConfigsInBridgelessMode([self fabricEnabled]); + RCTSetUseNativeViewConfigsInBridgelessMode(fabricEnabled); // Enable TurboModule interop by default in Bridgeless mode RCTEnableTurboModuleInterop(YES); @@ -100,7 +116,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [self createReactHost]; [self unstable_registerLegacyComponents]; [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; - NSDictionary *initProps = [self prepareInitialProps]; RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps]; RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc] @@ -121,7 +136,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [self unstable_registerLegacyComponents]; [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; #endif - NSDictionary *initProps = [self prepareInitialProps]; + rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps]; } self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; @@ -143,15 +158,7 @@ - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge - (NSDictionary *)prepareInitialProps { - NSMutableDictionary *initProps = self.initialProps ? [self.initialProps mutableCopy] : [NSMutableDictionary new]; - -#ifdef RCT_NEW_ARCH_ENABLED - // Hardcoding the Concurrent Root as it it not recommended to - // have the concurrentRoot turned off when Fabric is enabled. - initProps[kRNConcurrentRoot] = @([self fabricEnabled]); -#endif - - return initProps; + return self.initialProps; } - (RCTBridge *)createBridgeWithDelegate:(id)delegate launchOptions:(NSDictionary *)launchOptions