Bläddra i källkod

Fix Constants.topBarHeight (#5252)

This approach is still not ideal as it assumes there's a visible stack somewhere in the Hierarchy.
It's better than the current implementation so I'm pushing it and will reiterate in the future if needed.
Guy Carmeli 5 år sedan
förälder
incheckning
f19e523afc

+ 2
- 1
lib/ios/Constants.m Visa fil

@@ -1,4 +1,5 @@
1 1
 #import "Constants.h"
2
+#import "UIViewController+LayoutProtocol.h"
2 3
 
3 4
 @implementation Constants
4 5
 
@@ -7,7 +8,7 @@
7 8
 }
8 9
 
9 10
 + (CGFloat)topBarHeight {
10
-	return UIApplication.sharedApplication.delegate.window.rootViewController.navigationController.navigationBar.frame.size.height;
11
+	return [UIApplication .sharedApplication.delegate.window.rootViewController getTopBarHeight];
11 12
 }
12 13
 
13 14
 + (CGFloat)statusBarHeight {

+ 2
- 0
lib/ios/RNNLayoutProtocol.h Visa fil

@@ -21,6 +21,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
21 21
 
22 22
 - (UIViewController<RNNLayoutProtocol> *)getCurrentChild;
23 23
 
24
+- (CGFloat) getTopBarHeight;
25
+
24 26
 - (void)mergeOptions:(RNNNavigationOptions *)options;
25 27
 
26 28
 - (RNNNavigationOptions *)resolveOptions;

+ 4
- 0
lib/ios/RNNNavigationController.m Visa fil

@@ -21,6 +21,10 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
21 21
 	return self.topViewController;
22 22
 }
23 23
 
24
+- (CGFloat)getTopBarHeight {
25
+    return self.navigationBar.frame.size.height;
26
+}
27
+
24 28
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
25 29
 	return self.getCurrentChild.supportedInterfaceOrientations;
26 30
 }

+ 4
- 4
lib/ios/RNNRootViewController.m Visa fil

@@ -1,8 +1,4 @@
1 1
 #import "RNNRootViewController.h"
2
-#import <React/RCTConvert.h>
3
-#import "RNNAnimator.h"
4
-#import "RNNPushAnimation.h"
5
-#import "RNNReactView.h"
6 2
 #import "RNNAnimationsTransitionDelegate.h"
7 3
 #import "UIViewController+LayoutProtocol.h"
8 4
 
@@ -93,6 +89,10 @@
93 89
 	return nil;
94 90
 }
95 91
 
92
+- (CGFloat)getTopBarHeight {
93
+    return [[self getCurrentChild] getTopBarHeight];
94
+}
95
+
96 96
 -(void)updateSearchResultsForSearchController:(UISearchController *)searchController {
97 97
 	[self.eventEmitter sendOnSearchBarUpdated:self.layoutInfo.componentId
98 98
 										 text:searchController.searchBar.text

+ 8
- 4
lib/ios/RNNSideMenuController.m Visa fil

@@ -1,6 +1,4 @@
1 1
 #import "RNNSideMenuController.h"
2
-#import "RNNSideMenuChildVC.h"
3
-#import "MMDrawerController.h"
4 2
 #import "MMDrawerVisualState.h"
5 3
 
6 4
 @interface RNNSideMenuController ()
@@ -92,7 +90,6 @@
92 90
 
93 91
 -(void)setControllers:(NSArray*)controllers {
94 92
 	for (id controller in controllers) {
95
-		
96 93
 		if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
97 94
 			RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;
98 95
 			
@@ -133,7 +130,6 @@
133 130
 			return self.right;
134 131
 		default:
135 132
 			return self.center;
136
-			break;
137 133
 	}
138 134
 }
139 135
 
@@ -141,4 +137,12 @@
141 137
 	return self.center;
142 138
 }
143 139
 
140
+- (CGFloat)getTopBarHeight {
141
+    for(UIViewController * child in [self childViewControllers]) {
142
+        CGFloat childTopBarHeight = [child getTopBarHeight];
143
+        if (childTopBarHeight > 0) return childTopBarHeight;
144
+    }
145
+    return [super getTopBarHeight];
146
+}
147
+
144 148
 @end

+ 8
- 0
lib/ios/RNNTabBarController.m Visa fil

@@ -12,6 +12,14 @@
12 12
 	return self.selectedViewController;
13 13
 }
14 14
 
15
+- (CGFloat)getTopBarHeight {
16
+    for(UIViewController * child in [self childViewControllers]) {
17
+        CGFloat childTopBarHeight = [child getTopBarHeight];
18
+        if (childTopBarHeight > 0) return childTopBarHeight;
19
+    }
20
+    return [super getTopBarHeight];
21
+}
22
+
15 23
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
16 24
 	return self.selectedViewController.supportedInterfaceOrientations;
17 25
 }

+ 4
- 0
lib/ios/UIViewController+LayoutProtocol.m Visa fil

@@ -70,6 +70,10 @@
70 70
 	return nil;
71 71
 }
72 72
 
73
+- (CGFloat)getTopBarHeight {
74
+    return 0;
75
+}
76
+
73 77
 - (void)onChildWillAppear {
74 78
 	[self.presenter applyOptions:self.resolveOptions];
75 79
 	[((UISplitViewController *)self.parentViewController) onChildWillAppear];

+ 4
- 1
playground/src/services/Navigation.js Visa fil

@@ -33,6 +33,8 @@ const compId = (selfOrCompId) => {
33 33
   return get(selfOrCompId, 'props.componentId', selfOrCompId);
34 34
 }
35 35
 
36
+const constants = Navigation.constants;
37
+
36 38
 module.exports = {
37 39
   mergeOptions,
38 40
   push,
@@ -49,5 +51,6 @@ module.exports = {
49 51
   setDefaultOptions: Navigation.setDefaultOptions.bind(Navigation),
50 52
   setRoot: Navigation.setRoot.bind(Navigation),
51 53
   TouchablePreview: Navigation.TouchablePreview,
52
-  setStackRoot
54
+  setStackRoot,
55
+  constants
53 56
 }