Skip to content

Commit

Permalink
Fix updating currentTabIndex (#6314)
Browse files Browse the repository at this point in the history
`BottomTabsController.currentTabIndex` didn't get updated on pressing tabs which resulted in wrong option resolving and multiple styling bugs.

Closes #6310
Closes #6313
  • Loading branch information
yogevbd committed Jun 16, 2020
1 parent c612d6c commit bd710bc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions e2e/BottomTabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,12 @@ describe('BottomTabs', () => {
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.BOTTOM_TABS)).toBeVisible();
});

it('hide Tab Bar on second tab after pressing the tab', async () => {
await elementById(TestIDs.SECOND_TAB_BAR_BTN).tap();
await elementById(TestIDs.HIDE_TABS_PUSH_BTN).tap();
await expect(elementById(TestIDs.BOTTOM_TABS)).toBeNotVisible();
await elementById(TestIDs.POP_BTN).tap();
await expect(elementById(TestIDs.BOTTOM_TABS)).toBeVisible();
});
});
6 changes: 6 additions & 0 deletions lib/ios/RNNBottomTabsController.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ - (UIViewController *)selectedViewController {
return children.count ? children[_currentTabIndex] : nil;
}

- (void)setSelectedViewController:(__kindof UIViewController *)selectedViewController {
NSArray* children = self.pendingChildViewControllers ?: self.childViewControllers;
_currentTabIndex = [children indexOfObject:selectedViewController];
[super setSelectedViewController:selectedViewController];
}

- (void)loadChildren:(NSArray *)children {
if (self.viewWillAppearOnce) {
[super loadChildren:children];
Expand Down
4 changes: 3 additions & 1 deletion playground/src/screens/SecondBottomTabScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const {
PUSHED_BOTTOM_TABS,
SIDE_MENU_TAB,
FLAT_LIST_BTN,
HIDE_TABS_PUSH_BTN
HIDE_TABS_PUSH_BTN,
SECOND_TAB_BAR_BTN
} = require('../testIDs')

class SecondBottomTabScreen extends React.Component {
Expand All @@ -24,6 +25,7 @@ class SecondBottomTabScreen extends React.Component {
bottomTab: {
icon: require('../../img/star.png'),
text: 'Tab 2',
testID: SECOND_TAB_BAR_BTN,
dotIndicator: {
visible: true,
color: 'green'
Expand Down

0 comments on commit bd710bc

Please sign in to comment.