【问题标题】:App stuck when relauch after press back button on root screen应用程序在根屏幕上按返回按钮后重新启动时卡住
【发布时间】:2019-02-20 16:18:57
【问题描述】:

我正在使用 React Native 0.57.8 和 Wix React Native Navigation v2.7.1,当我按下手机的虚拟后退按钮时,在我的根屏幕上,应用程序似乎关闭并返回到我的应用程序启动器。但是,当我重新启动该应用程序时,它会永远卡在黑屏上,直到我终止该应用程序并重新打开它。

我不明白为什么会这样,真的很奇怪。

我在根屏幕上尝试了BackHandler,但没有成功:

this.backHandler = BackHandler.addEventListener("hardwareBackPress", () => {
  BackHandler.exitApp();
  //return true;
});

谢谢。

【问题讨论】:

    标签: android react-native react-native-navigation


    【解决方案1】:

    我在 App.js 上使用 react-native-navigation 的 Navigation.events().registerAppLaunchedListener 修复了该行为,以便调用 setRoot()...

    Navigation.events().registerAppLaunchedListener(() => {
          Navigation.setRoot({
          root: {
            sideMenu: {
              left: {
                component: {
                ....
                }
              },
            }
          }
        });
    });
    

    【讨论】:

      【解决方案2】:

      我的解决方法是:

      Navigation.events().registerAppLaunchedListener(() => {
        if (Platform.OS === 'android') {
          SplashScreen.hide();
        }
        Navigation.setRoot(myRoot);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-06
        • 2011-09-14
        • 2017-09-24
        • 2017-08-10
        • 1970-01-01
        相关资源
        最近更新 更多