Browse Source

Fix topBar.title.color on popping (#4234)

Yogev Ben David 6 years ago
parent
commit
3162de8235
No account linked to committer's email address

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

78
 		UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
78
 		UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
79
 		if ([controller isKindOfClass:[RNNRootViewController class]]) {
79
 		if ([controller isKindOfClass:[RNNRootViewController class]]) {
80
 			RNNRootViewController *rnnController = (RNNRootViewController *)controller;
80
 			RNNRootViewController *rnnController = (RNNRootViewController *)controller;
81
-			[self setTopBarBackgroundColor:[rnnController.resolveOptions.topBar.background.color getWithDefaultValue:nil]];
81
+			[self.presenter applyOptionsBeforePopping:rnnController.resolveOptions];
82
 		}
82
 		}
83
 	}
83
 	}
84
 	
84
 	

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

2
 
2
 
3
 @interface RNNNavigationControllerPresenter : RNNBasePresenter
3
 @interface RNNNavigationControllerPresenter : RNNBasePresenter
4
 
4
 
5
+- (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options;
6
+
5
 @end
7
 @end

+ 6
- 0
lib/ios/RNNNavigationControllerPresenter.m View File

35
 	[navigationController rnn_setBackButtonIcon:[options.topBar.backButton.icon getWithDefaultValue:nil] withColor:[options.topBar.backButton.color getWithDefaultValue:nil] title:[options.topBar.backButton.showTitle getWithDefaultValue:YES] ? [options.topBar.backButton.title getWithDefaultValue:nil] : @""];
35
 	[navigationController rnn_setBackButtonIcon:[options.topBar.backButton.icon getWithDefaultValue:nil] withColor:[options.topBar.backButton.color getWithDefaultValue:nil] title:[options.topBar.backButton.showTitle getWithDefaultValue:YES] ? [options.topBar.backButton.title getWithDefaultValue:nil] : @""];
36
 }
36
 }
37
 
37
 
38
+- (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options {
39
+	RNNNavigationController* navigationController = self.bindedViewController;
40
+	[navigationController setTopBarBackgroundColor:[options.topBar.background.color getWithDefaultValue:nil]];
41
+	[navigationController rnn_setNavigationBarFontFamily:[options.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.title.fontSize getWithDefaultValue:@(17)] color:[options.topBar.title.color getWithDefaultValue:[UIColor blackColor]]];
42
+}
43
+
38
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
44
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
39
 	[super mergeOptions:newOptions currentOptions:currentOptions defaultOptions:defaultOptions];
45
 	[super mergeOptions:newOptions currentOptions:currentOptions defaultOptions:defaultOptions];
40
 	
46
 	

+ 8
- 0
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerPresenterTest.m View File

92
 	[_bindedViewController verify];
92
 	[_bindedViewController verify];
93
 }
93
 }
94
 
94
 
95
+- (void)testApplyOptionsBefoePoppingShouldSetTopBarBackgroundForPoppingViewController {
96
+	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
97
+	
98
+	[[_bindedViewController expect] setTopBarBackgroundColor:_options.topBar.background.color.get];
99
+	[self.uut applyOptionsBeforePopping:self.options];
100
+	[_bindedViewController verify];
101
+}
102
+
95
 
103
 
96
 
104
 
97
 @end
105
 @end

+ 23
- 12
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m View File

19
 - (void)setUp {
19
 - (void)setUp {
20
     [super setUp];
20
     [super setUp];
21
 	
21
 	
22
-	_vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions]  defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
22
+	_vc1 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNViewControllerPresenter alloc] init]] options:[[RNNNavigationOptions alloc] initEmptyOptions]  defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
23
 	_vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
23
 	_vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
24
 	_vc3 = [UIViewController new];
24
 	_vc3 = [UIViewController new];
25
-	_options = [[RNNNavigationOptions alloc] initEmptyOptions];
26
-	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNViewControllerPresenter alloc] init]];
25
+	_options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]];
26
+	self.uut = [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1, _vc2] options:_options defaultOptions:nil presenter:[OCMockObject partialMockForObject:[[RNNNavigationControllerPresenter alloc] init]]];
27
 }
27
 }
28
 
28
 
29
 - (void)testInitWithLayoutInfo_shouldBindPresenter {
29
 - (void)testInitWithLayoutInfo_shouldBindPresenter {
115
 }
115
 }
116
 
116
 
117
 - (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController {
117
 - (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController {
118
-	RNNNavigationController* uut = [RNNNavigationController new];
119
-	[uut setViewControllers:@[_vc1, _vc2]];
120
-	
121
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
118
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
122
 	[_vc1 overrideOptions:_options];
119
 	[_vc1 overrideOptions:_options];
123
 	
120
 	
124
-	[uut popViewControllerAnimated:NO];
125
-	XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, uut.navigationBar.barTintColor);
121
+	[self.uut popViewControllerAnimated:NO];
122
+	XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
126
 }
123
 }
127
 
124
 
128
 - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
125
 - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
129
-	RNNNavigationController* uut = [RNNNavigationController new];
130
-	[uut setViewControllers:@[_vc1, _vc2]];
131
-
132
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
126
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
133
 	[_vc1 setDefaultOptions:_options];
127
 	[_vc1 setDefaultOptions:_options];
134
 
128
 
129
+	[self.uut popViewControllerAnimated:NO];
130
+	XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.barTintColor);
131
+}
132
+
133
+- (void)testPopViewControllerShouldInvokeApplyOptionsBeforePoppingForDestinationViewController {
134
+	RNNNavigationController* uut = [RNNNavigationController new];
135
+	[uut setViewControllers:@[_vc1, _vc2]];
136
+	
137
+	[[(id)uut.presenter expect] applyOptionsBeforePopping:[OCMArg any]];
138
+	
135
 	[uut popViewControllerAnimated:NO];
139
 	[uut popViewControllerAnimated:NO];
136
-	XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, uut.navigationBar.barTintColor);
140
+	
141
+	[(id)uut.presenter verify];
137
 }
142
 }
138
 
143
 
144
+- (void)testOverrideOptionsShouldOverrideOptionsState {
145
+	RNNNavigationOptions* overrideOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
146
+	[(RNNNavigationOptions*)[(id)self.uut.options expect] overrideOptions:overrideOptions];
147
+	[self.uut overrideOptions:overrideOptions];
148
+	[(id)self.uut.options verify];
149
+}
139
 
150
 
140
 - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
151
 - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
141
 	return [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init]];
152
 	return [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init]];