繁体   English   中英

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

[英]How to refresh the first screen after poping the second screen from stack react-native-navigation V2?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM