diff --git a/lib/ios/RNNBottomTabsController.m b/lib/ios/RNNBottomTabsController.m index d870018c78..90e545fbc5 100644 --- a/lib/ios/RNNBottomTabsController.m +++ b/lib/ios/RNNBottomTabsController.m @@ -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]; } diff --git a/playground/ios/NavigationTests/RNNCommandsHandlerTest.m b/playground/ios/NavigationTests/RNNCommandsHandlerTest.m index 89d9b4bfc7..9ca676635e 100644 --- a/playground/ios/NavigationTests/RNNCommandsHandlerTest.m +++ b/playground/ios/NavigationTests/RNNCommandsHandlerTest.m @@ -515,8 +515,10 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab { commandId:@"" completion:^(NSString *componentId){ }]; + XCTAssertTrue(_vc1.isViewLoaded); XCTAssertFalse(_vc2.isViewLoaded); + [tabBarController setSelectedIndex:1]; XCTAssertTrue(_vc2.isViewLoaded); } @@ -531,6 +533,7 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex { BottomTabsBaseAttacher *attacher = [[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options]; + RNNBottomTabsController *tabBarController = [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil @@ -540,8 +543,9 @@ - (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); @@ -549,10 +553,21 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTabWithCustomIndex { 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 {