如何从堆栈react-native-navigation V2弹出第二个屏幕后刷新第一个屏幕

问题描述 投票:0回答:1

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

goBack = () => {

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

我在GitHub https://github.com/wix/react-native-navigation/issues/2594上发现了这个问题,他说这个问题可以通过使用Redux / MobX同步数据或者听visibility events来解决,但我没有在V2中找到可见性事件。并且不知道如何处理redux。

android react-native redux pop wix-react-native-navigation
1个回答
0
投票
    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()
        }
© www.soinside.com 2019 - 2024. All rights reserved.