Browse Source

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 years ago
parent
commit
f19e523afc

+ 2
- 1
lib/ios/Constants.m View File

1
 #import "Constants.h"
1
 #import "Constants.h"
2
+#import "UIViewController+LayoutProtocol.h"
2
 
3
 
3
 @implementation Constants
4
 @implementation Constants
4
 
5
 
7
 }
8
 }
8
 
9
 
9
 + (CGFloat)topBarHeight {
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
 + (CGFloat)statusBarHeight {
14
 + (CGFloat)statusBarHeight {

+ 2
- 0
lib/ios/RNNLayoutProtocol.h View File

21
 
21
 
22
 - (UIViewController<RNNLayoutProtocol> *)getCurrentChild;
22
 - (UIViewController<RNNLayoutProtocol> *)getCurrentChild;
23
 
23
 
24
+- (CGFloat) getTopBarHeight;
25
+
24
 - (void)mergeOptions:(RNNNavigationOptions *)options;
26
 - (void)mergeOptions:(RNNNavigationOptions *)options;
25
 
27
 
26
 - (RNNNavigationOptions *)resolveOptions;
28
 - (RNNNavigationOptions *)resolveOptions;

+ 4
- 0
lib/ios/RNNNavigationController.m View File

21
 	return self.topViewController;
21
 	return self.topViewController;
22
 }
22
 }
23
 
23
 
24
+- (CGFloat)getTopBarHeight {
25
+    return self.navigationBar.frame.size.height;
26
+}
27
+
24
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
28
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
25
 	return self.getCurrentChild.supportedInterfaceOrientations;
29
 	return self.getCurrentChild.supportedInterfaceOrientations;
26
 }
30
 }

+ 4
- 4
lib/ios/RNNRootViewController.m View File

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

+ 8
- 4
lib/ios/RNNSideMenuController.m View File

1
 #import "RNNSideMenuController.h"
1
 #import "RNNSideMenuController.h"
2
-#import "RNNSideMenuChildVC.h"
3
-#import "MMDrawerController.h"
4
 #import "MMDrawerVisualState.h"
2
 #import "MMDrawerVisualState.h"
5
 
3
 
6
 @interface RNNSideMenuController ()
4
 @interface RNNSideMenuController ()
92
 
90
 
93
 -(void)setControllers:(NSArray*)controllers {
91
 -(void)setControllers:(NSArray*)controllers {
94
 	for (id controller in controllers) {
92
 	for (id controller in controllers) {
95
-		
96
 		if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
93
 		if ([controller isKindOfClass:[RNNSideMenuChildVC class]]) {
97
 			RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;
94
 			RNNSideMenuChildVC *child = (RNNSideMenuChildVC*)controller;
98
 			
95
 			
133
 			return self.right;
130
 			return self.right;
134
 		default:
131
 		default:
135
 			return self.center;
132
 			return self.center;
136
-			break;
137
 	}
133
 	}
138
 }
134
 }
139
 
135
 
141
 	return self.center;
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
 @end
148
 @end

+ 8
- 0
lib/ios/RNNTabBarController.m View File

12
 	return self.selectedViewController;
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
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
23
 - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
16
 	return self.selectedViewController.supportedInterfaceOrientations;
24
 	return self.selectedViewController.supportedInterfaceOrientations;
17
 }
25
 }

+ 4
- 0
lib/ios/UIViewController+LayoutProtocol.m View File

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

+ 4
- 1
playground/src/services/Navigation.js View File

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