Skip to content

Commit

Permalink
feat: allow custom assignment of rootView to rootViewController (#37873)
Browse files Browse the repository at this point in the history
Summary:
To use a native Drawer on iPad, I can override `createRootViewController` to create a `UISplitViewController` instead of a `UIViewController`, but I then need to assign the rootView with
```objective-c
[splitViewController setViewController:mainVC forColumn:UISplitViewControllerColumnSecondary];
```
which I can currently only do by copy pasting the entire `didFinishLaunchingWithOptions` and only replacing the assignment
```objective-c
    rootViewController.view = rootView;
```

In an attempt of making it easier for developers to use a native drawer in iOS, being able to override the assignment would make it easier.

bypass-github-export-checks

## Changelog:
[iOS] [ADDED] - added override method with default implementation

Pull Request resolved: #37873

Test Plan: Tested on iPad iOS 16 simulator

Reviewed By: cortinico

Differential Revision: D46761919

Pulled By: cipolleschi

fbshipit-source-id: c3ece0170d732133edc08f220a2f9a67da93815a
  • Loading branch information
Gregoirevda authored and facebook-github-bot committed Jun 15, 2023
1 parent dc2037c commit abc6e1c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down Expand Up @@ -129,6 +129,11 @@ - (UIViewController *)createRootViewController
return [UIViewController new];
}

- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController
{
rootViewController.view = rootView;
}

- (BOOL)runtimeSchedulerEnabled
{
return YES;
Expand Down

0 comments on commit abc6e1c

Please sign in to comment.