Ver código fonte

Fix status bar visibility on iOS 13 (#6084)

This commit fixes statusBar.visible option which stopped working on iOS 13.
Yogev Ben David 4 anos atrás
pai
commit
f487134d8e
Nenhuma conta vinculada ao e-mail do autor do commit

+ 2
- 1
lib/ios/RNNBasePresenter.h Ver arquivo

@@ -43,5 +43,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
43 43
 
44 44
 - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options;
45 45
 
46
-- (BOOL)isStatusBarVisibility:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions;
46
+- (BOOL)statusBarVisibile:(UINavigationController *)stack resolvedOptions:(RNNNavigationOptions *)resolvedOptions;
47
+
47 48
 @end

+ 2
- 2
lib/ios/RNNBasePresenter.m Ver arquivo

@@ -102,8 +102,8 @@
102 102
     return [options withDefault:[self defaultOptions]].layout.supportedOrientations;
103 103
 }
104 104
 
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];
107 107
     if (withDefault.statusBar.visible.hasValue) {
108 108
         return ![withDefault.statusBar.visible get];
109 109
     } else if ([withDefault.statusBar.hideWithTopBar getWithDefaultValue:NO]) {

+ 4
- 0
lib/ios/RNNBottomTabsController.m Ver arquivo

@@ -91,6 +91,10 @@
91 91
 	return [[self presenter] getStatusBarStyle:self.resolveOptions];
92 92
 }
93 93
 
94
+- (BOOL)prefersStatusBarHidden {
95
+    return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
96
+}
97
+
94 98
 #pragma mark UITabBarControllerDelegate
95 99
 
96 100
 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {

+ 4
- 0
lib/ios/RNNComponentViewController.m Ver arquivo

@@ -83,6 +83,10 @@
83 83
 	return [_presenter getStatusBarStyle:[self resolveOptions]];
84 84
 }
85 85
 
86
+- (BOOL)prefersStatusBarHidden {
87
+    return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
88
+}
89
+
86 90
 - (UIViewController *)previewingContext:(id<UIViewControllerPreviewing>)previewingContext viewControllerForLocation:(CGPoint)location{
87 91
 	return self.previewController;
88 92
 }

+ 4
- 0
lib/ios/RNNSideMenuController.m Ver arquivo

@@ -134,6 +134,10 @@
134 134
 	return self.openedViewController.preferredStatusBarStyle;
135 135
 }
136 136
 
137
+- (BOOL)prefersStatusBarHidden {
138
+    return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
139
+}
140
+
137 141
 - (UIViewController<RNNLayoutProtocol> *)getCurrentChild {
138 142
 	return self.openedViewController;
139 143
 }

+ 4
- 0
lib/ios/RNNStackController.m Ver arquivo

@@ -39,6 +39,10 @@
39 39
 	return [_presenter getStatusBarStyle:self.resolveOptions];
40 40
 }
41 41
 
42
+- (BOOL)prefersStatusBarHidden {
43
+    return [self.presenter statusBarVisibile:self.navigationController resolvedOptions:self.resolveOptions];
44
+}
45
+
42 46
 - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
43 47
     [self prepareForPop];
44 48
 	return [super popViewControllerAnimated:animated];

+ 0
- 4
lib/ios/UIViewController+LayoutProtocol.m Ver arquivo

@@ -60,10 +60,6 @@
60 60
 	return interfaceOrientationMask;
61 61
 }
62 62
 
