diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index ca029d2f4ba4db..cf6cd3a63382aa 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -100,8 +100,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 7f8163ed2f8c61..0cc46548fc2576 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -49,6 +49,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; } @@ -76,10 +89,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); @@ -88,7 +104,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); @@ -97,8 +113,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [self createReactHost]; [self unstable_registerLegacyComponents]; [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; - RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName - initialProperties:launchOptions]; + RCTFabricSurface *surface = [_reactHost createSurfaceWithModuleName:self.moduleName initialProperties:initProps]; RCTSurfaceHostingProxyRootView *surfaceHostingProxyRootView = [[RCTSurfaceHostingProxyRootView alloc] initWithSurface:surface @@ -118,7 +133,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]; @@ -140,15 +155,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