React-native-tab-view: Navigation

Created on 18 Mar 2018  路  1Comment  路  Source: satya164/react-native-tab-view

I have component Home contains TabView.
2 child components : Showing & Coming are 2 Tab of component Home
Inside component Showing has a button
How to press this button, index of TabView in Home will change to 1 (move to Coming tab)

Thank you !

Most helpful comment

First - please make sure you fill out the _issue template_ before you post an issue here. The maintainer is not likely going to entertain your question without it.

Secondly, if I am understanding your question correctly - you mean to ask how do you want to navigate from one screen to the other? If not, the solution below might not be relevant to you.


The navigation object whose index property matches with index attribute in the _navigation state_ is rendered.

So for example, if your navigation state looks something like this:

state = {
  index: 0,
  routes: [
    { index: 0, text: 'Showing' },
    { index: 1, text: 'Coming' },
  ]
}

Then in both the views which will have the button to navigate/switch tabs you can just update the index prop in the state object:

handleIndexChange = index => this.setState({ index });

and your button in one of the views maybe something like this:

<TouchableOpacity onPress={() => this.handleIndexChange(2)}> // this will switch to tab2 if you're on tab1
  <Text>Press to switch to tab 2</Text>
</TouchableOpacity>

Please refer to the example code here!

>All comments

First - please make sure you fill out the _issue template_ before you post an issue here. The maintainer is not likely going to entertain your question without it.

Secondly, if I am understanding your question correctly - you mean to ask how do you want to navigate from one screen to the other? If not, the solution below might not be relevant to you.


The navigation object whose index property matches with index attribute in the _navigation state_ is rendered.

So for example, if your navigation state looks something like this:

state = {
  index: 0,
  routes: [
    { index: 0, text: 'Showing' },
    { index: 1, text: 'Coming' },
  ]
}

Then in both the views which will have the button to navigate/switch tabs you can just update the index prop in the state object:

handleIndexChange = index => this.setState({ index });

and your button in one of the views maybe something like this:

<TouchableOpacity onPress={() => this.handleIndexChange(2)}> // this will switch to tab2 if you're on tab1
  <Text>Press to switch to tab 2</Text>
</TouchableOpacity>

Please refer to the example code here!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ashusdn picture ashusdn  路  4Comments

satya164 picture satya164  路  3Comments

ahmedrowaihi picture ahmedrowaihi  路  3Comments

hyochan35 picture hyochan35  路  3Comments

compojoom picture compojoom  路  4Comments