mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Fix StatusBar style and visibility on iOS 27 (#58926)
Summary: Fixes https://github.com/react/react-native/issues/58758. In apps built with the iOS 27 SDK, `StatusBar.setBarStyle` and `StatusBar.setHidden` do nothing. `RCTStatusBarManager` uses the `UIApplication` status bar setters, and UIKit turns them into no-ops for apps linked against the iOS 27 SDK. Apps built with the iOS 26 SDK are not affected. A plain UIKit app built with the iOS 27 SDK shows that with `UIViewControllerBasedStatusBarAppearance` set to `NO`, nothing can change the status bar on iOS 27. With `YES`, the view controller methods still work. This change moves `StatusBar` to the view controller model. The module stores the requested style, hidden state, and animation in a new `RCTStatusBarAppearance` class and calls `setNeedsStatusBarAppearanceUpdate` on the presented view controller. The default root view controller from `RCTDefaultReactNativeFactoryDelegate` and the Fabric modal controller return those values. The modal keeps the status bar that was on screen when it opened until JS changes it, so a status bar set natively (ie by react-native-screens) is not lost. With `NO`, the module still calls the `UIApplication` setters, so apps built with older SDKs keep working. When React Native is built with the iOS 27 SDK and runs on iOS 27, it also logs one warning that tells the developer to set the key to `YES`. Apps that override `createRootViewController` need their view controller to return the `RCTStatusBarAppearance` values for `StatusBar` to work on iOS 27. A similar change, https://github.com/react/react-native/issues/25919, landed in March 2020 and was reverted the next day ## Changelog: [IOS] [FIXED] - `StatusBar` style and visibility work on iOS 27 for apps built with the iOS 27 SDK when `UIViewControllerBasedStatusBarAppearance` is `YES`. Custom root view controllers must return the `RCTStatusBarAppearance` values. Pull Request resolved: https://github.com/react/react-native/pull/58926 Test Plan: 12 new XCTest cases in `RCTStatusBarAppearanceTests`. The OSS XCTest file has no internal BUCK owner and was not run locally. Validation for the review update: - Applied the explicit legacy-API guard to both `setStyle:animated:` and `setHidden:withAnimation:`. The appearance-state update remains unconditional; UIKit setters and warnings remain limited to apps using app-level status bar appearance. - Meta-managed `clang-format` and `arc lint` passed for `RCTStatusBarManager.mm`. - Built `ReactApple`, `CoreModulesApple`, `RCTFabricApple` and `RCTAppDelegateApple` for `iphonesimulator-arm64` with annotation checks enabled. - No public headers changed, so API snapshots are unchanged. - Diff-time CI will rerun for the updated code. Reviewed By: javache Differential Revision: D127555263 Pulled By: cipolleschi fbshipit-source-id: 9a6d21236987e309917e620387b34e88e7da24c7
This commit is contained in:
1 parent
d576b40bff
commit
bd08dafc98
15 files changed
+418
-15
No files matched your search
+24
-1
@@ -14,9 +14,32 @@
|
||||
#endif
|
||||
|
||||
#import <RCTAnimatedModuleProvider/RCTAnimatedModuleProvider.h>
|
||||
#import <React/RCTStatusBarAppearance.h>
|
||||
#import <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#import <react/nativemodule/defaults/DefaultTurboModules.h>
|
||||
|
||||
@interface RCTRootViewController : UIViewController
|
||||
@end
|
||||
|
||||
@implementation RCTRootViewController
|
||||
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle
|
||||
{
|
||||
return RCTStatusBarAppearance.style;
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden
|
||||
{
|
||||
return RCTStatusBarAppearance.hidden;
|
||||
}
|
||||
|
||||
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
|
||||
{
|
||||
return RCTStatusBarAppearance.updateAnimation;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTDefaultReactNativeFactoryDelegate {
|
||||
// C++ Native Animated provider, created once on first use (getTurboModule: may be called
|
||||
// concurrently for different module names).
|
||||
@@ -35,7 +58,7 @@
|
||||
|
||||
- (UIViewController *)createRootViewController
|
||||
{
|
||||
return [UIViewController new];
|
||||
return [RCTRootViewController new];
|
||||
}
|
||||
|
||||
- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController
|
||||
|
||||
@@ -41,7 +41,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* It creates the RootViewController.
|
||||
* By default, it creates a new instance of a `UIViewController`.
|
||||
* By default, it creates a view controller that returns the `RCTStatusBarAppearance` values.
|
||||
* You can override it to provide your own initial ViewController.
|
||||
*
|
||||
* @return: an instance of `UIViewController`.
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and 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>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* The status bar state set from JavaScript. Root view controllers return these values from their status bar methods.
|
||||
*/
|
||||
@interface RCTStatusBarAppearance : NSObject
|
||||
|
||||
@property (class, nonatomic, readonly) UIStatusBarStyle style;
|
||||
@property (class, nonatomic, readonly) BOOL hidden;
|
||||
@property (class, nonatomic, readonly) UIStatusBarAnimation updateAnimation;
|
||||
|
||||
+ (void)setStyle:(UIStatusBarStyle)style animated:(BOOL)animated;
|
||||
+ (void)setHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTStatusBarAppearance.h"
|
||||
|
||||
#import "RCTAssert.h"
|
||||
#import "RCTUtils.h"
|
||||
|
||||
static UIStatusBarStyle sStyle = UIStatusBarStyleDefault;
|
||||
static BOOL sHidden = NO;
|
||||
static UIStatusBarAnimation sUpdateAnimation = UIStatusBarAnimationNone;
|
||||
|
||||
@implementation RCTStatusBarAppearance
|
||||
|
||||
+ (UIStatusBarStyle)style
|
||||
{
|
||||
return sStyle;
|
||||
}
|
||||
|
||||
+ (BOOL)hidden
|
||||
{
|
||||
return sHidden;
|
||||
}
|
||||
|
||||
+ (UIStatusBarAnimation)updateAnimation
|
||||
{
|
||||
return sUpdateAnimation;
|
||||
}
|
||||
|
||||
+ (void)setStyle:(UIStatusBarStyle)style animated:(BOOL)animated
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
sStyle = style;
|
||||
[self updateStatusBarAnimated:animated];
|
||||
}
|
||||
|
||||
+ (void)setHidden:(BOOL)hidden withAnimation:(UIStatusBarAnimation)animation
|
||||
{
|
||||
RCTAssertMainQueue();
|
||||
sHidden = hidden;
|
||||
sUpdateAnimation = animation;
|
||||
[self updateStatusBarAnimated:animation != UIStatusBarAnimationNone];
|
||||
}
|
||||
|
||||
+ (void)updateStatusBarAnimated:(BOOL)animated
|
||||
{
|
||||
UIViewController *viewController = RCTPresentedViewController();
|
||||
if (animated) {
|
||||
[UIView animateWithDuration:UINavigationControllerHideShowBarDuration
|
||||
animations:^{
|
||||
[viewController setNeedsStatusBarAppearanceUpdate];
|
||||
}];
|
||||
} else {
|
||||
[viewController setNeedsStatusBarAppearanceUpdate];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -11,6 +11,7 @@
|
||||
#import <React/RCTEventDispatcherProtocol.h>
|
||||
#import <React/RCTInitializing.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTStatusBarAppearance.h>
|
||||
#import <React/RCTUtils.h>
|
||||
|
||||
#import <FBReactNativeSpec/FBReactNativeSpec.h>
|
||||
@@ -68,6 +69,28 @@ static BOOL RCTViewControllerBasedStatusBarAppearance()
|
||||
return value;
|
||||
}
|
||||
|
||||
// UIKit makes the app-level setters no-ops only for apps built with the iOS 27 SDK.
|
||||
static BOOL RCTAppLevelStatusBarIsNoOp()
|
||||
{
|
||||
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 270000
|
||||
if (@available(iOS 27.0, *)) {
|
||||
return YES;
|
||||
}
|
||||
#endif
|
||||
return NO;
|
||||
}
|
||||
|
||||
static void RCTWarnAppLevelStatusBarUnavailable()
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
RCTLogWarn(
|
||||
@"StatusBar has no effect because UIViewControllerBasedStatusBarAppearance is NO in Info.plist. "
|
||||
@"Apps built with the iOS 27 SDK cannot use the app-level status bar API that this setting uses. "
|
||||
@"Set UIViewControllerBasedStatusBarAppearance to YES to control the status bar from JavaScript.");
|
||||
});
|
||||
}
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
+ (BOOL)requiresMainQueueSetup
|
||||
@@ -147,15 +170,16 @@ RCT_EXPORT_MODULE()
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIStatusBarStyle statusBarStyle = [RCTConvert UIStatusBarStyle:style];
|
||||
if (RCTViewControllerBasedStatusBarAppearance()) {
|
||||
RCTLogWarn(@"RCTStatusBarManager is a no-op when \
|
||||
UIViewControllerBasedStatusBarAppearance is YES; set the status bar from your view controller instead");
|
||||
} else {
|
||||
[RCTStatusBarAppearance setStyle:statusBarStyle animated:animated];
|
||||
if (!RCTViewControllerBasedStatusBarAppearance()) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[RCTSharedApplication() setStatusBarStyle:statusBarStyle animated:animated];
|
||||
}
|
||||
#pragma clang diagnostic pop
|
||||
if (RCTAppLevelStatusBarIsNoOp()) {
|
||||
RCTWarnAppLevelStatusBarUnavailable();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,14 +187,15 @@ RCT_EXPORT_MODULE()
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
UIStatusBarAnimation animation = [RCTConvert UIStatusBarAnimation:withAnimation];
|
||||
if (RCTViewControllerBasedStatusBarAppearance()) {
|
||||
RCTLogWarn(@"RCTStatusBarManager is a no-op when \
|
||||
UIViewControllerBasedStatusBarAppearance is YES; set the status bar from your view controller instead");
|
||||
} else {
|
||||
[RCTStatusBarAppearance setHidden:hidden withAnimation:animation];
|
||||
if (!RCTViewControllerBasedStatusBarAppearance()) {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
[RCTSharedApplication() setStatusBarHidden:hidden withAnimation:animation];
|
||||
#pragma clang diagnostic pop
|
||||
if (RCTAppLevelStatusBarIsNoOp()) {
|
||||
RCTWarnAppLevelStatusBarUnavailable();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+30
-2
@@ -8,6 +8,7 @@
|
||||
#import "RCTFabricModalHostViewController.h"
|
||||
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTStatusBarAppearance.h>
|
||||
#import <React/RCTSurfaceTouchHandler.h>
|
||||
|
||||
@implementation RCTFabricModalHostViewController {
|
||||
@@ -15,6 +16,11 @@
|
||||
#if !TARGET_OS_TV
|
||||
RCTSurfaceTouchHandler *_touchHandler;
|
||||
#endif
|
||||
BOOL _hasCapturedStatusBar;
|
||||
UIStatusBarStyle _capturedStatusBarStyle;
|
||||
BOOL _capturedStatusBarHidden;
|
||||
UIStatusBarStyle _jsStatusBarStyleAtCapture;
|
||||
BOOL _jsStatusBarHiddenAtCapture;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
@@ -46,15 +52,37 @@
|
||||
#endif
|
||||
}
|
||||
|
||||
- (void)captureStatusBarAppearance
|
||||
{
|
||||
UIStatusBarManager *statusBarManager = RCTUIStatusBarManager();
|
||||
_hasCapturedStatusBar = YES;
|
||||
_capturedStatusBarStyle = statusBarManager.statusBarStyle;
|
||||
_capturedStatusBarHidden = statusBarManager.isStatusBarHidden;
|
||||
_jsStatusBarStyleAtCapture = RCTStatusBarAppearance.style;
|
||||
_jsStatusBarHiddenAtCapture = RCTStatusBarAppearance.hidden;
|
||||
}
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
// Keep the status bar from before the modal until JS changes it.
|
||||
- (UIStatusBarStyle)preferredStatusBarStyle
|
||||
{
|
||||
return [RCTUIStatusBarManager() statusBarStyle];
|
||||
if (_hasCapturedStatusBar && RCTStatusBarAppearance.style == _jsStatusBarStyleAtCapture) {
|
||||
return _capturedStatusBarStyle;
|
||||
}
|
||||
return RCTStatusBarAppearance.style;
|
||||
}
|
||||
|
||||
- (BOOL)prefersStatusBarHidden
|
||||
{
|
||||
return [RCTUIStatusBarManager() isStatusBarHidden];
|
||||
if (_hasCapturedStatusBar && RCTStatusBarAppearance.hidden == _jsStatusBarHiddenAtCapture) {
|
||||
return _capturedStatusBarHidden;
|
||||
}
|
||||
return RCTStatusBarAppearance.hidden;
|
||||
}
|
||||
|
||||
- (UIStatusBarAnimation)preferredStatusBarUpdateAnimation
|
||||
{
|
||||
return RCTStatusBarAppearance.updateAnimation;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+5
@@ -17,6 +17,10 @@
|
||||
|
||||
#import "RCTFabricModalHostViewController.h"
|
||||
|
||||
@interface RCTFabricModalHostViewController ()
|
||||
- (void)captureStatusBarAppearance;
|
||||
@end
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
#if !TARGET_OS_TV
|
||||
@@ -173,6 +177,7 @@ static ModalHostViewEventEmitter::OnOrientationChange onOrientationChangeStruct(
|
||||
[self saveAccessibilityFocusedView];
|
||||
self.viewController.presentationController.delegate = self;
|
||||
self.viewController.modalInPresentation = _modalInPresentation;
|
||||
[self.viewController captureStatusBarAppearance];
|
||||
|
||||
_isPresented = YES;
|
||||
[self presentViewController:self.viewController
|
||||
|
||||
@@ -81,6 +81,6 @@
|
||||
<string>UIInterfaceOrientationPortraitUpsideDown</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -17,6 +17,7 @@
|
||||
5C60EB1C226440DB0018C04F /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5C60EB1B226440DB0018C04F /* AppDelegate.mm */; };
|
||||
602160B9478DAFF2BAB56595 /* RCTUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D5D13FB1445C5C19639921CC /* RCTUtilsTests.m */; };
|
||||
79B29C2E2E607A99007612A5 /* SceneDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 79B29C2D2E607A99007612A5 /* SceneDelegate.mm */; };
|
||||
7F806D4D4D97AD6403558B35 /* RCTStatusBarAppearanceTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 67B0814814F7C07E196BC295 /* RCTStatusBarAppearanceTests.mm */; };
|
||||
8145AE06241172D900A3F8DA /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8145AE05241172D900A3F8DA /* LaunchScreen.storyboard */; };
|
||||
832F45BB2A8A6E1F0097B4E6 /* SwiftTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 832F45BA2A8A6E1F0097B4E6 /* SwiftTest.swift */; };
|
||||
A975CA6C2C05EADF0043F72A /* RCTNetworkTaskTests.m in Sources */ = {isa = PBXBuildFile; fileRef = A975CA6B2C05EADE0043F72A /* RCTNetworkTaskTests.m */; };
|
||||
@@ -94,6 +95,7 @@
|
||||
4C706D402EE4AF9BE838CBA9 /* libPods-RNTester.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RNTester.a"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
51BC9297B6C3163C14532020 /* Pods-RNTester.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RNTester.release.xcconfig"; path = "Target Support Files/Pods-RNTester/Pods-RNTester.release.xcconfig"; sourceTree = "<group>"; };
|
||||
5C60EB1B226440DB0018C04F /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = RNTester/AppDelegate.mm; sourceTree = "<group>"; };
|
||||
67B0814814F7C07E196BC295 /* RCTStatusBarAppearanceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTStatusBarAppearanceTests.mm; sourceTree = "<group>"; };
|
||||
79B29C2C2E607A99007612A5 /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SceneDelegate.h; path = RNTester/SceneDelegate.h; sourceTree = "<group>"; };
|
||||
79B29C2D2E607A99007612A5 /* SceneDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = SceneDelegate.mm; path = RNTester/SceneDelegate.mm; sourceTree = "<group>"; };
|
||||
8145AE05241172D900A3F8DA /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = RNTester/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
@@ -350,6 +352,7 @@
|
||||
E7DB20D022B2BAA5005AC45F /* RCTURLUtilsTests.m */,
|
||||
D5D13FB1445C5C19639921CC /* RCTUtilsTests.m */,
|
||||
E7DB20B322B2BAA4005AC45F /* RNTesterUnitTestsBundle.js */,
|
||||
67B0814814F7C07E196BC295 /* RCTStatusBarAppearanceTests.mm */,
|
||||
);
|
||||
path = RNTesterUnitTests;
|
||||
sourceTree = "<group>";
|
||||
@@ -778,6 +781,7 @@
|
||||
E7DB20E922B2BAA6005AC45F /* RCTComponentPropsTests.m in Sources */,
|
||||
E7DB20D822B2BAA6005AC45F /* RCTJSONTests.m in Sources */,
|
||||
602160B9478DAFF2BAB56595 /* RCTUtilsTests.m in Sources */,
|
||||
7F806D4D4D97AD6403558B35 /* RCTStatusBarAppearanceTests.mm in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/*
|
||||
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import <React-RCTAppDelegate/RCTDefaultReactNativeFactoryDelegate.h>
|
||||
#import <React/RCTFabricModalHostViewController.h>
|
||||
#import <React/RCTStatusBarAppearance.h>
|
||||
#import <React/RCTStatusBarManager.h>
|
||||
#import <React/RCTUtils.h>
|
||||
#import <React/RCTUtilsUIOverride.h>
|
||||
|
||||
@interface RCTFabricModalHostViewController ()
|
||||
- (void)captureStatusBarAppearance;
|
||||
@end
|
||||
|
||||
@interface RCTStatusBarManager (RCTStatusBarAppearanceTests)
|
||||
- (void)setStyle:(NSString *)style animated:(BOOL)animated;
|
||||
- (void)setHidden:(BOOL)hidden withAnimation:(NSString *)withAnimation;
|
||||
@end
|
||||
|
||||
@interface RCTStatusBarAppearanceTestViewController : UIViewController
|
||||
@property (nonatomic, assign) NSUInteger updateCount;
|
||||
@end
|
||||
|
||||
@implementation RCTStatusBarAppearanceTestViewController
|
||||
|
||||
- (void)setNeedsStatusBarAppearanceUpdate
|
||||
{
|
||||
[super setNeedsStatusBarAppearanceUpdate];
|
||||
self.updateCount++;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface RCTStatusBarAppearanceTests : XCTestCase
|
||||
@end
|
||||
|
||||
@implementation RCTStatusBarAppearanceTests {
|
||||
UIStatusBarStyle _initialStyle;
|
||||
BOOL _initialHidden;
|
||||
UIStatusBarAnimation _initialAnimation;
|
||||
RCTStatusBarAppearanceTestViewController *_viewController;
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
[super setUp];
|
||||
_initialStyle = RCTStatusBarAppearance.style;
|
||||
_initialHidden = RCTStatusBarAppearance.hidden;
|
||||
_initialAnimation = RCTStatusBarAppearance.updateAnimation;
|
||||
_viewController = [RCTStatusBarAppearanceTestViewController new];
|
||||
[RCTUtilsUIOverride setPresentedViewController:_viewController];
|
||||
}
|
||||
|
||||
- (void)tearDown
|
||||
{
|
||||
[RCTUtilsUIOverride setPresentedViewController:nil];
|
||||
[RCTStatusBarAppearance setStyle:_initialStyle animated:NO];
|
||||
[RCTStatusBarAppearance setHidden:_initialHidden withAnimation:_initialAnimation];
|
||||
[super tearDown];
|
||||
}
|
||||
|
||||
- (void)waitForMainQueue
|
||||
{
|
||||
XCTestExpectation *expectation = [self expectationWithDescription:@"main queue"];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[expectation fulfill];
|
||||
});
|
||||
[self waitForExpectations:@[ expectation ] timeout:1];
|
||||
}
|
||||
|
||||
- (void)testSetStyleStoresStyle
|
||||
{
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleLightContent animated:NO];
|
||||
XCTAssertEqual(RCTStatusBarAppearance.style, UIStatusBarStyleLightContent);
|
||||
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleDarkContent animated:YES];
|
||||
XCTAssertEqual(RCTStatusBarAppearance.style, UIStatusBarStyleDarkContent);
|
||||
}
|
||||
|
||||
- (void)testSetHiddenStoresHiddenAndAnimation
|
||||
{
|
||||
[RCTStatusBarAppearance setHidden:YES withAnimation:UIStatusBarAnimationSlide];
|
||||
XCTAssertTrue(RCTStatusBarAppearance.hidden);
|
||||
XCTAssertEqual(RCTStatusBarAppearance.updateAnimation, UIStatusBarAnimationSlide);
|
||||
|
||||
[RCTStatusBarAppearance setHidden:NO withAnimation:UIStatusBarAnimationFade];
|
||||
XCTAssertFalse(RCTStatusBarAppearance.hidden);
|
||||
XCTAssertEqual(RCTStatusBarAppearance.updateAnimation, UIStatusBarAnimationFade);
|
||||
}
|
||||
|
||||
- (void)testSetStyleDoesNotChangeUpdateAnimation
|
||||
{
|
||||
[RCTStatusBarAppearance setHidden:NO withAnimation:UIStatusBarAnimationSlide];
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleLightContent animated:YES];
|
||||
XCTAssertEqual(RCTStatusBarAppearance.updateAnimation, UIStatusBarAnimationSlide);
|
||||
}
|
||||
|
||||
- (void)testUpdateTargetsPresentedViewController
|
||||
{
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleLightContent animated:NO];
|
||||
XCTAssertEqual(_viewController.updateCount, 1u);
|
||||
|
||||
[RCTStatusBarAppearance setHidden:YES withAnimation:UIStatusBarAnimationNone];
|
||||
XCTAssertEqual(_viewController.updateCount, 2u);
|
||||
}
|
||||
|
||||
- (void)testAnimatedUpdateTargetsPresentedViewController
|
||||
{
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleLightContent animated:YES];
|
||||
XCTAssertEqual(_viewController.updateCount, 1u);
|
||||
|
||||
[RCTStatusBarAppearance setHidden:YES withAnimation:UIStatusBarAnimationFade];
|
||||
XCTAssertEqual(_viewController.updateCount, 2u);
|
||||
}
|
||||
|
||||
- (void)testLastHiddenCallWins
|
||||
{
|
||||
[RCTStatusBarAppearance setHidden:YES withAnimation:UIStatusBarAnimationSlide];
|
||||
[RCTStatusBarAppearance setHidden:NO withAnimation:UIStatusBarAnimationSlide];
|
||||
XCTAssertFalse(RCTStatusBarAppearance.hidden);
|
||||
XCTAssertEqual(_viewController.updateCount, 2u);
|
||||
}
|
||||
|
||||
- (void)testStatusBarManagerSetStyleUpdatesAppearance
|
||||
{
|
||||
[[RCTStatusBarManager new] setStyle:@"light-content" animated:NO];
|
||||
[self waitForMainQueue];
|
||||
XCTAssertEqual(RCTStatusBarAppearance.style, UIStatusBarStyleLightContent);
|
||||
XCTAssertEqual(_viewController.updateCount, 1u);
|
||||
}
|
||||
|
||||
- (void)testStatusBarManagerSetHiddenUpdatesAppearance
|
||||
{
|
||||
[[RCTStatusBarManager new] setHidden:YES withAnimation:@"fade"];
|
||||
[self waitForMainQueue];
|
||||
XCTAssertTrue(RCTStatusBarAppearance.hidden);
|
||||
XCTAssertEqual(RCTStatusBarAppearance.updateAnimation, UIStatusBarAnimationFade);
|
||||
XCTAssertEqual(_viewController.updateCount, 1u);
|
||||
}
|
||||
|
||||
- (void)testUnknownStyleFallsBackToDefault
|
||||
{
|
||||
[[RCTStatusBarManager new] setStyle:@"light-content" animated:NO];
|
||||
[self waitForMainQueue];
|
||||
XCTAssertEqual(RCTStatusBarAppearance.style, UIStatusBarStyleLightContent);
|
||||
|
||||
[[RCTStatusBarManager new] setStyle:@"not-a-style" animated:NO];
|
||||
[self waitForMainQueue];
|
||||
XCTAssertEqual(RCTStatusBarAppearance.style, UIStatusBarStyleDefault);
|
||||
}
|
||||
|
||||
- (void)testDefaultRootViewControllerReportsAppearance
|
||||
{
|
||||
UIViewController *rootViewController = [[RCTDefaultReactNativeFactoryDelegate new] createRootViewController];
|
||||
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleLightContent animated:NO];
|
||||
[RCTStatusBarAppearance setHidden:YES withAnimation:UIStatusBarAnimationSlide];
|
||||
|
||||
XCTAssertEqual(rootViewController.preferredStatusBarStyle, UIStatusBarStyleLightContent);
|
||||
XCTAssertTrue(rootViewController.prefersStatusBarHidden);
|
||||
XCTAssertEqual(rootViewController.preferredStatusBarUpdateAnimation, UIStatusBarAnimationSlide);
|
||||
}
|
||||
|
||||
- (void)testModalKeepsStatusBarCapturedBeforePresentation
|
||||
{
|
||||
UIStatusBarManager *sceneStatusBar = RCTUIStatusBarManager();
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleLightContent animated:NO];
|
||||
[RCTStatusBarAppearance setHidden:YES withAnimation:UIStatusBarAnimationNone];
|
||||
XCTAssertNotEqual(sceneStatusBar.statusBarStyle, UIStatusBarStyleLightContent);
|
||||
XCTAssertFalse(sceneStatusBar.isStatusBarHidden);
|
||||
|
||||
RCTFabricModalHostViewController *modalViewController = [RCTFabricModalHostViewController new];
|
||||
[modalViewController captureStatusBarAppearance];
|
||||
|
||||
XCTAssertEqual(modalViewController.preferredStatusBarStyle, sceneStatusBar.statusBarStyle);
|
||||
XCTAssertFalse(modalViewController.prefersStatusBarHidden);
|
||||
}
|
||||
|
||||
- (void)testModalViewControllerReportsAppearance
|
||||
{
|
||||
RCTFabricModalHostViewController *modalViewController = [RCTFabricModalHostViewController new];
|
||||
[modalViewController captureStatusBarAppearance];
|
||||
|
||||
[RCTStatusBarAppearance setStyle:UIStatusBarStyleLightContent animated:NO];
|
||||
[RCTStatusBarAppearance setHidden:YES withAnimation:UIStatusBarAnimationSlide];
|
||||
|
||||
XCTAssertEqual(modalViewController.preferredStatusBarStyle, UIStatusBarStyleLightContent);
|
||||
XCTAssertTrue(modalViewController.prefersStatusBarHidden);
|
||||
XCTAssertEqual(modalViewController.preferredStatusBarUpdateAnimation, UIStatusBarAnimationSlide);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -64,6 +64,6 @@
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
</array>
|
||||
<key>UIViewControllerBasedStatusBarAppearance</key>
|
||||
<false/>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1747,6 +1747,14 @@ interface RCTSourceCode : public NSObject <RCTBridgeModule> {
|
||||
interface RCTSpringAnimation : public NSObject <RCTAnimationDriver> {
|
||||
}
|
||||
|
||||
interface RCTStatusBarAppearance : public NSObject {
|
||||
public @property (assign, readonly) BOOL hidden;
|
||||
public @property (assign, readonly) UIStatusBarAnimation updateAnimation;
|
||||
public @property (assign, readonly) UIStatusBarStyle style;
|
||||
public virtual static void setHidden:withAnimation:(BOOL hidden, UIStatusBarAnimation animation);
|
||||
public virtual static void setStyle:animated:(UIStatusBarStyle style, BOOL animated);
|
||||
}
|
||||
|
||||
interface RCTStatusBarManager : public RCTEventEmitter {
|
||||
}
|
||||
|
||||
|
||||
@@ -1790,6 +1790,14 @@ interface RCTSourceCode : public NSObject <RCTBridgeModule> {
|
||||
interface RCTSpringAnimation : public NSObject <RCTAnimationDriver> {
|
||||
}
|
||||
|
||||
interface RCTStatusBarAppearance : public NSObject {
|
||||
public @property (assign, readonly) BOOL hidden;
|
||||
public @property (assign, readonly) UIStatusBarAnimation updateAnimation;
|
||||
public @property (assign, readonly) UIStatusBarStyle style;
|
||||
public virtual static void setHidden:withAnimation:(BOOL hidden, UIStatusBarAnimation animation);
|
||||
public virtual static void setStyle:animated:(UIStatusBarStyle style, BOOL animated);
|
||||
}
|
||||
|
||||
interface RCTStatusBarManager : public RCTEventEmitter {
|
||||
}
|
||||
|
||||
|
||||
@@ -1746,6 +1746,14 @@ interface RCTSourceCode : public NSObject <RCTBridgeModule> {
|
||||
interface RCTSpringAnimation : public NSObject <RCTAnimationDriver> {
|
||||
}
|
||||
|
||||
interface RCTStatusBarAppearance : public NSObject {
|
||||
public @property (assign, readonly) BOOL hidden;
|
||||
public @property (assign, readonly) UIStatusBarAnimation updateAnimation;
|
||||
public @property (assign, readonly) UIStatusBarStyle style;
|
||||
public virtual static void setHidden:withAnimation:(BOOL hidden, UIStatusBarAnimation animation);
|
||||
public virtual static void setStyle:animated:(UIStatusBarStyle style, BOOL animated);
|
||||
}
|
||||
|
||||
interface RCTStatusBarManager : public RCTEventEmitter {
|
||||
}
|
||||
|
||||
|
||||
@@ -1747,6 +1747,14 @@ interface RCTSourceCode : public NSObject <RCTBridgeModule> {
|
||||
interface RCTSpringAnimation : public NSObject <RCTAnimationDriver> {
|
||||
}
|
||||
|
||||
interface RCTStatusBarAppearance : public NSObject {
|
||||
public @property (assign, readonly) BOOL hidden;
|
||||
public @property (assign, readonly) UIStatusBarAnimation updateAnimation;
|
||||
public @property (assign, readonly) UIStatusBarStyle style;
|
||||
public virtual static void setHidden:withAnimation:(BOOL hidden, UIStatusBarAnimation animation);
|
||||
public virtual static void setStyle:animated:(UIStatusBarStyle style, BOOL animated);
|
||||
}
|
||||
|
||||
interface RCTStatusBarManager : public RCTEventEmitter {
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user