mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
80e6d672f3
Summary:
{emoji:26a0} This is a follow up to https://github.com/facebook/react-native/issues/25425 -- which isn't merged yet… See https://github.com/facebook/react-native/pull/25919/files/2a286257a6553a80a34e2b1f1ad94fc7bae36ea3..125aedbedc234c65c8d1b2133b79e926ad6cf145 for actual diff
Currently, StatusBar native module manages the status bar on iOS globally, using `UIApplication.` APIs. This is bad because:
- those APIs have been deprecated for 4 years
- Apple really, really wants you to have an explicitly defined view controller, and control the status bar there
- it [breaks external native components](https://github.com/facebook/react-native/issues/25181#issuecomment-506792819)
- it's [not compatible with iPadOS 13 multi window support](https://github.com/facebook/react-native/issues/25181#issuecomment-506690818)
for those reasons I we should transition towards view controller-based status bar management.
With that, there is a need to introduce a default React Native root view controller, so I added `RCTRootViewController`. Using it is completely opt-in and there is no breaking change here. However I believe this should be a part of the template for new RN iOS apps.
Additionally, I added `RCTRootViewControllerProtocol` with hooks needed for RCTStatusBarManager to control the status bar. This means apps that want to have total control over their view controller can still opt in to react native VC-based status bar by conforming their root view controller to this protocol.
## Changelog
[iOS] [Added] - Added `RCTRootViewController` and `RCTRootViewControllerProtocol`
[iOS] [Fixed] - `UIViewControllerBasedStatusBarAppearance=YES` no longer triggers an error as long as you use `RCTRootViewController`
[iOS] [Fixed] - Status bar style is now correctly changed in multi-window iPadOS 13 apps if you use `RCTRootViewController` and set `UIViewControllerBasedStatusBarAppearance=YES`
Pull Request resolved: https://github.com/facebook/react-native/pull/25919
Test Plan: - Open RNTester → StatusBar → and check that no features broke
Reviewed By: fkgozali
Differential Revision: D16957766
Pulled By: hramos
fbshipit-source-id: 9ae1384ee20a06933053c4404b8237810f1e7c2c
53 lines
1.3 KiB
Objective-C
53 lines
1.3 KiB
Objective-C
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#import <React/RCTBridge.h>
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
@class RCTRootView;
|
|
|
|
@protocol RCTRootViewControllerProtocol <NSObject>
|
|
|
|
/**
|
|
* RCTStatusBarManager calls this to update the status bar style.
|
|
*
|
|
* Conforming view controllers should use this to update preferred status bar style
|
|
*/
|
|
- (void)updateStatusBarStyle:(UIStatusBarStyle)style
|
|
hidden:(BOOL)hidden
|
|
animation:(UIStatusBarAnimation)animation
|
|
animated:(BOOL)animate;
|
|
|
|
@end
|
|
|
|
@interface RCTRootViewController : UIViewController <RCTRootViewControllerProtocol>
|
|
|
|
/**
|
|
* - Designated initializer -
|
|
*/
|
|
- (instancetype)initWithRootView:(RCTRootView *)rootView NS_DESIGNATED_INITIALIZER;
|
|
|
|
/**
|
|
* The root view used by the view controller.
|
|
*/
|
|
@property (nonatomic, strong, readonly) RCTRootView *rootView;
|
|
|
|
/**
|
|
* See: RCTRootViewControllerProtocol
|
|
*/
|
|
- (void)updateStatusBarStyle:(UIStatusBarStyle)style
|
|
hidden:(BOOL)hidden
|
|
animation:(UIStatusBarAnimation)animation
|
|
animated:(BOOL)animate;
|
|
|
|
@end
|
|
|
|
NS_ASSUME_NONNULL_END
|