Skip to content

Instantly share code, notes, and snippets.

@shubhnik
Last active November 10, 2017 12:12
Show Gist options
  • Save shubhnik/c3826edc44d80a7bdd5ed7fec3720f0b to your computer and use it in GitHub Desktop.
Save shubhnik/c3826edc44d80a7bdd5ed7fec3720f0b to your computer and use it in GitHub Desktop.
// a simple demo screen1 to demonstrate dispatching actions to update navigation state and navigate to screen2.
// Don not forget to check the complete code here ---> https://github.com/shubhnik/redux-react-navigation
class Screen1 extends Component {
navigate = () => {
const navigateToScreen2 = NavigationActions.navigate({
routeName:'screen2',
params:{name:'Shubhnik'}
})
// navigateToscreen2 will look like this:
/*
{
"type": "Navigation/NAVIGATE",
"routeName": "screen2",
"params":{
"name":"Shubhnik"
}
}
*/
// The navigateToScreen2 action is dispatched and new navigation state will be calculated in basicNavigationReducer here ---> https://gist.github.com/shubhnik/b55602633aaeb5919f6f3c15552d1802
this.props.navigation.dispatch(navigateToScreen2)
}
render(){
return(
<View style={{flex: 1}}>
<TouchableOpacity
onPress={this.navigate}
>
<Text>Navigate to screen2</Text>
</TouchableOpacity>
</View>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment