繁体   English   中英

反应导航 v6 和 v5,禁用向后滑动操作

[英]react navigation v6 and v5, Disable swipe back action

我正在使用反应导航 5:

我创建了 MainStackScreen 和 AuthStackScreen,

const AuthStack = createStackNavigator();

function AuthStackScreen() {
  return (
    <AuthStack.Navigator headerMode="none">
      <AuthStack.Screen name="Main" component={Main} />
      <AuthStack.Screen name="Login" component={Login} />
      <AuthStack.Screen name="Registration" component={Registration} />
      <AuthStack.Screen name="Home" component={DrawerNavigator} />
      <AuthStack.Screen name="Notifications" component={Notifications} />
      <AuthStack.Screen name="SmsValidation" component={SmsValidation} />
      <AuthStack.Screen name="MoreRegistrationInfo" component={MoreRegistrationInfo} />
    </AuthStack.Navigator>
  );
}

主堆栈屏幕:

const MainScreen = createStackNavigator();

function MainStackScreen({navigation}) {
  return (
    <MainScreen.Navigator>
      <MainScreen.Screen name="Main" component={Main} />
      <MainScreen.Screen name="SmsValidation" component={SmsValidation} />
      <MainScreen.Screen name="MoreRegistrationInfo" component={MoreRegistrationInfo} />
    </MainScreen.Navigator>
  );
}

我想防止 IOS 在登录我的屏幕之间向后滑动操作

您可以在如下屏幕中将 gestureEnabled 设置为 false:

<AuthStack.Screen
   name="Login"
   component={Login}
   options={{gestureEnabled: false}}
/>

或者整个导航器像:

<AuthStack.Navigator screenOptions={{gestureEnabled: false}}>
  ...
</AuthStack.Navigator>
/* -------------------------------------------------------------------------- */
/*                                 AUTH STACK                                 */
/* -------------------------------------------------------------------------- */

const AuthStack = createStackNavigator();

function AuthStackScreen() {
  return (
    <AuthStack.Navigator headerMode="none">
      <AuthStack.Screen name="Main" component={Main} />
      <AuthStack.Screen name="Login" component={Login} options={{gestureEnabled: false}} />
      <AuthStack.Screen
        name="Registration"
        component={Registration}
        options={{gestureEnabled: false}}
      />
      <AuthStack.Screen name="Home" component={DrawerNavigator} options={{gestureEnabled: false}} />
      <AuthStack.Screen
        name="Notifications"
        component={Notifications}
        options={{gestureEnabled: false}}
      />
      <AuthStack.Screen
        name="SmsValidation"
        component={SmsValidation}
        options={{gestureEnabled: false}}
      />
      <AuthStack.Screen
        name="MoreRegistrationInfo"
        component={MoreRegistrationInfo}
        options={{gestureEnabled: false}}
      />
    </AuthStack.Navigator>
  );
}

您可以设置一个beforeRemove侦听器以防止返回。 反应导航文档

暂无
暂无

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

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