Browse Source

fix custom header (#3798)

* fix custom header

* fix e2e
Yogev Ben David 6 years ago
parent
commit
5162f17bef
No account linked to committer's email address

+ 11
- 0
lib/ios/RNNReactRootView.h View File

@@ -0,0 +1,11 @@
1
+#import <UIKit/UIKit.h>
2
+#import <React/RCTRootView.h>
3
+#import <React/RCTRootViewDelegate.h>
4
+
5
+@interface RNNReactRootView : RCTRootView <RCTRootViewDelegate>
6
+
7
+@property (nonatomic, copy) void (^rootViewDidChangeIntrinsicSize)(CGSize intrinsicSize);
8
+
9
+- (void)setAlignment:(NSString*)alignment;
10
+
11
+@end

+ 24
- 0
lib/ios/RNNReactRootView.m View File

@@ -0,0 +1,24 @@
1
+#import "RNNReactRootView.h"
2
+
3
+@implementation RNNReactRootView
4
+
5
+- (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
6
+	_rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
7
+	self.delegate = self;
8
+}
9
+
10
+- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
11
+	if (_rootViewDidChangeIntrinsicSize) {
12
+		_rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
13
+	}
14
+}
15
+
16
+- (void)setAlignment:(NSString *)alignment {
17
+	if ([alignment isEqualToString:@"fill"]) {
18
+		self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
19
+	} else {
20
+		self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
21
+	}
22
+}
23
+
24
+@end

+ 1
- 9
lib/ios/RNNReactRootViewCreator.m View File

@@ -1,14 +1,6 @@
1 1
 
2 2
 #import "RNNReactRootViewCreator.h"
3
-#import <React/RCTRootView.h>
4
-
5
-@interface RNNReactRootView : RCTRootView
6
-
7
-@end
8
-
9
-@implementation RNNReactRootView
10
-
11
-@end
3
+#import "RNNReactRootView.h"
12 4
 
13 5
 @implementation RNNReactRootViewCreator {
14 6
 	RCTBridge *_bridge;

+ 12
- 7
lib/ios/RNNRootViewController.m View File

@@ -4,9 +4,10 @@
4 4
 #import "RNNAnimator.h"
5 5
 #import "RNNCustomTitleView.h"
6 6
 #import "RNNPushAnimation.h"
7
+#import "RNNReactRootView.h"
7 8
 
8 9
 @interface RNNRootViewController() {
9
-	UIView* _customTitleView;
10
+	RNNReactRootView* _customTitleView;
10 11
 	UIView* _customTopBar;
11 12
 	UIView* _customTopBarBackground;
12 13
 }
@@ -137,14 +138,18 @@
137 138
 - (void)setCustomNavigationTitleView {
138 139
 	if (!_customTitleView) {
139 140
 		if (self.options.topBar.title.component.name) {
140
-			RCTRootView *reactView = (RCTRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.title.component];
141
-			
142
-			_customTitleView = [[RNNCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:self.options.topBar.title.component.alignment];
143
-			reactView.backgroundColor = UIColor.clearColor;
141
+			_customTitleView = (RNNReactRootView*)[_creator createRootViewFromComponentOptions:self.options.topBar.title.component];
144 142
 			_customTitleView.backgroundColor = UIColor.clearColor;
143
+			[_customTitleView setAlignment:self.options.topBar.title.component.alignment];
144
+			BOOL isCenter = [self.options.topBar.title.component.alignment isEqualToString:@"center"];
145
+			__weak RNNReactRootView *weakTitleView = _customTitleView;
146
+			[_customTitleView setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicContentSize) {
147
+				if (isCenter) {
148
+					[weakTitleView setFrame:CGRectMake(0, 0, intrinsicContentSize.width, intrinsicContentSize.height)];
149
+				}
150
+			}];
151
+			[_customTitleView setFrame:self.navigationController.navigationBar.frame];
145 152
 			self.navigationItem.titleView = _customTitleView;
146
-		} if ([self.navigationItem.title isKindOfClass:[RNNCustomTitleView class]] && !_customTitleView) {
147
-			self.navigationItem.title = nil;
148 153
 		}
149 154
 	} else if (_customTitleView && _customTitleView.superview == nil) {
150 155
 		if ([self.navigationItem.title isKindOfClass:[RNNCustomTitleView class]] && !_customTitleView) {

+ 8
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj View File

@@ -67,6 +67,8 @@
67 67
 		5016E8F020209690009D4F7C /* RNNCustomTitleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5016E8EE2020968F009D4F7C /* RNNCustomTitleView.m */; };
68 68
 		50175CD1207A2AA1004FE91B /* RNNComponentOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50175CCF207A2AA1004FE91B /* RNNComponentOptions.h */; };
69 69
 		50175CD2207A2AA1004FE91B /* RNNComponentOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */; };
70
+		50220F48212ABDFD004C2B0A /* RNNReactRootView.h in Headers */ = {isa = PBXBuildFile; fileRef = 50220F46212ABDFD004C2B0A /* RNNReactRootView.h */; };
71
+		50220F49212ABDFD004C2B0A /* RNNReactRootView.m in Sources */ = {isa = PBXBuildFile; fileRef = 50220F47212ABDFD004C2B0A /* RNNReactRootView.m */; };
70 72
 		502CB43A20CBCA180019B2FE /* RNNBridgeManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
71 73
 		502CB46E20CD1DDA0019B2FE /* RNNBackButtonOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 502CB46C20CD1DDA0019B2FE /* RNNBackButtonOptions.h */; };
