diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index fd7310c7f88..f9ca86a602a 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -64,6 +64,9 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, strong, nullable) NSDictionary *initialProps; @property (nonatomic, strong, nonnull) RCTRootViewFactory *rootViewFactory; +/// If `automaticallyLoadReactNativeWindow` is set to `true`, the React Native window will be loaded automatically. +@property (nonatomic, assign) BOOL automaticallyLoadReactNativeWindow; + @property (nonatomic, nullable) RCTSurfacePresenterBridgeAdapter *bridgeAdapter; /** diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 1e87756cad8..ca5be139ffb 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -12,6 +12,7 @@ #import #import #import +#include #import #import #import @@ -38,6 +39,14 @@ @implementation RCTAppDelegate +- (instancetype)init +{ + if (self = [super init]) { + _automaticallyLoadReactNativeWindow = YES; + } + return self; +} + - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [self _setUpFeatureFlags]; @@ -47,23 +56,28 @@ RCTAppSetupPrepareApp(application, self.turboModuleEnabled); self.rootViewFactory = [self createRCTRootViewFactory]; - - UIView *rootView = [self.rootViewFactory viewWithModuleName:self.moduleName - initialProperties:self.initialProps - launchOptions:launchOptions]; - if (self.newArchEnabled || self.fabricEnabled) { [RCTComponentViewFactory currentComponentViewFactory].thirdPartyFabricComponentsProvider = self; } + if (self.automaticallyLoadReactNativeWindow) { + [self loadReactNativeWindow:launchOptions]; + } + + return YES; +} + +- (void)loadReactNativeWindow:(NSDictionary *)launchOptions +{ + UIView *rootView = [self.rootViewFactory viewWithModuleName:self.moduleName + initialProperties:self.initialProps + launchOptions:launchOptions]; + self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [self createRootViewController]; [self setRootView:rootView toRootViewController:rootViewController]; - self.window.rootViewController = rootViewController; - self.window.windowScene.delegate = self; - [self.window makeKeyAndVisible]; - - return YES; + _window.rootViewController = rootViewController; + [_window makeKeyAndVisible]; } - (void)applicationDidEnterBackground:(UIApplication *)application