React Native Navigation Passing back parameters two screen pop

﹥>﹥吖頭↗ 提交于 2019-12-20 06:06:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!