React-native-navigation: v2 switchToTab do not exist?

Created on 26 Jun 2018  路  5Comments  路  Source: wix/react-native-navigation

There is no documentation for switchToTab.
Is it not exist in v2?
How can I switch Tabs in v2?

    Navigation.switchToTab({
      tabIndex: 1
    });

I even searched source for v2 and there is no "switchToTab" method.

documentation v2

Most helpful comment

switchToTab is not part of the v2 api. The active tab index is a property of the BottomTabs layout, to change it programatically, call mergeOptions as you would change any other option.

Navigation.mergeOptions(this.props.componentId, {
  bottomTabs: {
    currentTabIndex: 1
  }
}

We're planning on writing a more detailed migration guide in the upcoming days.

All 5 comments

switchToTab is not part of the v2 api. The active tab index is a property of the BottomTabs layout, to change it programatically, call mergeOptions as you would change any other option.

Navigation.mergeOptions(this.props.componentId, {
  bottomTabs: {
    currentTabIndex: 1
  }
}

We're planning on writing a more detailed migration guide in the upcoming days.

@guyca I'm trying to create a custom bottomTab bar and using the mergeOptions currentTabIndex to navigate between views. I disabled the tabbar with

bottomTabs: {
  visible: false
}

on first render the bottomTabs are hidden but position absolute + bottom: 0 is rendering the custom bar above the invisible bottomTabs. After navigating once the bottomTabs are gone.

I could fix this by adding drawBehind: false but after adding this, the largeTitle keeps animating after switching tab from the normal title to the large title til the tabbar gets rendered shortly and removed afterwards?

https://wix.github.io/react-native-navigation/v2/#/docs/layout-types?id=selecting-tabs-programmatically

This should be documented somewhere, correct me if I'm wrong but I could not find any documentation on this.

@guyca , is there any way to trigger an event whenever we mergeOptions? in this case, whenever a tab is changed? I would like to run a function after the tab is changed. Do you know how can I do that? Thanks!

Was this page helpful?
0 / 5 - 0 ratings