简体   繁体   English

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

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

I am using Wix's react-native-navigation V2 in my app for Android. 我在Android应用中使用Wix的react-native-navigation V2。 When I am pushing one screen and after a pop or pressing back button the previous or first component not rendering and not executing any lifecycle method. 当我按下一个屏幕时,在弹出或按下返回按钮之后,上一个或第一个组件不会渲染,也不会执行任何生命周期方法。 Even we cannot use pass props in pop. 即使我们不能在流行音乐中使用传递道具。 I want to refresh that previous page how can I do that. 我想刷新上一页,我该怎么做。 I am just poping the screen as below 我只是弹出屏幕如下

goBack = () => {

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

I found this issue on GitHub and it is saying that this problem could be solved by either syncing the data using Redux/MobX or listen to visibility events but I didn't found visibility events in V2. 我在GitHub上发现了问题,这是说可以通过使用Redux / MobX同步数据或侦听visibility events来解决此问题,但我在V2中没有发现可见性事件。 And don't know how to do with redux. 而且不知道如何使用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.

相关问题 从v1迁移到react-native-navigation v2后的不变违例 - Invariant Violation after migrating to react-native-navigation v2 from v1 从 Android 启动 react-native-navigation 屏幕 - Launching react-native-navigation screen from Android 如何在react-native-navigation中从堆栈完成SplashScreen - How to finish SplashScreen from stack in react-native-navigation 将新屏幕推送到堆栈时,Android 上的从左到右的 animation 与 react-native-navigation - Left-to-right animation on Android with react-native-navigation when pushing new screen to stack React-native-navigation 在登录屏幕上隐藏导航栏? - React-native-navigation hide navigation bar on login screen? 如何为topBar wix的react-native-navigation V2提供渐变颜色 - How to give gradient color to topBar wix's react-native-navigation V2 wix / React-Native-Navigation黑屏开头 - wix/React-Native-Navigation blank screen in the beginning 在本地反应导航中从单屏应用转到基于选项卡的应用 - Going from single screen app to tab based app in react-native-navigation 在 Android 上使用 react-native-spalsh 屏幕和 react-native-navigation - use react-native-spalsh screen with react-native-navigation on Android 无法构建 react-native-navigation v1 - Failed to build react-native-navigation v1
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM