【问题标题】:Prevent user from swipe back or using physical back button to go back to splash screen防止用户向后滑动或使用物理后退按钮返回初始屏幕
【发布时间】:2020-06-27 10:01:03
【问题描述】:

我在阻止用户返回初始屏幕时遇到问题。 以前当我使用 React Navigation 4 时,这是我使用的

const resetAction = StackActions.reset({
  index: 0,
  actions: [NavigationActions.navigate({ routeName: "HomeScreen" })]
});
navigation.dispatch(resetAction);

但在 React Navigation 5 中,我尝试了以下代码但没有成功:

const resetAction = CommonActions.reset({
  index: 0,
  actions: [CommonActions.navigate({ name: screenName })]
});
navigation.dispatch(resetAction);

或者这个:

navigation.reset({
  index: 0,
  routes: [{ name: "HomeScreen" }]
});

我还尝试在 Stack.Screen options 道具或 Stack.Navigator screenOptions 道具中将 gestureEnabled 设置为 false,但我仍然可以向右滑动以返回初始屏幕。

有人对此有任何解决方法吗? 谢谢。

【问题讨论】:

标签: react-native react-navigation react-navigation-v5


【解决方案1】:

网站上有认证流程指南,可能有用:here

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-18
    • 1970-01-01
    • 1970-01-01
    • 2022-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    相关资源
    最近更新 更多