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