【问题标题】:How to refresh the first screen after poping the second screen from stack react-native-navigation V2?从堆栈 react-native-navigation V2 弹出第二个屏幕后如何刷新第一个屏幕?
【发布时间】:2019-03-20 06:33:48
【问题描述】:

我在我的 Android 应用中使用 Wix 的 react-native-navigation V2。当我按下一个屏幕并在弹出或按下后退按钮后,前一个或第一个组件不呈现并且不执行任何生命周期方法。即使我们不能在 pop 中使用 pass 道具。我想刷新上一页我该怎么做。我只是弹出如下屏幕

goBack = () => {

        Navigation.pop(this.props.componentId);
}

我在 GitHub 上发现了 this 问题,据说可以通过使用 Redux/MobX 同步数据或收听 visibility events 来解决此问题,但我没有在 V2 中找到可见性事件。而且不知道怎么用redux。

【问题讨论】:

标签: android react-native redux wix-react-native-navigation


【解决方案1】:
    You can follow the below steps to do so:

    1). Subscribe for react-navigation's 'didFocus' event in the component's constructor(or componentDidMount or componentWillMount).
    // Subscribe for Event
    constructor(props) {
            super(props)
            this.didFocusSubscription = this.props.navigation.addListener(
                'didFocus',
                payload => {
                    // Refresh your screen here
                }
              );
        }

2). Do not forget to unsubscribe the event when the component will unmount.
    // UnSubscribe for Event
    componentWillUnmount = () => {
            this.didFocusSubscription.remove()
        }

【讨论】:

  • 感谢您的回答,但我正在使用 Wix 的 react-native-navigation
猜你喜欢
  • 2019-09-11
  • 2019-07-27
  • 1970-01-01
  • 1970-01-01
  • 2020-06-29
  • 1970-01-01
  • 1970-01-01
  • 2020-07-27
  • 2021-01-25
相关资源
最近更新 更多