mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
feat: allow custom assignment of rootView to rootViewController (#37873)
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: https://github.com/facebook/react-native/pull/37873
Test Plan: Tested on iPad iOS 16 simulator
Reviewed By: cortinico
Differential Revision: D46761919
Pulled By: cipolleschi
fbshipit-source-id: c3ece0170d732133edc08f220a2f9a67da93815a
This commit is contained in:
committed by
Facebook GitHub Bot
parent
dc2037c0f1
commit
abc6e1cbf4
@@ -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`.
|
||||
|
||||
@@ -77,7 +77,7 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
|
||||
|
||||
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 @@ static NSString *const kRNConcurrentRoot = @"concurrentRoot";
|
||||
return [UIViewController new];
|
||||
}
|
||||
|
||||
- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController
|
||||
{
|
||||
rootViewController.view = rootView;
|
||||
}
|
||||
|
||||
- (BOOL)runtimeSchedulerEnabled
|
||||
{
|
||||
return YES;
|
||||
|
||||
Reference in New Issue
Block a user