问题
I have a Screen for Main then it's push to Next for selection and passes parameters to next pushed screen and when you select something in that screen I need to pop(2)
and send selected details to the main screen.
But pop
didn't accept parameters. How to accomplish this.
I don't use Redux or MobX.
回答1:
You need to do this
Screen A:
this.props.navigation.navigate('ScreenB', {
onPressScreenAFun: (params) => {
this.screenAFun(params)
},
})
screenAFun = (params) => {
console.log(params)
}
Screen B:
this.props.navigation.navigate('ScreenC', {
onPressScreenBFun: (params) => {
this.screenBFun(params)
},
})
screenBFun = (params) => {
const { onPressScreenAFun } = this.props.navigation.navigate.state.params
onPressScreenAFun(params)
this.props.navigation.goBack()
}
Screen C:
moveBack = (params) => {
const { onPressScreenBFun } = this.props.navigation.navigate.state.params
onPressScreenBFun(params)
this.props.navigation.goBack()
}
this is how you can pass params from Screen C to Screen A with two pop()
来源:https://stackoverflow.com/questions/52578670/react-native-navigation-passing-back-parameters-two-screen-pop