From bd08dafc98776a02e9b89c685d0475c48b6fd1b3 Mon Sep 17 00:00:00 2001 From: Alan Hughes Date: Mon, 26 Oct 2026 08:53:31 -0700 Subject: [PATCH] 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 --- .../RCTDefaultReactNativeFactoryDelegate.mm | 25 ++- .../AppDelegate/RCTUIConfiguratorProtocol.h | 2 +- .../React/Base/RCTStatusBarAppearance.h | 26 +++ .../React/Base/RCTStatusBarAppearance.mm | 62 ++++++ .../React/CoreModules/RCTStatusBarManager.mm | 43 +++- .../Modal/RCTFabricModalHostViewController.mm | 32 ++- .../Modal/RCTModalHostViewComponentView.mm | 5 + packages/rn-tester/RNTester/Info.plist | 2 +- .../RNTesterPods.xcodeproj/project.pbxproj | 4 + .../RCTStatusBarAppearanceTests.mm | 198 ++++++++++++++++++ private/helloworld/ios/HelloWorld/Info.plist | 2 +- .../api-snapshots/ReactAppleDebugCxx.api | 8 + .../api-snapshots/ReactAppleFrameworksCxx.api | 8 + .../api-snapshots/ReactAppleNewarchCxx.api | 8 + .../api-snapshots/ReactAppleReleaseCxx.api | 8 + 15 files changed, 418 insertions(+), 15 deletions(-) create mode 100644 packages/react-native/React/Base/RCTStatusBarAppearance.h create mode 100644 packages/react-native/React/Base/RCTStatusBarAppearance.mm create mode 100644 packages/rn-tester/RNTesterUnitTests/RCTStatusBarAppearanceTests.mm diff --git a/packages/react-native/Libraries/AppDelegate/RCTDefaultReactNativeFactoryDelegate.mm b/packages/react-native/Libraries/AppDelegate/RCTDefaultReactNativeFactoryDelegate.mm index d94631a23d8..cc22ea05a4b 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTDefaultReactNativeFactoryDelegate.mm +++ b/packages/react-native/Libraries/AppDelegate/RCTDefaultReactNativeFactoryDelegate.mm @@ -14,9 +14,32 @@ #endif #import +#import #import #import +@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 diff --git a/packages/react-native/Libraries/AppDelegate/RCTUIConfiguratorProtocol.h b/packages/react-native/Libraries/AppDelegate/RCTUIConfiguratorProtocol.h index 3a97e122620..bcfd9840cb8 100644 --- a/packages/react-native/Libraries/AppDelegate/RCTUIConfiguratorProtocol.h +++ b/packages/react-native/Libraries/AppDelegate/RCTUIConfiguratorProtocol.h @@ -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`. diff --git a/packages/react-native/React/Base/RCTStatusBarAppearance.h b/packages/react-native/React/Base/RCTStatusBarAppearance.h new file mode 100644 index 00000000000..5cbc3f63188 --- /dev/null +++ b/packages/react-native/React/Base/RCTStatusBarAppearance.h @@ -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 + +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 diff --git a/packages/react-native/React/Base/RCTStatusBarAppearance.mm b/packages/react-native/React/Base/RCTStatusBarAppearance.mm new file mode 100644 index 00000000000..2592910edcb --- /dev/null +++ b/packages/react-native/React/Base/RCTStatusBarAppearance.mm @@ -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 diff --git a/packages/react-native/React/CoreModules/RCTStatusBarManager.mm b/packages/react-native/React/CoreModules/RCTStatusBarManager.mm index dc0a6568251..350edb366f7 100644 --- a/packages/react-native/React/CoreModules/RCTStatusBarManager.mm +++ b/packages/react-native/React/CoreModules/RCTStatusBarManager.mm @@ -11,6 +11,7 @@ #import #import #import +#import #import #import @@ -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(); + } } }); } diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm index 35e6eafecf2..5febef18d1c 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTFabricModalHostViewController.mm @@ -8,6 +8,7 @@ #import "RCTFabricModalHostViewController.h" #import +#import #import @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 diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm index 73de2f509e4..858daed3d25 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Modal/RCTModalHostViewComponentView.mm @@ -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 diff --git a/packages/rn-tester/RNTester/Info.plist b/packages/rn-tester/RNTester/Info.plist index 359e0f1be53..ce09c212a74 100644 --- a/packages/rn-tester/RNTester/Info.plist +++ b/packages/rn-tester/RNTester/Info.plist @@ -81,6 +81,6 @@ UIInterfaceOrientationPortraitUpsideDown UIViewControllerBasedStatusBarAppearance - + diff --git a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj index 1d336b42413..2573a501ff3 100644 --- a/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj +++ b/packages/rn-tester/RNTesterPods.xcodeproj/project.pbxproj @@ -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 = ""; }; 5C60EB1B226440DB0018C04F /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = RNTester/AppDelegate.mm; sourceTree = ""; }; + 67B0814814F7C07E196BC295 /* RCTStatusBarAppearanceTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = RCTStatusBarAppearanceTests.mm; sourceTree = ""; }; 79B29C2C2E607A99007612A5 /* SceneDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SceneDelegate.h; path = RNTester/SceneDelegate.h; sourceTree = ""; }; 79B29C2D2E607A99007612A5 /* SceneDelegate.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; name = SceneDelegate.mm; path = RNTester/SceneDelegate.mm; sourceTree = ""; }; 8145AE05241172D900A3F8DA /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = RNTester/LaunchScreen.storyboard; sourceTree = ""; }; @@ -350,6 +352,7 @@ E7DB20D022B2BAA5005AC45F /* RCTURLUtilsTests.m */, D5D13FB1445C5C19639921CC /* RCTUtilsTests.m */, E7DB20B322B2BAA4005AC45F /* RNTesterUnitTestsBundle.js */, + 67B0814814F7C07E196BC295 /* RCTStatusBarAppearanceTests.mm */, ); path = RNTesterUnitTests; sourceTree = ""; @@ -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; }; diff --git a/packages/rn-tester/RNTesterUnitTests/RCTStatusBarAppearanceTests.mm b/packages/rn-tester/RNTesterUnitTests/RCTStatusBarAppearanceTests.mm new file mode 100644 index 00000000000..17de4a4e9cf --- /dev/null +++ b/packages/rn-tester/RNTesterUnitTests/RCTStatusBarAppearanceTests.mm @@ -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 + +#import +#import +#import +#import +#import +#import + +@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 diff --git a/private/helloworld/ios/HelloWorld/Info.plist b/private/helloworld/ios/HelloWorld/Info.plist index 2dda775f5af..032a0c493ca 100644 --- a/private/helloworld/ios/HelloWorld/Info.plist +++ b/private/helloworld/ios/HelloWorld/Info.plist @@ -64,6 +64,6 @@ UIInterfaceOrientationLandscapeRight UIViewControllerBasedStatusBarAppearance - + diff --git a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api index 9815b007ef8..1fcde6e4b01 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleDebugCxx.api @@ -1747,6 +1747,14 @@ interface RCTSourceCode : public NSObject { interface RCTSpringAnimation : public NSObject { } +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 { } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api index 7d95a55afdd..e8364d85397 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleFrameworksCxx.api @@ -1790,6 +1790,14 @@ interface RCTSourceCode : public NSObject { interface RCTSpringAnimation : public NSObject { } +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 { } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api index e74431082e2..e058c681e1f 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleNewarchCxx.api @@ -1746,6 +1746,14 @@ interface RCTSourceCode : public NSObject { interface RCTSpringAnimation : public NSObject { } +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 { } diff --git a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api index 08697b483f6..a717a338bf7 100644 --- a/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAppleReleaseCxx.api @@ -1747,6 +1747,14 @@ interface RCTSourceCode : public NSObject { interface RCTSpringAnimation : public NSObject { } +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 { }