如何在从堆栈反应基本响应v2中弹出第二个屏幕后刷新第一个屏幕



我在我的应用程序中使用了wix的反应nvigation v2 for android。当我按下一个屏幕,然后按下一个屏幕或按下后面按钮,以前或第一个组件不渲染而不执行任何生命周期方法。即使我们也无法使用POP中的通行道具。我想刷新上一页我该怎么做。我只是在屏幕上弹出

goBack = () => {
        Navigation.pop(this.props.componentId);
}

我在github上发现了这个问题,它说可以通过使用redux/mobx同步数据或收听visibility events来解决此问题,但我没有在v2中找到可见性事件。并且不知道如何使用redux。

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

最新更新