Skip to content

Commit 985a827

Browse files
authored
fix: first tab being rendered when onSwitchToTab and a custom currentTabIndex is set (#7922)
1 parent 8c64969 commit 985a827

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/ios/RNNBottomTabsController.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
2929
_bottomTabPresenter = bottomTabPresenter;
3030
_dotIndicatorPresenter = dotIndicatorPresenter;
3131

32+
if ([options.bottomTabs.currentTabIndex hasValue]) {
33+
_currentTabIndex = [options.bottomTabs.currentTabIndex get];
34+
_previousTabIndex = _currentTabIndex;
35+
}
36+
3237
self = [super initWithLayoutInfo:layoutInfo
3338
creator:creator
3439
options:options

playground/ios/NavigationTests/RNNCommandsHandlerTest.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,40 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab {
521521
XCTAssertTrue(_vc2.isViewLoaded);
522522
}
523523

524+
- (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex {
525+
[self.uut setReadyToReceiveCommands:true];
526+
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];
527+
options.bottomTabs.tabsAttachMode =
528+
[[BottomTabsAttachMode alloc] initWithValue:@"onSwitchToTab"];
529+
options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES];
530+
options.bottomTabs.currentTabIndex = [IntNumber withValue:@1];
531+
532+
BottomTabsBaseAttacher *attacher =
533+
[[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options];
534+
RNNBottomTabsController *tabBarController =
535+
[[RNNBottomTabsController alloc] initWithLayoutInfo:nil
536+
creator:nil
537+
options:options
538+
defaultOptions:[RNNNavigationOptions emptyOptions]
539+
presenter:[RNNBasePresenter new]
540+
bottomTabPresenter:nil
541+
dotIndicatorPresenter:nil
542+
eventEmitter:_eventEmmiter
543+
childViewControllers:@[ _vc1, _vc2 ]
544+
bottomTabsAttacher:attacher];
545+
[tabBarController viewWillAppear:YES];
546+
OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController);
547+
548+
[self.uut setRoot:@{}
549+
commandId:@""
550+
completion:^(NSString *componentId){
551+
}];
552+
XCTAssertFalse(_vc1.isViewLoaded);
553+
XCTAssertTrue(_vc2.isViewLoaded);
554+
[tabBarController setSelectedIndex:0];
555+
XCTAssertTrue(_vc1.isViewLoaded);
556+
}
557+
524558
- (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab {
525559
[self.uut setReadyToReceiveCommands:true];
526560
RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions];

0 commit comments

Comments
 (0)