Browse Source

Resolve options from bottomTabs direct child in mergeChildOptions (#6050)

Solves an issue where setting bottomTabs.badge with mergeOptions resets the bottomTab icon and title.
Yogev Ben David 4 years ago
parent
commit
124f975f42
No account linked to committer's email address

+ 3
- 2
lib/ios/RNNBottomTabsController.m View File

@@ -38,8 +38,9 @@
38 38
 
39 39
 - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
40 40
     [super mergeChildOptions:options child:child];
41
-    [_bottomTabPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
42
-    [_dotIndicatorPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
41
+    UIViewController* childViewController = [self findViewController:child];
42
+    [_bottomTabPresenter mergeOptions:options resolvedOptions:childViewController.resolveOptions child:childViewController];
43
+    [_dotIndicatorPresenter mergeOptions:options resolvedOptions:childViewController.resolveOptions child:childViewController];
43 44
 }
44 45
 
45 46
 - (id<UITabBarControllerDelegate>)delegate {

+ 30
- 0
playground/ios/NavigationTests/RNNCommandsHandlerTest.m View File

@@ -439,6 +439,36 @@
439 439
 	XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]);
440 440
 }
441 441
 
442
+- (void)testMergeOptions_shouldResolveTreeOptions {
443
+	[self.uut setReadyToReceiveCommands:true];
444
+	NSDictionary* mergeOptions = @{@"bottomTab": @{@"badge": @"Badge"}};
445
+	
446
+	RNNNavigationOptions* firstChildOptions = [RNNNavigationOptions emptyOptions];
447
+	
448
+	RNNNavigationOptions* secondChildOptions = [RNNNavigationOptions emptyOptions];
449
+	secondChildOptions.bottomTab.text = [Text withValue:@"Second"];
450
+	RNNNavigationOptions* stackOptions = [RNNNavigationOptions emptyOptions];
451
+	stackOptions.bottomTab.text = [Text withValue:@"First"];
452
+	
453
+	RNNComponentViewController* firstChild = [RNNComponentViewController createWithComponentId:@"first" initialOptions:firstChildOptions];
454
+	RNNStackController* stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:stackOptions defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[firstChild]];
455
+	RNNComponentViewController* secondChild = [RNNComponentViewController createWithComponentId:@"second" initialOptions:secondChildOptions];
456
+	
457
+	RNNBottomTabsController* tabBarController = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:[RNNBasePresenter new] bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:[RNNNavigationOptions emptyOptions]] dotIndicatorPresenter:nil eventEmitter:_eventEmmiter childViewControllers:@[stack, secondChild] bottomTabsAttacher:nil];
458
+	
459
+	OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);
460
+	[self.mainWindow setRootViewController:tabBarController];
461
+	[secondChild viewWillAppear:YES];
462
+	
463
+	[self.uut mergeOptions:firstChild.layoutInfo.componentId options:mergeOptions completion:^{
464
+
465
+	}];
466
+	
467
+	XCTAssertTrue([stack.tabBarItem.badgeValue isEqualToString:@"Badge"]);
468
+	XCTAssertTrue([stack.tabBarItem.title isEqualToString:@"First"]);
469
+	XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]);
470
+}
471
+
442 472
 - (void)testShowModal_shouldShowAnimated {
443 473
 	[self.uut setReadyToReceiveCommands:true];
444 474
 	self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions];