Skip to content

Commit

Permalink
Fix setting bottomTabs.currentTabIndex on bottomTabs init (#4457)
Browse files Browse the repository at this point in the history
  • Loading branch information
yogevbd authored Dec 16, 2018
1 parent e32ed66 commit 631e7db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/ios/RNNTabBarController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
self.presenter = presenter;
[self.presenter bindViewController:self];
[self setViewControllers:childViewControllers];
[self.presenter applyOptionsOnInit:self.options];

return self;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/ios/RNNTabBarPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

@implementation RNNTabBarPresenter

- (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
UITabBarController* tabBarController = self.bindedViewController;
[tabBarController rnn_setCurrentTabIndex:[initialOptions.bottomTabs.currentTabIndex getWithDefaultValue:0]];
}

- (void)applyOptions:(RNNNavigationOptions *)options {
UITabBarController* tabBarController = self.bindedViewController;

Expand Down
11 changes: 10 additions & 1 deletion lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ - (void)testApplyOptions_shouldSetDefaultEmptyOptions {
[self.bindedViewController verify];
}

- (void)testApplyOptions_shouldSetInitialOptions {
- (void)testApplyOptions_shouldApplyOptions {
RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"];
initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]];
Expand All @@ -53,4 +53,13 @@ - (void)testApplyOptions_shouldSetInitialOptions {
[self.bindedViewController verify];
}

- (void)testApplyOptions_shouldApplyOptionsOnInit {
RNNNavigationOptions* initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
initialOptions.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)];
[[self.bindedViewController expect] rnn_setCurrentTabIndex:1];

[self.uut applyOptionsOnInit:initialOptions];
[self.bindedViewController verify];
}

@end

0 comments on commit 631e7db

Please sign in to comment.