Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react navigation 5 Disable swipe back action

Tags:

I'm working with react navigation 5 :

I created MainStackScreen and 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>   ); } 

MainStackScreen :

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

I want to prevent IOS swipe action back between Login my screens

like image 202
Khaled Boussoffara Avatar asked Sep 22 '20 15:09

Khaled Boussoffara


People also ask

How do I go back in react navigation?

The header bar will automatically show a back button, but you can programmatically go back by calling navigation. goBack() . On Android, the hardware back button just works as expected. You can go back to an existing screen in the stack with navigation.


2 Answers

You can set gestureEnabled to false in a screen like:

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

Or the whole navigator like:

<AuthStack.Navigator screenOptions={{gestureEnabled: false}}>   ... </AuthStack.Navigator> 
like image 182
Arif Arifi Avatar answered Sep 19 '22 03:09

Arif Arifi


/* -------------------------------------------------------------------------- */ /*                                 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>   ); } 
like image 43
Khaled Boussoffara Avatar answered Sep 19 '22 03:09

Khaled Boussoffara