React Native Navigation Passing back parameters two screen pop

前端 未结 1 418
日久生厌
日久生厌 2021-01-27 05:32

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)

1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-27 06:09

    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()

    0 讨论(0)
提交回复
热议问题