72 74
 		502CB46F20CD1DDA0019B2FE /* RNNBackButtonOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 502CB46D20CD1DDA0019B2FE /* RNNBackButtonOptions.m */; };
@@ -291,6 +293,8 @@
291 293
 		5016E8EE2020968F009D4F7C /* RNNCustomTitleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNCustomTitleView.m; sourceTree = "<group>"; };
292 294
 		50175CCF207A2AA1004FE91B /* RNNComponentOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNComponentOptions.h; sourceTree = "<group>"; };
293 295
 		50175CD0207A2AA1004FE91B /* RNNComponentOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNComponentOptions.m; sourceTree = "<group>"; };
296
+		50220F46212ABDFD004C2B0A /* RNNReactRootView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNReactRootView.h; sourceTree = "<group>"; };
297
+		50220F47212ABDFD004C2B0A /* RNNReactRootView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNReactRootView.m; sourceTree = "<group>"; };
294 298
 		502CB43920CBCA140019B2FE /* RNNBridgeManagerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBridgeManagerDelegate.h; sourceTree = "<group>"; };
295 299
 		502CB46C20CD1DDA0019B2FE /* RNNBackButtonOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBackButtonOptions.h; sourceTree = "<group>"; };
296 300
 		502CB46D20CD1DDA0019B2FE /* RNNBackButtonOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBackButtonOptions.m; sourceTree = "<group>"; };
@@ -642,6 +646,8 @@
642 646
 				504AFE611FFE52EF0076E904 /* Options */,
643 647
 				50D031312005146C00386B3D /* Managers */,
644 648
 				50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */,
649
+				50220F46212ABDFD004C2B0A /* RNNReactRootView.h */,
650
+				50220F47212ABDFD004C2B0A /* RNNReactRootView.m */,
645 651
 				50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */,
646 652
 				26916C941E4B9CCC00D13680 /* RNNRootViewCreator.h */,
647 653
 				26916C961E4B9E7700D13680 /* RNNReactRootViewCreator.h */,
@@ -889,6 +895,7 @@
889 895
 				E8E5182E1F83A48B000467AC /* RNNTransitionStateHolder.h in Headers */,
890 896
 				50887CAA20F26BFE00D06111 /* RNNOverlayWindow.h in Headers */,
891 897
 				507E7D57201DDD3000444E6C /* RNNAnimationOptions.h in Headers */,
898
+				50220F48212ABDFD004C2B0A /* RNNReactRootView.h in Headers */,
892 899
 				2DCD9195200014A900EDC75D /* RNNBridgeManager.h in Headers */,
893 900
 				7B1126A91E2D2B6C00F9B03B /* RNNControllerFactory.h in Headers */,
894 901
 				263905D61E4C94970023D7D3 /* RNNSideMenuController.h in Headers */,
@@ -1063,6 +1070,7 @@
1063 1070
 				50EB4ED82068EBE000D6ED34 /* RNNBackgroundOptions.m in Sources */,
1064 1071
 				507F43CA1FF4F9CC00D9425B /* RNNTopTabOptions.m in Sources */,
1065 1072
 				26916C991E4B9E7700D13680 /* RNNReactRootViewCreator.m in Sources */,
1073
+				50220F49212ABDFD004C2B0A /* RNNReactRootView.m in Sources */,
1066 1074
 				5064495E20DC62B90026709C /* RNNSideMenuSideOptions.m in Sources */,
1067 1075
 				214545251F4DC125006E8DA1 /* RNNUIBarButtonItem.m in Sources */,
1068 1076
 				263905B81E4C6F440023D7D3 /* UIViewController+MMDrawerController.m in Sources */,