Skip to content

Instantly share code, notes, and snippets.

@jjgonecrypto
Last active October 6, 2016 16:08
Show Gist options
  • Save jjgonecrypto/d4b97d126dc11781bf72c2f0b03847e8 to your computer and use it in GitHub Desktop.
Save jjgonecrypto/d4b97d126dc11781bf72c2f0b03847e8 to your computer and use it in GitHub Desktop.
Navigator in react-native
import Start from './Start'
import NextPage from './NextPage'
const Views = { Start, NextPage }
<Navigator
initialRoute={{ view: 'Start' }}
renderScene={(route, navigator) => {
const SceneComponent = Views[route.view];
return <SceneComponent {...route.props} navigator={navigator} />;
}}
/>
export default class Start extends Component {
onPress() {
this.props.navigator.push({ view: 'NextPage', props: { ... } }); // add props if required
// If in NextPage you want to go "back", you'd do
// this.props.navigator.pop();
}
render() {
<TouchableHighlight onPress={this.onPress.bind(this)}>Test</TouchableHighlight>
}
}
Start.propTypes = {
navigator: PropTypes.object.isRequired
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment