Browse Source

Fixes large title - #4192 (#4200)

Yogev Ben David 5 years ago
parent
commit
e5cf52f08c
No account linked to committer's email address

+ 3
- 1
lib/ios/RNNNavigationController.m View File

@@ -72,7 +72,7 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
72 72
 		UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
73 73
 		if ([controller isKindOfClass:[RNNRootViewController class]]) {
74 74
 			RNNRootViewController *rnnController = (RNNRootViewController *)controller;
75
-			[self.presenter applyOptions:rnnController.options];
75
+			[self setTopBarBackgroundColor:[rnnController.options.topBar.background.color getWithDefaultValue:nil]];
76 76
 		}
77 77
 	}
78 78
 	
@@ -129,6 +129,8 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
129 129
 			self.navigationBar.shadowImage = self.originalTopBarImages[@"shadowImage"] ? self.originalTopBarImages[@"shadowImage"] : self.navigationBar.shadowImage;
130 130
 			self.originalTopBarImages = nil;
131 131
 		}
132
+		
133
+		self.navigationBar.barTintColor = nil;
132 134
 	}
133 135
 }
134 136
 

+ 1
- 1
lib/ios/RNNSideMenuPresenter.m View File

@@ -19,7 +19,7 @@
19 19
 	[sideMenuController setAnimationVelocityLeft:[options.sideMenu.left.animationVelocity getWithDefaultValue:840.0f]];
20 20
 	[sideMenuController setAnimationVelocityRight:[options.sideMenu.right.animationVelocity getWithDefaultValue:840.0f]];
21 21
 	
22
-	[sideMenuController setAnimationType:[options.sideMenu.animationType getWithDefaultValue:@"door"]];
22
+	[sideMenuController setAnimationType:[options.sideMenu.animationType getWithDefaultValue:nil]];
23 23
 
24 24
 	if (options.sideMenu.left.width.hasValue) {
25 25
 		[sideMenuController side:MMDrawerSideLeft width:options.sideMenu.left.width.get];

+ 2
- 2
lib/ios/RNNViewControllerPresenter.m View File

@@ -17,10 +17,8 @@
17 17
 	
18 18
 	UIViewController* viewController = self.bindedViewController;
19 19
 	[viewController rnn_setBackgroundImage:[options.backgroundImage getWithDefaultValue:nil]];
20
-	[viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
21 20
 	[viewController rnn_setNavigationItemTitle:[options.topBar.title.text getWithDefaultValue:nil]];
22 21
 	[viewController rnn_setTopBarPrefersLargeTitle:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
23
-	[viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
24 22
 	[viewController rnn_setTabBarItemBadgeColor:[options.bottomTab.badgeColor getWithDefaultValue:nil]];
25 23
 	[viewController rnn_setStatusBarBlur:[options.statusBar.blur getWithDefaultValue:NO]];
26 24
 	[viewController rnn_setStatusBarStyle:[options.statusBar.style getWithDefaultValue:@"default"] animated:[options.statusBar.animate getWithDefaultValue:YES]];
@@ -47,6 +45,8 @@
47 45
 	UIViewController* viewController = self.bindedViewController;
48 46
 	[viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[options.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
49 47
 	[viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
48
+	[viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
49
+	[viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
50 50
 }
51 51
 
52 52
 - (void)mergeOptions:(RNNNavigationOptions *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions {

+ 0
- 28
lib/ios/ReactNativeNavigationTests/RNNRootViewControllerTest.m View File

@@ -546,34 +546,6 @@
546 546
 //	XCTAssertTrue([[(UIImageView*)self.uut.view.subviews[0] image] isEqual:backgroundImage]);
547 547
 //}
548 548
 
549
--(void)testTopBarDrawUnder_true {
550
-	self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(1)];
551
-	[self.uut viewWillAppear:false];
552
-
553
-	XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
554
-}
555
-
556
--(void)testTopBarDrawUnder_false {
557
-	self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(0)];
558
-	[self.uut viewWillAppear:false];
559
-
560
-	XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeTop);
561
-}
562
-
563
--(void)testBottomTabsDrawUnder_true {
564
-	self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(1)];
565
-	[self.uut viewWillAppear:false];
566
-
567
-	XCTAssertTrue(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
568
-}
569
-
570
--(void)testBottomTabsDrawUnder_false {
571
-	self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(0)];
572
-	[self.uut viewWillAppear:false];
573
-
574
-	XCTAssertFalse(self.uut.edgesForExtendedLayout & UIRectEdgeBottom);
575
-}
576
-
577 549
 #pragma mark BottomTabs
578 550
 
579 551
 

+ 1
- 1
lib/ios/ReactNativeNavigationTests/RNNSideMenuPresenterTest.m View File

@@ -30,7 +30,7 @@
30 30
 	[[self.bindedViewController expect] setAnimationVelocityRight:840.0f];
31 31
 	[[self.bindedViewController reject] side:MMDrawerSideLeft width:0];
32 32
 	[[self.bindedViewController reject] side:MMDrawerSideRight width:0];
33
-  [[self.bindedViewController expect] setAnimationType:@"door"];
33
+  	[[self.bindedViewController expect] setAnimationType:nil];
34 34
     
35 35
 	[self.uut applyOptions:self.options];
36 36
 

+ 35
- 3
lib/ios/ReactNativeNavigationTests/RNNViewControllerPresenterTest.m View File

@@ -21,9 +21,9 @@
21 21
 	self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
22 22
 }
23 23
 
24
-- (void)testApplyOptions_backgroundImageDefaultNil {
24
+- (void)testApplyOptions_backgroundImageDefaultNilShouldNotAddSubview {
25 25
 	[self.uut applyOptions:self.options];
26
-	XCTAssertNil(((UIImageView *)self.bindedViewController.view.subviews[0]).image);
26
+	XCTAssertTrue((self.bindedViewController.view.subviews.count) == 0);
27 27
 }
28 28
 
29 29
 - (void)testApplyOptions_topBarPrefersLargeTitleDefaultFalse {
@@ -55,7 +55,7 @@
55 55
 - (void)testApplyOptions_drawBehindTabBarTrueWhenVisibleFalse {
56 56
 	self.options.bottomTabs.visible = [[Bool alloc] initWithValue:@(0)];
57 57
 	[[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
58
-	[self.uut applyOptions:self.options];
58
+	[self.uut applyOptionsOnInit:self.options];
59 59
 	[(id)self.bindedViewController verify];
60 60
 }
61 61
 
@@ -85,4 +85,36 @@
85 85
 	[(id)self.bindedViewController verify];
86 86
 }
87 87
 
88
+-(void)testApplyOptionsOnInit_TopBarDrawUnder_true {
89
+    self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(1)];
90
+    
91
+    [[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:YES];
92
+    [self.uut applyOptionsOnInit:self.options];
93
+    [(id)self.bindedViewController verify];
94
+}
95
+
96
+-(void)testApplyOptionsOnInit_TopBarDrawUnder_false {
97
+    self.options.topBar.drawBehind = [[Bool alloc] initWithValue:@(0)];
98
+    
99
+    [[(id)self.bindedViewController expect] rnn_setDrawBehindTopBar:NO];
100
+    [self.uut applyOptionsOnInit:self.options];
101
+    [(id)self.bindedViewController verify];
102
+}
103
+
104
+-(void)testApplyOptionsOnInit_BottomTabsDrawUnder_true {
105
+    self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(1)];
106
+    
107
+    [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:YES];
108
+    [self.uut applyOptionsOnInit:self.options];
109
+    [(id)self.bindedViewController verify];
110
+}
111
+
112
+-(void)testApplyOptionsOnInit_BottomTabsDrawUnder_false {
113
+    self.options.bottomTabs.drawBehind = [[Bool alloc] initWithValue:@(0)];
114
+    
115
+    [[(id)self.bindedViewController expect] rnn_setDrawBehindTabBar:NO];
116
+    [self.uut applyOptionsOnInit:self.options];
117
+    [(id)self.bindedViewController verify];
118
+}
119
+
88 120
 @end

+ 17
- 0
lib/ios/ReactNativeNavigationTests/UIViewController+RNNOptionsTest.m View File

@@ -71,6 +71,23 @@
71 71
 	XCTAssertEqual([self.uut edgesForExtendedLayout], expectedRectEdge);
72 72
 }
73 73
 
74
+- (void)testSetBackgroundImageShouldNotAddViewIfImageNil {
75
+	NSUInteger subviewsCount = [[[self.uut view] subviews] count];
76
+	[self.uut rnn_setBackgroundImage:nil];
77
+	XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount);
78
+}
79
+
80
+- (void)testSetBackgroundImageShouldAddUIImageViewSubview {
81
+	NSUInteger subviewsCount = [[[self.uut view] subviews] count];
82
+	[self.uut rnn_setBackgroundImage:[UIImage new]];
83
+	XCTAssertEqual([[[self.uut view] subviews] count], subviewsCount+1);
84
+}
74 85
 
86
+- (void)testSetBackgroundImageShouldAddUIImageViewSubviewWithImage {
87
+	UIImage* image = [UIImage new];
88
+	[self.uut rnn_setBackgroundImage:image];
89
+	UIImageView* imageView = [[[self.uut view] subviews] firstObject];
90
+	XCTAssertEqual(imageView.image, image);
91
+}
75 92
 
76 93
 @end

+ 10
- 8
lib/ios/UIViewController+RNNOptions.m View File

@@ -5,15 +5,17 @@ const NSInteger BLUR_STATUS_TAG = 78264801;
5 5
 @implementation UIViewController (RNNOptions)
6 6
 
7 7
 - (void)rnn_setBackgroundImage:(UIImage *)backgroundImage {
8
-	UIImageView* backgroundImageView = (self.view.subviews.count > 0) ? self.view.subviews[0] : nil;
9
-	if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
10
-		backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
11
-		[self.view insertSubview:backgroundImageView atIndex:0];
8
+	if (backgroundImage) {
9
+		UIImageView* backgroundImageView = (self.view.subviews.count > 0) ? self.view.subviews[0] : nil;
10
+		if (![backgroundImageView isKindOfClass:[UIImageView class]]) {
11
+			backgroundImageView = [[UIImageView alloc] initWithFrame:self.view.bounds];
12
+			[self.view insertSubview:backgroundImageView atIndex:0];
13
+		}
14
+		
15
+		backgroundImageView.layer.masksToBounds = YES;
16
+		backgroundImageView.image = backgroundImage;
17
+		[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
12 18
 	}
13
-	
14
-	backgroundImageView.layer.masksToBounds = YES;
15
-	backgroundImageView.image = backgroundImage;
16
-	[backgroundImageView setContentMode:UIViewContentModeScaleAspectFill];
17 19
 }
18 20
 
19 21
 - (void)rnn_setModalPresentationStyle:(UIModalPresentationStyle)modalPresentationStyle {