Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ios): ensure correct initial tab is rendered when onSwitchToTab is set #7922

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

[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
Loading