Skip to content

Commit f487134

Browse files
authored
Fix status bar visibility on iOS 13 (#6084)
This commit fixes statusBar.visible option which stopped working on iOS 13.
1 parent 68e4c4b commit f487134

11 files changed

+96
-21
lines changed

lib/ios/RNNBasePresenter.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
4343

4444
- (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options;
4545

46-
- (BOOL)isStatusBarVisibility:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions;
46+
- (BOOL)statusBarVisibile:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions;
47+
4748
@end

lib/ios/RNNBasePresenter.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options {
102102
return [options withDefault:[self defaultOptions]].layout.supportedOrientations;
103103
}
104104

105-
- (BOOL)isStatusBarVisibility:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
106-
RNNNavigationOptions *withDefault = [resolvedOptions withDefault:[self defaultOptions]];
105+
- (BOOL)statusBarVisibile:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions {
106+
RNNNavigationOptions *withDefault = [resolvedOptions withDefault:self.defaultOptions];
107107
if (withDefault.statusBar.visible.hasValue) {
108108
return ![withDefault.statusBar.visible get];
109109
} else if ([withDefault.statusBar.hideWithTopBar getWithDefaultValue:NO]) {

lib/ios/RNNBottomTabsController.m

+4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ - (UIStatusBarStyle)preferredStatusBarStyle {
9191
return [[self presenter] getStatusBarStyle:self.resolveOptions];
9292
}
9393

94+
- (BOOL)prefersStatusBarHidden {
95+
return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
96+
}
97+
9498
#pragma mark UITabBarControllerDelegate
9599

96100
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {

lib/ios/RNNComponentViewController.m

+4
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ - (UIStatusBarStyle)preferredStatusBarStyle {
8383
return [_presenter getStatusBarStyle:[self resolveOptions]];
8484
}
8585

86+
- (BOOL)prefersStatusBarHidden {
87+
return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
88+
}
89+
8690
- (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
8791
return self.previewController;
8892
}

lib/ios/RNNSideMenuController.m

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ - (UIStatusBarStyle)preferredStatusBarStyle {
134134
return self.openedViewController.preferredStatusBarStyle;
135135
}
136136

137+
- (BOOL)prefersStatusBarHidden {
138+
return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
139+
}
140+
137141
- (UIViewController<RNNLayoutProtocol> *)getCurrentChild {
138142
return self.openedViewController;
139143
}

lib/ios/RNNStackController.m

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ - (UIStatusBarStyle)preferredStatusBarStyle {
3939
return [_presenter getStatusBarStyle:self.resolveOptions];
4040
}
4141

42+
- (BOOL)prefersStatusBarHidden {
43+
return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
44+
}
45+
4246
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
4347
[self prepareForPop];
4448
return [super popViewControllerAnimated:animated];

lib/ios/UIViewController+LayoutProtocol.m

-4
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
6060
return interfaceOrientationMask;
6161
}
6262

63-
- (BOOL)prefersStatusBarHidden {
64-
return [self.presenter isStatusBarVisibility:self.navigationController resolvedOptions:self.resolveOptions];
65-
}
66-
6763
- (UINavigationController *)stack {
6864
if ([self isKindOfClass:UINavigationController.class]) {
6965
return (UINavigationController *)self;

playground/ios/NavigationTests/RNNTabBarControllerTest.m playground/ios/NavigationTests/BottomTabsControllerTest.m

+27-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
#import <OCMock/OCMock.h>
66
#import <ReactNativeNavigation/BottomTabPresenterCreator.h>
77
#import "RNNBottomTabsController+Helpers.h"
8+
#import "RNNComponentViewController+Utils.h"
89

9-
@interface RNNTabBarControllerTest : XCTestCase
10+
@interface BottomTabsControllerTest : XCTestCase
1011

1112
@property(nonatomic, strong) RNNBottomTabsController * originalUut;
1213
@property(nonatomic, strong) RNNBottomTabsController * uut;
@@ -16,16 +17,17 @@ @interface RNNTabBarControllerTest : XCTestCase
1617

1718
@end
1819

19-
@implementation RNNTabBarControllerTest
20+
@implementation BottomTabsControllerTest
2021

2122
- (void)setUp {
2223
[super setUp];
2324

2425
id tabBarClassMock = OCMClassMock([RNNBottomTabsController class]);
2526
OCMStub([tabBarClassMock parentViewController]).andReturn([OCMockObject partialMockForObject:[RNNBottomTabsController new]]);
26-
NSArray* children = @[[[UIViewController alloc] init]];
27+
UIViewController* childViewController = [RNNComponentViewController createWithComponentId:@"componentId" initialOptions:[RNNNavigationOptions emptyOptions]];
28+
NSArray* children = @[childViewController];
2729
self.mockTabBarPresenter = [OCMockObject partialMockForObject:[[RNNBottomTabsPresenter alloc] init]];
28-
self.mockChildViewController = [OCMockObject partialMockForObject:[RNNComponentViewController new]];
30+
self.mockChildViewController = [OCMockObject partialMockForObject:childViewController];
2931
self.mockEventEmitter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
3032
self.originalUut = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:self.mockTabBarPresenter bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:nil] dotIndicatorPresenter:[[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:nil] eventEmitter:self.mockEventEmitter childViewControllers:children bottomTabsAttacher:nil];
3133
self.uut = [OCMockObject partialMockForObject:self.originalUut];
@@ -101,7 +103,7 @@ - (void)testOnChildAppear_shouldInvokePresenterApplyOptionsWithResolvedOptions {
101103
- (void)testMergeOptions_shouldInvokePresenterMergeOptions {
102104
RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:@{}];
103105

104-
[(RNNBottomTabsPresenter *) [self.mockTabBarPresenter expect] mergeOptions:options resolvedOptions:[self.uut options]];
106+
[(RNNBottomTabsPresenter *) [self.mockTabBarPresenter expect] mergeOptions:options resolvedOptions:[OCMArg any]];
105107
[self.uut mergeOptions:options];
106108
[self.mockTabBarPresenter verify];
107109
}
@@ -142,6 +144,26 @@ - (void)testPreferredStatusBarStyle_shouldInvokeSelectedViewControllerPreferredS
142144
[self.mockTabBarPresenter verify];
143145
}
144146

147+
- (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleTrue {
148+
self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(1)];
149+
XCTAssertFalse(self.uut.prefersStatusBarHidden);
150+
}
151+
152+
- (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleFalse {
153+
self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(0)];
154+
XCTAssertTrue(self.uut.prefersStatusBarHidden);
155+
}
156+
157+
- (void)testPreferredStatusHidden_shouldHideStatusBar {
158+
self.uut.options.statusBar.visible = [Bool withValue:@(1)];
159+
XCTAssertFalse(self.uut.prefersStatusBarHidden);
160+
}
161+
162+
- (void)testPreferredStatusHidden_shouldShowStatusBar {
163+
self.uut.options.statusBar.visible = [Bool withValue:@(0)];
164+
XCTAssertTrue(self.uut.prefersStatusBarHidden);
165+
}
166+
145167
- (void)testTabBarControllerDidSelectViewControllerDelegate_shouldInvokeSendBottomTabSelectedEvent {
146168
NSUInteger selectedIndex = 2;
147169
OCMStub([self.uut selectedIndex]).andReturn(selectedIndex);

playground/ios/NavigationTests/RNNSideMenuControllerTest.m

+24-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ @implementation RNNSideMenuControllerTest
1616
- (void)setUp {
1717
[super setUp];
1818
_creator = [[RNNTestRootViewCreator alloc] init];
19-
_leftVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeLeft];
20-
_rightVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeRight];
21-
_centerVC =[[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeCenter];
22-
self.uut = [[RNNSideMenuController alloc] initWithLayoutInfo:nil creator:nil childViewControllers:@[_leftVC, _centerVC, _rightVC] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil];
19+
_leftVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeLeft];
20+
_rightVC = [[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeRight];
21+
_centerVC =[[RNNSideMenuChildVC alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewController:self.generateComponent type:RNNSideMenuChildTypeCenter];
22+
self.uut = [[RNNSideMenuController alloc] initWithLayoutInfo:nil creator:nil childViewControllers:@[_leftVC, _centerVC, _rightVC] options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:[[RNNSideMenuPresenter alloc] initWithDefaultOptions:nil] eventEmitter:nil];
2323
}
2424

2525
- (RNNComponentViewController *)generateComponent {
@@ -70,4 +70,24 @@ - (void)testResolveOptions {
7070
[self waitForExpectationsWithTimeout:1 handler:nil];
7171
}
7272

73+
- (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleTrue {
74+
self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(1)];
75+
XCTAssertFalse(self.uut.prefersStatusBarHidden);
76+
}
77+
78+
- (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleFalse {
79+
self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(0)];
80+
XCTAssertTrue(self.uut.prefersStatusBarHidden);
81+
}
82+
83+
- (void)testPreferredStatusHidden_shouldHideStatusBar {
84+
self.uut.options.statusBar.visible = [Bool withValue:@(1)];
85+
XCTAssertFalse(self.uut.prefersStatusBarHidden);
86+
}
87+
88+
- (void)testPreferredStatusHidden_shouldShowStatusBar {
89+
self.uut.options.statusBar.visible = [Bool withValue:@(0)];
90+
XCTAssertTrue(self.uut.prefersStatusBarHidden);
91+
}
92+
7393
@end

playground/ios/NavigationTests/RNNStackControllerTest.m

+20
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ - (void)testPreferredStatusBarStyle_shouldReturnLeafPreferredStatusBarStyle {
7070
XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
7171
}
7272

73+
- (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleTrue {
74+
self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(1)];
75+
XCTAssertFalse(self.uut.prefersStatusBarHidden);
76+
}
77+
78+
- (void)testPreferredStatusHidden_shouldResolveChildStatusBarVisibleFalse {
79+
self.uut.getCurrentChild.options.statusBar.visible = [Bool withValue:@(0)];
80+
XCTAssertTrue(self.uut.prefersStatusBarHidden);
81+
}
82+
83+
- (void)testPreferredStatusHidden_shouldHideStatusBar {
84+
self.uut.options.statusBar.visible = [Bool withValue:@(1)];
85+
XCTAssertFalse(self.uut.prefersStatusBarHidden);
86+
}
87+
88+
- (void)testPreferredStatusHidden_shouldShowStatusBar {
89+
self.uut.options.statusBar.visible = [Bool withValue:@(0)];
90+
XCTAssertTrue(self.uut.prefersStatusBarHidden);
91+
}
92+
7393
- (void)testPopGestureEnabled_false {
7494
NSNumber* popGestureEnabled = @(0);
7595
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];

playground/ios/playground.xcodeproj/project.pbxproj

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
E58D26472385888C003F36BA /* RNNRootViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D26262385888B003F36BA /* RNNRootViewControllerTest.m */; };
3131
E58D26482385888C003F36BA /* RNNDotIndicatorPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D26272385888B003F36BA /* RNNDotIndicatorPresenterTest.m */; };
3232
E58D26492385888C003F36BA /* RNNFontAttributesCreatorTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D26282385888B003F36BA /* RNNFontAttributesCreatorTest.m */; };
33-
E58D264A2385888C003F36BA /* RNNTabBarControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D26292385888B003F36BA /* RNNTabBarControllerTest.m */; };
33+
E58D264A2385888C003F36BA /* BottomTabsControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D26292385888B003F36BA /* BottomTabsControllerTest.m */; };
3434
E58D264B2385888C003F36BA /* RNNLayoutManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D262A2385888B003F36BA /* RNNLayoutManagerTest.m */; };
3535
E58D264C2385888C003F36BA /* RNNSideMenuParserTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D262B2385888B003F36BA /* RNNSideMenuParserTest.m */; };
3636
E58D264D2385888C003F36BA /* RNNOverlayManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D262D2385888B003F36BA /* RNNOverlayManagerTest.m */; };
@@ -114,7 +114,7 @@
114114
E58D26262385888B003F36BA /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = "<group>"; };
115115
E58D26272385888B003F36BA /* RNNDotIndicatorPresenterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNDotIndicatorPresenterTest.m; sourceTree = "<group>"; };
116116
E58D26282385888B003F36BA /* RNNFontAttributesCreatorTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNFontAttributesCreatorTest.m; sourceTree = "<group>"; };
117-
E58D26292385888B003F36BA /* RNNTabBarControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNTabBarControllerTest.m; sourceTree = "<group>"; };
117+
E58D26292385888B003F36BA /* BottomTabsControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BottomTabsControllerTest.m; sourceTree = "<group>"; };
118118
E58D262A2385888B003F36BA /* RNNLayoutManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNLayoutManagerTest.m; sourceTree = "<group>"; };
119119
E58D262B2385888B003F36BA /* RNNSideMenuParserTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuParserTest.m; sourceTree = "<group>"; };
120120
E58D262C2385888B003F36BA /* RNNOptionsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNOptionsTest.h; sourceTree = "<group>"; };
@@ -260,6 +260,7 @@
260260
isa = PBXGroup;
261261
children = (
262262
E58D26442385888C003F36BA /* Options */,
263+
E58D262E2385888B003F36BA /* utils */,
263264
E58D26422385888C003F36BA /* RNNBasePresenterTest.m */,
264265
500E9FE62406A4E200C61231 /* BottomTabPresenterTest.m */,
265266
50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */,
@@ -281,7 +282,7 @@
281282
E58D262B2385888B003F36BA /* RNNSideMenuParserTest.m */,
282283
E58D26362385888B003F36BA /* RNNSideMenuPresenterTest.m */,
283284
E58D26312385888B003F36BA /* RNNStackPresenterTest.m */,
284-
E58D26292385888B003F36BA /* RNNTabBarControllerTest.m */,
285+
E58D26292385888B003F36BA /* BottomTabsControllerTest.m */,
285286
5022EDCB240551EE00852BA6 /* RNNBottomTabsAppearancePresenterTest.m */,
286287
E58D26342385888B003F36BA /* RNNTestRootViewCreator.h */,
287288
E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */,
@@ -292,7 +293,6 @@
292293
50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */,
293294
50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */,
294295
50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */,
295-
E58D262E2385888B003F36BA /* utils */,
296296
E58D261F238587F4003F36BA /* Info.plist */,
297297
);
298298
path = NavigationTests;
@@ -770,7 +770,7 @@
770770
501C86B9239FE9C400E0B631 /* UIImage+Utils.m in Sources */,
771771
E58D265F2385888C003F36BA /* RNNBasePresenterTest.m in Sources */,
772772
E58D26542385888C003F36BA /* RNNSideMenuControllerTest.m in Sources */,
773-
E58D264A2385888C003F36BA /* RNNTabBarControllerTest.m in Sources */,
773+
E58D264A2385888C003F36BA /* BottomTabsControllerTest.m in Sources */,
774774
E58D26472385888C003F36BA /* RNNRootViewControllerTest.m in Sources */,
775775
E58D26582385888C003F36BA /* UITabBarController+RNNOptionsTest.m in Sources */,
776776
E58D265A2385888C003F36BA /* RNNTestRootViewCreator.m in Sources */,

0 commit comments

Comments
 (0)