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

时间:2019-03-20 06:33:49

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

我正在Android的应用程序中使用Wix的react-native-navigation V2。当我按下一个屏幕时,在弹出或按下返回按钮之后,上一个或第一个组件不会渲染,也不会执行任何生命周期方法。即使我们不能在流行音乐中使用传递道具。我想刷新上一页,我该怎么做。我只是弹出如下屏幕

goBack = () => {

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

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

1 个答案:

答案 0 :(得分: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()
        }