Browse Source

Fix topBar component setDefaultOptions issue (#5710)

* Closes #5622

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

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

165
 }
165
 }
166
 
166
 
167
 - (void)renderComponents:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
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
 - (void)setCustomNavigationTitleView:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
172
 - (void)setCustomNavigationTitleView:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {

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

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

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

198
 }
198
 }
199
 
199
 
200
 - (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
200
 - (void)setCustomNavigationComponentBackground:(RNNNavigationOptions *)options perform:(RNNReactViewReadyCompletionBlock)readyBlock {
201
+    RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
201
 	RNNStackController* stack = self.boundViewController;
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
 		readyBlock();
204
 		readyBlock();
204
 		readyBlock = nil;
205
 		readyBlock = nil;
205
 	}
206
 	}
206
-	if (options.topBar.background.component.name.hasValue) {
207
+	if (withDefault.topBar.background.component.name.hasValue) {
207
 		NSString* currentChildComponentId = [stack getCurrentChild].layoutInfo.componentId;
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
 		_customTopBarBackgroundReactView = reactView;
210
 		_customTopBarBackgroundReactView = reactView;
210
 		
211
 		
211
 	} else {
212
 	} else {

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

161
 	RNNComponentViewController* boundViewController = [RNNComponentViewController new];
161
 	RNNComponentViewController* boundViewController = [RNNComponentViewController new];
162
 	RNNLayoutInfo* layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
162
 	RNNLayoutInfo* layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"];
163
 	boundViewController.layoutInfo = layoutInfo;
163
 	boundViewController.layoutInfo = layoutInfo;
164
+	boundViewController.defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
164
 	[self.uut boundViewController:boundViewController];
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
 	[self.uut renderComponents:self.options perform:nil];
192
 	[self.uut renderComponents:self.options perform:nil];
170
 	[(id)self.componentRegistry verify];
193
 	[(id)self.componentRegistry verify];
171
 	
194