Skip to content

Commit

Permalink
Back out "UIViewController-based status bar management"
Browse files Browse the repository at this point in the history
Summary:
Original commit changeset: 9ae1384ee20a

Changelog: [Internal]

Reviewed By: hramos

Differential Revision: D20289822

fbshipit-source-id: 0db9d99bea458e150d33b3407c256b862dedb9c1
  • Loading branch information
logandaniels authored and facebook-github-bot committed Mar 5, 2020
1 parent fbd09b1 commit f4538e5
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 177 deletions.
8 changes: 3 additions & 5 deletions RNTester/RNTester/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#import <React/RCTDataRequestHandler.h>
#import <React/RCTFileRequestHandler.h>
#import <React/RCTRootView.h>
#import <React/RCTRootViewController.h>
#import <ReactCommon/BridgeJSCallInvoker.h>

#import <cxxreact/JSExecutor.h>
Expand Down Expand Up @@ -90,13 +89,12 @@ - (BOOL)application:(__unused UIApplication *)application didFinishLaunchingWith

UIView *rootView = [[RCTFabricSurfaceHostingProxyRootView alloc] initWithBridge:_bridge moduleName:@"RNTesterApp" initialProperties:initProps];
#else
RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:_bridge
moduleName:@"RNTesterApp"
initialProperties:initProps];
UIView *rootView = [[RCTRootView alloc] initWithBridge:_bridge moduleName:@"RNTesterApp" initialProperties:initProps];
#endif

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
RCTRootViewController *rootViewController = [[RCTRootViewController alloc] initWithRootView:rootView];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[self initializeFlipper:application];
Expand Down
2 changes: 2 additions & 0 deletions RNTester/RNTester/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSPhotoLibraryUsageDescription</key>
<string>You need to add NSPhotoLibraryUsageDescription key in Info.plist to enable photo library usage, otherwise it is going to *fail silently*!</string>
<key>RN_BUNDLE_PREFIX</key>
Expand Down
52 changes: 0 additions & 52 deletions React/Base/RCTRootViewController.h

This file was deleted.

73 changes: 0 additions & 73 deletions React/Base/RCTRootViewController.m

This file was deleted.

64 changes: 19 additions & 45 deletions React/CoreModules/RCTStatusBarManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#import <React/RCTLog.h>
#import <React/RCTUIManager.h>
#import <React/RCTUtils.h>
#import <React/RCTRootViewController.h>

#if !TARGET_OS_TV
#import <FBReactNativeSpec/FBReactNativeSpec.h>
Expand Down Expand Up @@ -145,27 +144,7 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
[self emitEvent:@"statusBarFrameWillChange" forNotification:notification];
}

- (UIViewController<RCTRootViewControllerProtocol>*) viewControllerForReactTag:(nonnull NSNumber *)reactTag
{
if (!RCTViewControllerBasedStatusBarAppearance()) {
return nil;
}

UIView *view = [self.bridge.uiManager viewForReactTag:reactTag];
UIViewController *viewController = view.window.rootViewController ?: RCTKeyWindow().rootViewController;

if ([viewController conformsToProtocol:@protocol(RCTRootViewControllerProtocol)]) {
return (UIViewController<RCTRootViewControllerProtocol>*) viewController;
} else {
RCTLogError(@"RCTStatusBarManager could not find RCTRootViewController. \
If UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to YES (recommended for new apps), \
You need to use RCTRootViewControllerProtocol-conforming view controller as app window's root view controller \
and must pass a node reference to `surface` argument of StatusBar methods.");
return nil;
}
}

RCT_EXPORT_METHOD(getHeight:(RCTResponseSenderBlock)callback)
RCT_EXPORT_METHOD(getHeight : (RCTResponseSenderBlock)callback)
{
callback(@[ @{
@"height" : @(RCTSharedApplication().statusBarFrame.size.height),
Expand All @@ -176,43 +155,38 @@ - (void)applicationWillChangeStatusBarFrame:(NSNotification *)notification
animated:(BOOL)animated
reactTag:(double)reactTag)
{
// NSNumber *reactTag = options.reactTag() ? @(options.reactTag()) : @-1;
UIStatusBarStyle statusBarStyle = [RCTConvert UIStatusBarStyle:style];
UIViewController<RCTRootViewControllerProtocol> *viewController = [self viewControllerForReactTag:@(reactTag)];
UIStatusBarStyle statusBarStyle = [RCTConvert UIStatusBarStyle:style];
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
return;
}

if (viewController) {
[viewController updateStatusBarStyle:statusBarStyle
hidden:viewController.prefersStatusBarHidden
animation:viewController.preferredStatusBarUpdateAnimation
animated:animated];
} else {
// TODO (T62270453): Add proper support for UIScenes (this requires view controller based status bar management)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[RCTSharedApplication() setStatusBarStyle:statusBarStyle
animated:animated];
[RCTSharedApplication() setStatusBarStyle:statusBarStyle
animated:animated];
#pragma clang diagnostic pop
}
}

RCT_EXPORT_METHOD(setHidden:(BOOL)hidden
withAnimation:(NSString *)withAnimation
reactTag:(double)reactTag)
{
UIStatusBarAnimation animation = [RCTConvert UIStatusBarAnimation:withAnimation];
UIViewController<RCTRootViewControllerProtocol> *viewController = [self viewControllerForReactTag:@(reactTag)];

if (viewController) {
[viewController updateStatusBarStyle:viewController.preferredStatusBarStyle
hidden:hidden
animation:animation
animated:animation != UIStatusBarAnimationNone];
} else {
if (RCTViewControllerBasedStatusBarAppearance()) {
RCTLogError(@"RCTStatusBarManager module requires that the \
UIViewControllerBasedStatusBarAppearance key in the Info.plist is set to NO");
return;
}

// TODO (T62270453): Add proper support for UIScenes (this requires view controller based status bar management)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[RCTSharedApplication() setStatusBarHidden:hidden
withAnimation:animation];
[RCTSharedApplication() setStatusBarHidden:hidden
withAnimation:animation];
#pragma clang diagnostic pop
}
}

RCT_EXPORT_METHOD(setNetworkActivityIndicatorVisible : (BOOL)visible)
Expand Down
4 changes: 2 additions & 2 deletions template/ios/HelloWorld/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <React/RCTRootViewController.h>

#if DEBUG
#import <FlipperKit/FlipperClient.h>
Expand Down Expand Up @@ -40,7 +39,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
RCTRootViewController *rootViewController = [[RCTRootViewController alloc] initWithRootView:rootView];
UIViewController *rootViewController = [UIViewController new];
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
return YES;
Expand Down
2 changes: 2 additions & 0 deletions template/ios/HelloWorld/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,7 @@
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
</dict>
</plist>

3 comments on commit f4538e5

@adbl
Copy link
Contributor

@adbl adbl commented on f4538e5 Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@logandaniels @hramos I'm wondering why this was reverted: #25919 (comment)

@DevinTope
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adbl did you get any reason why it was reverted? @logandaniels @hramos

@adbl
Copy link
Contributor

@adbl adbl commented on f4538e5 May 20, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adbl did you get any reason why it was reverted? @logandaniels @hramos

Nope, never heard anything.

Please sign in to comment.