Browse Source

Fix topBar component setDefaultOptions issue (#5710)

* Closes #5622

* Fix unit tests
Yogev Ben David 5 years ago
parent
commit
4a1b8b4a64
No account linked to committer's email address

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

@@ -165,7 +165,8 @@
165 165
 }
166 166
 
167 167
 - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
168
-	[self setCustomNavigationTitleView:options perform:readyBlock];
168
+    RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
169
+	[self setCustomNavigationTitleView:withDefault perform:readyBlock];
169 170
 }
170 171
 
171 172
 - (void)setCustomNavigationTitleView:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {

+ 1
- 0
lib/ios/RNNComponentViewController.m View File

@@ -28,6 +28,7 @@
28 28
 }
29 29
 
30 30
 - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
31
+    _defaultOptions = defaultOptions;
31 32
 	[_presenter setDefaultOptions:defaultOptions];
32 33
 }
33 34
 

+ 4
- 3
lib/ios/RNNStackPresenter.m View File

@@ -198,14 +198,15 @@
198 198
 }
199 199
 
200 200
 - (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
201
+    RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
201 202
 	RNNStackController* stack = self.boundViewController;
202
-	if (![options.topBar.background.component.waitForRender getWithDefaultValue:NO] && readyBlock) {
203
+	if (![withDefault.topBar.background.component.waitForRender getWithDefaultValue:NO] && readyBlock) {
203 204
 		readyBlock();
204 205
 		readyBlock = nil;
205 206
 	}
206
-	if (options.topBar.background.component.name.hasValue) {
207
+	if (withDefault.topBar.background.component.name.hasValue) {
207 208
 		NSString* currentChildComponentId = [stack getCurrentChild].layoutInfo.componentId;
208
-		RNNReactView *reactView = [_componentRegistry createComponentIfNotExists:options.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock];
209
+		RNNReactView *reactView = [_componentRegistry createComponentIfNotExists:withDefault.topBar.background.component parentComponentId:currentChildComponentId reactViewReadyBlock:readyBlock];
209 210
 		_customTopBarBackgroundReactView = reactView;
210 211
 		
211 212
 	} else {

+ 25
- 2
playground/ios/NavigationTests/RNNComponentPresenterTest.m View File

@@ -161,11 +161,34 @@
161 161
 	RNNComponentViewController* boundViewController = [RNNComponentViewController new];
162 162
 	RNNLayoutInfo* layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
163 163
 	boundViewController.layoutInfo = layoutInfo;
164
+	boundViewController.defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
164 165
 	[self.uut boundViewController:boundViewController];
165 166
 	
166
-	self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent"}];
167
+	self.options.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent", @"componentId": @"id"}];
167 168
 	
168
-	[[(id)self.componentRegistry expect] createComponentIfNotExists:self.options.topBar.title.component parentComponentId:self.uut.boundComponentId reactViewReadyBlock:[OCMArg any]];
169
+	[[(id)self.componentRegistry expect] createComponentIfNotExists:[OCMArg checkWithBlock:^BOOL(RNNComponentOptions* options) {
170
+		return [options.name.get isEqual:@"titleComponent"] &&
171
+		[options.componentId.get isEqual:@"id"];
172
+	}] parentComponentId:self.uut.boundComponentId reactViewReadyBlock:[OCMArg any]];
173
+	[self.uut renderComponents:self.options perform:nil];
174
+	[(id)self.componentRegistry verify];
175
+	
176
+	
177
+	XCTAssertEqual(self.uut.boundComponentId, @"componentId");
178
+}
179
+
180
+- (void)testRenderComponentsCreateReactViewFromDefaultOptions {
181
+	RNNComponentViewController* boundViewController = [RNNComponentViewController new];
182
+	boundViewController.layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
183
+	self.uut.defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
184
+	[self.uut boundViewController:boundViewController];
185
+	
186
+	self.uut.defaultOptions.topBar.title.component = [[RNNComponentOptions alloc] initWithDict:@{@"name": @"titleComponent", @"componentId": @"id"}];
187
+	
188
+	[[(id)self.componentRegistry expect] createComponentIfNotExists:[OCMArg checkWithBlock:^BOOL(RNNComponentOptions* options) {
189
+		return [options.name.get isEqual:@"titleComponent"] &&
190
+		[options.componentId.get isEqual:@"id"];
191
+	}] parentComponentId:self.uut.boundComponentId reactViewReadyBlock:[OCMArg any]];
169 192
 	[self.uut renderComponents:self.options perform:nil];
170 193
 	[(id)self.componentRegistry verify];
171 194