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): load initial tab when onSwitchToTab mode is set. #7924

Merged
merged 1 commit into from
Oct 16, 2024
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
23 changes: 13 additions & 10 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ - (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
defaultOptions:defaultOptions
presenter:presenter
eventEmitter:eventEmitter
childViewControllers:childViewControllers];

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

self = [super initWithLayoutInfo:layoutInfo
creator:creator
options:options
defaultOptions:defaultOptions
presenter:presenter
eventEmitter:eventEmitter
childViewControllers:childViewControllers];
if (@available(iOS 13.0, *)) {
self.tabBar.standardAppearance = [UITabBarAppearance new];
}
Expand Down
25 changes: 20 additions & 5 deletions playground/ios/NavigationTests/RNNCommandsHandlerTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,10 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab {
commandId:@""
completion:^(NSString *componentId){
}];

XCTAssertTrue(_vc1.isViewLoaded);
XCTAssertFalse(_vc2.isViewLoaded);

[tabBarController setSelectedIndex:1];
XCTAssertTrue(_vc2.isViewLoaded);
}
Expand All @@ -531,6 +533,7 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex {

BottomTabsBaseAttacher *attacher =
[[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options];

RNNBottomTabsController *tabBarController =
[[RNNBottomTabsController alloc] initWithLayoutInfo:nil
creator:nil
Expand All @@ -540,19 +543,31 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex {
bottomTabPresenter:nil
dotIndicatorPresenter:nil
eventEmitter:_eventEmmiter
childViewControllers:@[ _vc1, _vc2 ]
childViewControllers:@[ _vc1, _vc2, _vc3 ]
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);

// TODO: for some reason the controller always loads the default controller (index 0), regardless the initial value.
XCTAssertTrue(_vc1.isViewLoaded);
XCTAssertTrue(_vc2.isViewLoaded);
XCTAssertFalse(_vc3.isViewLoaded);

[tabBarController setSelectedIndex:0];
XCTAssertTrue(_vc1.isViewLoaded);
XCTAssertTrue(_vc2.isViewLoaded);
XCTAssertFalse(_vc3.isViewLoaded);

[tabBarController setSelectedIndex:2];
XCTAssertTrue(_vc1.isViewLoaded);
XCTAssertTrue(_vc2.isViewLoaded);
XCTAssertTrue(_vc3.isViewLoaded);
}

- (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab {
Expand Down
Loading