Преглед на файлове

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

Yogev Ben David преди 6 години
родител
ревизия
3162de8235
No account linked to committer's email address

+ 1
- 1
lib/ios/RNNNavigationController.m Целия файл

@@ -78,7 +78,7 @@ const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
78 78
 		UIViewController *controller = self.viewControllers[self.viewControllers.count - 2];
79 79
 		if ([controller isKindOfClass:[RNNRootViewController class]]) {
80 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 Целия файл

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

+ 6
- 0
lib/ios/RNNNavigationControllerPresenter.m Целия файл

@@ -35,6 +35,12 @@
35 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 44
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
39 45
 	[super mergeOptions:newOptions currentOptions:currentOptions defaultOptions:defaultOptions];
40 46
 	

+ 8
- 0
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerPresenterTest.m Целия файл

@@ -92,6 +92,14 @@
92 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 105
 @end

+ 23
- 12
lib/ios/ReactNativeNavigationTests/RNNNavigationControllerTest.m Целия файл

@@ -19,11 +19,11 @@
19 19
 - (void)setUp {
20 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 23
 	_vc2 = [[RNNRootViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:[[RNNViewControllerPresenter alloc] init] options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]];
24 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 29
 - (void)testInitWithLayoutInfo_shouldBindPresenter {
@@ -115,27 +115,38 @@
115 115
 }
116 116
 
117 117
 - (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController {
118
-	RNNNavigationController* uut = [RNNNavigationController new];
119
-	[uut setViewControllers:@[_vc1, _vc2]];
120
-	
121 118
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
122 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 125
 - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
129
-	RNNNavigationController* uut = [RNNNavigationController new];
130
-	[uut setViewControllers:@[_vc1, _vc2]];
131
-
132 126
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
133 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 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 151
 - (RNNNavigationController *)createNavigationControllerWithOptions:(RNNNavigationOptions *)options {
141 152
 	return [[RNNNavigationController alloc] initWithLayoutInfo:nil childViewControllers:@[_vc1] options:options defaultOptions:nil presenter:[[RNNNavigationControllerPresenter alloc] init]];