本文介绍了React Native Navigation 传回参数两屏弹出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个主屏幕,然后它被推到下一个进行选择,并将参数传递给下一个被推的屏幕,当你在那个屏幕中选择某些东西时,我需要 pop(2)
并将选定的详细信息发送到主屏幕.
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.
但是 pop
不接受参数.如何实现这一点.
But pop
didn't accept parameters. How to accomplish this.
我不使用 Redux 或 MobX.
I don't use Redux or MobX.
推荐答案
你需要这样做
屏幕 A:
this.props.navigation.navigate('ScreenB', {
onPressScreenAFun: (params) => {
this.screenAFun(params)
},
})
screenAFun = (params) => {
console.log(params)
}
屏幕 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()
}
屏幕 C:
moveBack = (params) => {
const { onPressScreenBFun } = this.props.navigation.navigate.state.params
onPressScreenBFun(params)
this.props.navigation.goBack()
}
这是如何使用两个 pop() 将参数从屏幕 C 传递到屏幕 A
this is how you can pass params from Screen C to Screen A with two pop()
这篇关于React Native Navigation 传回参数两屏弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!