63
-- (BOOL)prefersStatusBarHidden {
64
-    return [self.presenter isStatusBarVisibility:self.navigationController resolvedOptions:self.resolveOptions];
65
-}
66
-
67 63
 - (UINavigationController *)stack {
68 64
     if ([self isKindOfClass:UINavigationController.class]) {
69 65
         return (UINavigationController *)self;

playground/ios/NavigationTests/RNNTabBarControllerTest.m → playground/ios/NavigationTests/BottomTabsControllerTest.m Ver arquivo

@@ -5,8 +5,9 @@
5 5
 #import <OCMock/OCMock.h>
6 6
 #import <ReactNativeNavigation/BottomTabPresenterCreator.h>
7 7
 #import "RNNBottomTabsController+Helpers.h"
8
+#import "RNNComponentViewController+Utils.h"
8 9
 
9
-@interface RNNTabBarControllerTest : XCTestCase
10
+@interface BottomTabsControllerTest : XCTestCase
10 11
 
11 12
 @property(nonatomic, strong) RNNBottomTabsController * originalUut;
12 13
 @property(nonatomic, strong) RNNBottomTabsController * uut;
@@ -16,16 +17,17 @@
16 17
 
17 18
 @end
18 19
 
19
-@implementation RNNTabBarControllerTest
20
+@implementation BottomTabsControllerTest
20 21
 
21 22
 - (void)setUp {
22 23
     [super setUp];
23 24
 
24 25
     id tabBarClassMock = OCMClassMock([RNNBottomTabsController class]);
25 26
     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];
27 29
     self.mockTabBarPresenter = [OCMockObject partialMockForObject:[[RNNBottomTabsPresenter alloc] init]];
28
-    self.mockChildViewController = [OCMockObject partialMockForObject:[RNNComponentViewController new]];
30
+    self.mockChildViewController = [OCMockObject partialMockForObject:childViewController];
29 31
     self.mockEventEmitter = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
30 32
 	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];
31 33
     self.uut = [OCMockObject partialMockForObject:self.originalUut];
@@ -101,7 +103,7 @@
101 103
 - (void)testMergeOptions_shouldInvokePresenterMergeOptions {
102 104
     RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:@{}];
103 105
 
104
-    [(RNNBottomTabsPresenter *) [self.mockTabBarPresenter expect] mergeOptions:options resolvedOptions:[self.uut options]];
106
+    [(RNNBottomTabsPresenter *) [self.mockTabBarPresenter expect] mergeOptions:options resolvedOptions:[OCMArg any]];
105 107
     [self.uut mergeOptions:options];
106 108
     [self.mockTabBarPresenter verify];
107 109
 }
@@ -142,6 +144,26 @@
142 144
     [self.mockTabBarPresenter verify];
143 145
 }
144 146
 
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
+
145 167
 - (void)testTabBarControllerDidSelectViewControllerDelegate_shouldInvokeSendBottomTabSelectedEvent {
146 168
     NSUInteger selectedIndex = 2;
147 169
     OCMStub([self.uut selectedIndex]).andReturn(selectedIndex);

+ 24
- 4
playground/ios/NavigationTests/RNNSideMenuControllerTest.m Ver arquivo

@@ -16,10 +16,10 @@
16 16
 - (void)setUp {
17 17
     [super setUp];
18 18
 	_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];
23 23
 }
24 24
 
25 25
 - (RNNComponentViewController *)generateComponent {
@@ -70,4 +70,24 @@
70 70
     [self waitForExpectationsWithTimeout:1 handler:nil];
71 71
 }
72 72
 
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
+
73 93
 @end

+ 20
- 0
playground/ios/NavigationTests/RNNStackControllerTest.m Ver arquivo

@@ -70,6 +70,26 @@
70 70
 	XCTAssertTrue(self.uut.preferredStatusBarStyle == self.uut.getCurrentChild.preferredStatusBarStyle);
71 71
 }
72 72
 
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
+
73 93
 - (void)testPopGestureEnabled_false {
74 94
 	NSNumber* popGestureEnabled = @(0);
75 95
 	RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];

+ 5
- 5
playground/ios/playground.xcodeproj/project.pbxproj Ver arquivo

@@ -30,7 +30,7 @@
30 30
 		E58D26472385888C003F36BA /* RNNRootViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D26262385888B003F36BA /* RNNRootViewControllerTest.m */; };
31 31
 		E58D26482385888C003F36BA /* RNNDotIndicatorPresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D26272385888B003F36BA /* RNNDotIndicatorPresenterTest.m */; };
32 32
 		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 */; };
34 34
 		E58D264B2385888C003F36BA /* RNNLayoutManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D262A2385888B003F36BA /* RNNLayoutManagerTest.m */; };
35 35
 		E58D264C2385888C003F36BA /* RNNSideMenuParserTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D262B2385888B003F36BA /* RNNSideMenuParserTest.m */; };
36 36
 		E58D264D2385888C003F36BA /* RNNOverlayManagerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D262D2385888B003F36BA /* RNNOverlayManagerTest.m */; };
@@ -114,7 +114,7 @@
114 114
 		E58D26262385888B003F36BA /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = "<group>"; };
115 115
 		E58D26272385888B003F36BA /* RNNDotIndicatorPresenterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNDotIndicatorPresenterTest.m; sourceTree = "<group>"; };
116 116
 		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>"; };
118 118
 		E58D262A2385888B003F36BA /* RNNLayoutManagerTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNLayoutManagerTest.m; sourceTree = "<group>"; };
119 119
 		E58D262B2385888B003F36BA /* RNNSideMenuParserTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuParserTest.m; sourceTree = "<group>"; };
120 120
 		E58D262C2385888B003F36BA /* RNNOptionsTest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNOptionsTest.h; sourceTree = "<group>"; };
@@ -260,6 +260,7 @@
260 260
 			isa = PBXGroup;
261 261
 			children = (
262 262
 				E58D26442385888C003F36BA /* Options */,
263
+				E58D262E2385888B003F36BA /* utils */,
263 264
 				E58D26422385888C003F36BA /* RNNBasePresenterTest.m */,
264 265
 				500E9FE62406A4E200C61231 /* BottomTabPresenterTest.m */,
265 266
 				50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */,
@@ -281,7 +282,7 @@
281 282
 				E58D262B2385888B003F36BA /* RNNSideMenuParserTest.m */,
282 283
 				E58D26362385888B003F36BA /* RNNSideMenuPresenterTest.m */,
283 284
 				E58D26312385888B003F36BA /* RNNStackPresenterTest.m */,
284
-				E58D26292385888B003F36BA /* RNNTabBarControllerTest.m */,
285
+				E58D26292385888B003F36BA /* BottomTabsControllerTest.m */,
285 286
 				5022EDCB240551EE00852BA6 /* RNNBottomTabsAppearancePresenterTest.m */,
286 287
 				E58D26342385888B003F36BA /* RNNTestRootViewCreator.h */,
287 288
 				E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */,
@@ -292,7 +293,6 @@
292 293
 				50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */,
293 294
 				50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */,
294 295
 				50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */,
295
-				E58D262E2385888B003F36BA /* utils */,
296 296
 				E58D261F238587F4003F36BA /* Info.plist */,
297 297
 			);
298 298
 			path = NavigationTests;
@@ -770,7 +770,7 @@
770 770
 				501C86B9239FE9C400E0B631 /* UIImage+Utils.m in Sources */,
771 771
 				E58D265F2385888C003F36BA /* RNNBasePresenterTest.m in Sources */,
772 772
 				E58D26542385888C003F36BA /* RNNSideMenuControllerTest.m in Sources */,
773
-				E58D264A2385888C003F36BA /* RNNTabBarControllerTest.m in Sources */,
773
+				E58D264A2385888C003F36BA /* BottomTabsControllerTest.m in Sources */,
774 774
 				E58D26472385888C003F36BA /* RNNRootViewControllerTest.m in Sources */,
775 775
 				E58D26582385888C003F36BA /* UITabBarController+RNNOptionsTest.m in Sources */,
776 776
 				E58D265A2385888C003F36BA /* RNNTestRootViewCreator.m in Sources */,