ptomasroos / react-native-tab-navigator

A tab bar that switches between scenes, written in JS for cross-platform support
MIT License
2.4k stars 416 forks source link

use a button on the page to jump to another tab page #139

Closed JackGzj closed 7 years ago

JackGzj commented 7 years ago

Three is three tab items in my app, I want to jump to the second one on pressing the button in the first page, but if I use the navigator to jump to the page that contains the tab navigator, the tab page will be unmounted, and every time I press will lead to the whole page remount.I want to make the effect that when I press the button on the page, I will jump to the second page just like pressing the tab bar icon, how can I do that?

blumanski commented 7 years ago

Ok, that is how I do it.

I have a function like this in "app.js" (the file where you set up tab navigator).

changeTab = (key, value) => { this.setState({[key]: value}) }

You can then add the function to the screen/view (how ever you call it) like below

`

`

In the Whatever component you can link like below

<..... onPress={() => this.props.changeTab('selectedTab', 'TabYouWantToSelect')}

Hope that helps

ptomasroos commented 7 years ago

Glad you fixed it @JackGzj