From 4f2b4db1dbc85f9293f31f5ee1390b7cdef4a560 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Van=20der=20Auwermeulen?= Date: Wed, 14 Jun 2023 09:58:02 +0200 Subject: [PATCH 1/3] feat: allow custom assignment of rootView to rootViewController --- .../Libraries/AppDelegate/RCTAppDelegate.h | 12 ++++++++++++ .../Libraries/AppDelegate/RCTAppDelegate.mm | 8 +++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index f2df4437c3da92..67d4b5d0e23375 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -36,6 +36,8 @@ * - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString*)moduleName initProps:(NSDictionary *)initProps; * - (UIViewController *)createRootViewController; + * - (UIViewController *)attachRootView:(UIViewController *) rootViewController + rootView:(UIView *)rootView; * New Architecture: * - (BOOL)concurrentRootEnabled * - (BOOL)turboModuleEnabled; @@ -94,6 +96,16 @@ */ - (UIViewController *)createRootViewController; +/** + * It assigns the rootView to the rootViewController + * By default, it assigns the rootView to the view property of the rootViewController + * + * @return: an instance of `UIViewController` + */ +- (UIViewController *)attachRootView:(UIViewController *) rootViewController + rootView:(UIView *)rootView; + + /// 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..42b249f43b6acb 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 attachRootView:rootViewController rootView:rootView]; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; @@ -129,6 +129,12 @@ - (UIViewController *)createRootViewController return [UIViewController new]; } +- (UIViewController *)attachRootView:(UIViewController *) rootViewController + rootView:(UIView *)rootView { + rootViewController.view = rootView; + return rootViewController; +} + - (BOOL)runtimeSchedulerEnabled { return YES; From 45f66b6e27c606e9795c6d99ea83351b5743d411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Van=20der=20Auwermeulen=20Gr=C3=A9goire?= Date: Wed, 14 Jun 2023 23:21:03 +0200 Subject: [PATCH 2/3] Update packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h Co-authored-by: Riccardo Cipolleschi --- packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index 67d4b5d0e23375..28f4c63b3ddc40 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -102,8 +102,7 @@ * * @return: an instance of `UIViewController` */ -- (UIViewController *)attachRootView:(UIViewController *) rootViewController - rootView:(UIView *)rootView; + * - (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController; /// This method controls whether the App will use RuntimeScheduler. Only applicable in the legacy architecture. From 674c4e1bd107c6733a0e6330c02dbbeba573f763 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Van=20der=20Auwermeulen?= Date: Wed, 14 Jun 2023 23:33:52 +0200 Subject: [PATCH 3/3] fix: review --- .../Libraries/AppDelegate/RCTAppDelegate.h | 11 +++++------ .../Libraries/AppDelegate/RCTAppDelegate.mm | 7 +++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h index 67d4b5d0e23375..52763c21c4b7e9 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h +++ b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h @@ -36,8 +36,7 @@ * - (UIView *)createRootViewWithBridge:(RCTBridge *)bridge moduleName:(NSString*)moduleName initProps:(NSDictionary *)initProps; * - (UIViewController *)createRootViewController; - * - (UIViewController *)attachRootView:(UIViewController *) rootViewController - rootView:(UIView *)rootView; + * - (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController; * New Architecture: * - (BOOL)concurrentRootEnabled * - (BOOL)turboModuleEnabled; @@ -99,12 +98,12 @@ /** * 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: an instance of `UIViewController` + * @return: void */ -- (UIViewController *)attachRootView:(UIViewController *) rootViewController - rootView:(UIView *)rootView; - +- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController; /// This method controls whether the App will use RuntimeScheduler. Only applicable in the legacy architecture. /// diff --git a/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm index 42b249f43b6acb..98bbdafd4042a0 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]; - [self attachRootView:rootViewController rootView:rootView]; + [self setRootView:rootView toRootViewController:rootViewController]; self.window.rootViewController = rootViewController; [self.window makeKeyAndVisible]; @@ -129,12 +129,11 @@ - (UIViewController *)createRootViewController return [UIViewController new]; } -- (UIViewController *)attachRootView:(UIViewController *) rootViewController - rootView:(UIView *)rootView { +- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController { rootViewController.view = rootView; - return rootViewController; } + - (BOOL)runtimeSchedulerEnabled { return YES;