diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index f2df4437c3da92..52763c21c4b7e9 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -36,6 +36,7 @@ * - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString*)moduleName initProps:(NSDictionary *)initProps; * - (UIViewController *)createRootViewController; + * - (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController; * New Architecture: * - (BOOL)concurrentRootEnabled * - (BOOL)turboModuleEnabled; @@ -94,6 +95,16 @@ */ - (UIViewController *)createRootViewController; +/** + * It assigns the rootView to the rootViewController + * 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; + /// This method controls whether the App will use RuntimeScheduler. Only applicable in the legacy architecture. /// /// @return: `YES` to use RuntimeScheduler, `NO` to use JavaScript scheduler. The default value is `YES`. diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 808c315c2f1bf4..ecc438ca4a4f7a 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm @@ -77,7 +77,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; UIViewController *rootViewController = [self createRootViewController]; - rootViewController.view = rootView; + [self setRootView:rootView toRootViewController:rootViewController]; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; @@ -129,6 +129,11 @@ - (UIViewController *)createRootViewController return [UIViewController new]; } +- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController +{ + rootViewController.view = rootView; +} + - (BOOL)runtimeSchedulerEnabled { return YES;