Skip to content

Commit

Permalink
fix: first tab being rendered when onSwitchToTab and a custom current…
Browse files Browse the repository at this point in the history
…TabIndex is set (#7922)
  • Loading branch information
ismarbesic authored Oct 15, 2024
1 parent 8c64969 commit 985a827
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
_bottomTabPresenter = bottomTabPresenter;
_dotIndicatorPresenter = dotIndicatorPresenter;

if ([options.bottomTabs.currentTabIndex hasValue]) {
_currentTabIndex = [options.bottomTabs.currentTabIndex get];
_previousTabIndex = _currentTabIndex;
}

self = [super initWithLayoutInfo:layoutInfo
creator:creator
options:options
Expand Down
34 changes: 34 additions & 0 deletions playground/ios/NavigationTests/RNNCommandsHandlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,40 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab {
XCTAssertTrue(_vc2.isViewLoaded);
}

- (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex {
[self.uut setReadyToReceiveCommands:true];
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];
options.bottomTabs.tabsAttachMode =
[[BottomTabsAttachMode alloc] initWithValue:@"onSwitchToTab"];
options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES];
options.bottomTabs.currentTabIndex = [IntNumber withValue:@1];

BottomTabsBaseAttacher *attacher =
[[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options];
RNNBottomTabsController *tabBarController =
[[RNNBottomTabsController alloc] initWithLayoutInfo:nil
creator:nil
options:options
defaultOptions:[RNNNavigationOptions emptyOptions]
presenter:[RNNBasePresenter new]
bottomTabPresenter:nil
dotIndicatorPresenter:nil
eventEmitter:_eventEmmiter
childViewControllers:@[ _vc1, _vc2 ]
bottomTabsAttacher:attacher];
[tabBarController viewWillAppear:YES];
OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);

[self.uut setRoot:@{}
commandId:@""
completion:^(NSString *componentId){
}];
XCTAssertFalse(_vc1.isViewLoaded);
XCTAssertTrue(_vc2.isViewLoaded);
[tabBarController setSelectedIndex:0];
XCTAssertTrue(_vc1.isViewLoaded);
}

- (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab {
[self.uut setReadyToReceiveCommands:true];
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];
Expand Down

0 comments on commit 985a827

Please sign in to comment.