Skip to content

Commit

Permalink
Resolve options from bottomTabs direct child in mergeChildOptions (#6050
Browse files Browse the repository at this point in the history
)

Solves an issue where setting bottomTabs.badge with mergeOptions resets the bottomTab icon and title.
  • Loading branch information
yogevbd authored Mar 17, 2020
1 parent 3f8577d commit 124f975
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ - (void)onChildAddToParent:(UIViewController *)child options:(RNNNavigationOptio

- (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewController *)child {
[super mergeChildOptions:options child:child];
[_bottomTabPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
[_dotIndicatorPresenter mergeOptions:options resolvedOptions:child.resolveOptions child:[self findViewController:child]];
UIViewController* childViewController = [self findViewController:child];
[_bottomTabPresenter mergeOptions:options resolvedOptions:childViewController.resolveOptions child:childViewController];
[_dotIndicatorPresenter mergeOptions:options resolvedOptions:childViewController.resolveOptions child:childViewController];
}

- (id<UITabBarControllerDelegate>)delegate {
Expand Down
30 changes: 30 additions & 0 deletions playground/ios/NavigationTests/RNNCommandsHandlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,36 @@ - (void)testMergeOptions_shouldMergeWithChildOnly {
XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]);
}

- (void)testMergeOptions_shouldResolveTreeOptions {
[self.uut setReadyToReceiveCommands:true];
NSDictionary* mergeOptions = @{@"bottomTab": @{@"badge": @"Badge"}};

RNNNavigationOptions* firstChildOptions = [RNNNavigationOptions emptyOptions];

RNNNavigationOptions* secondChildOptions = [RNNNavigationOptions emptyOptions];
secondChildOptions.bottomTab.text = [Text withValue:@"Second"];
RNNNavigationOptions* stackOptions = [RNNNavigationOptions emptyOptions];
stackOptions.bottomTab.text = [Text withValue:@"First"];

RNNComponentViewController* firstChild = [RNNComponentViewController createWithComponentId:@"first" initialOptions:firstChildOptions];
RNNStackController* stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:stackOptions defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:@[firstChild]];
RNNComponentViewController* secondChild = [RNNComponentViewController createWithComponentId:@"second" initialOptions:secondChildOptions];

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];

OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);
[self.mainWindow setRootViewController:tabBarController];
[secondChild viewWillAppear:YES];

[self.uut mergeOptions:firstChild.layoutInfo.componentId options:mergeOptions completion:^{

}];

XCTAssertTrue([stack.tabBarItem.badgeValue isEqualToString:@"Badge"]);
XCTAssertTrue([stack.tabBarItem.title isEqualToString:@"First"]);
XCTAssertTrue([secondChild.tabBarItem.title isEqualToString:@"Second"]);
}

- (void)testShowModal_shouldShowAnimated {
[self.uut setReadyToReceiveCommands:true];
self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions];
Expand Down

0 comments on commit 124f975

Please sign in to comment.