-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disable swipe back action in stack navigation (react-navigation). #1063
Comments
@tungbt-2-3-1994 Did you find the solution for it? |
@narendrashetty |
Example of route definition with gesturesEnabled: false
For me, for some reason it does not work if I wrap gesturesEnabled: false with cardStack. |
@anton6 this is brilliant |
Any way to set this globally for all routes? |
@agersoncgps StackNavigator takes navigationOptions representing the "Default navigation options to use for screens" Example:
|
@anton6 thanks man! You made my day!!! <3 |
So as not to make your stuff messy, create a function and call it wherever you need it. _goHome() { Then call it like so this._goHome() |
gesturesEnabled didn't work for me ("react-navigation": "^2.3.1") but swipe enable did. I have a case with parent TabNavigator and StackNavigator as a child: https://stackoverflow.com/questions/48114810/react-native-disable-swiping-stacknavigator-in-tabnavigator?rq=1
|
If anyone is having the same problem in the newer versions, you can set the default navigation options for all the screens in a stack with
|
The const AppStack = createStackNavigator({
Welcome: {
screen: Welcome,
navigationOptions: () => ({
gestureResponseDistance: {
horizontal: -1,
vertical: -1,
},
}),
},
}); It is still a hack, but at least I was able to disable this behavior. This issue was causing me troubles while performing E2E testing with |
I would like to show a toast when the user swipes to navigate back, to let them know there changes will be lost. Any suggestions on how I could do that? |
not work for IphoneX ? |
Not working in iOS and Android gesturesEnabled: false |
This solution works for me on "react-navigation": "^3.3.2" |
It works for me if i didn't wrap "gestureEnabled: false" in card stack |
What if I wanted do disable and enable it dynamically? |
Worked for me as well ! |
in react navigation 4, |
in ios when using below code, it's loading a white background. I want to disable the swipe option const MainStack = createStackNavigator({ |
Anyone know how to fix above ? |
import React, {Component} from 'react'; import {createStackNavigator} from 'react-navigation-stack'; render() { const AppNavigator = createAppContainer(MainNavigator); |
I see a lot of |
@nikola-kolosek control it with |
Ahh... thank you so much. That worked for me when other solutions hadn't. |
'gesturesEnabled' will be removed in a future version. Use 'gestureEnabled' instead:
|
|
Hello, nothing mentioned in this thread worked for me. https://reactnavigation.org/docs/stack-navigator/#example /* -------------- example1 -------------- */
<Stack.Navigator initialRouteName="Home">
<Stack.Screen
name="Home"
component={Home}
options={{
gestureEnabled: false,
}}
/>
<Stack.Screen
name="Profile"
component={Profile}
options={{
gestureEnabled: false,
}}
/>
<Stack.Screen
name="Settings"
component={Settings}
options={{
gestureEnabled: false,
}}
/>
</Stack.Navigator> First, I had to give /* -------------- example2 -------------- */
<NavigationContainer>
<RootStack.Navigator headerMode="none" initialRouteName="TabNavigator">
<RootStack.Screen
name="SignUpNavigator"
component={SignUpNavigator}
/>
<RootStack.Screen
name="LoginNavigator"
component={LoginNavigator}
/>
<RootStack.Screen
name="TabNavigator"
component={TabNavigator}
/>
<RootStack.Screen
name="SettingsNavigator"
component={SettingsNavigator}
// Given that 'SettingsNavigator' is the one involving screens above (screens in example1 !!)
options={{ gestureEnabled: false }}
/>
</RootStack.Navigator>
</NavigationContainer> Hope this can be a nice help to somebody. |
Following up from @Youn-ha comment - you can disable it across the whole stack navigator by doing the following. <Stack.Navigator
screenOptions={{
headerShown: false,
gestureEnabled: false,
}}>
{/* screens here */}
</Stack.Navigator> Hope this helps someone out there 😁 |
This worked perfectly, TY! |
iOS 14, all ways above not working for me =( |
me to not work
|
not working for ios14 |
is there any way to override this swipe behaviour for android and ios? I would like to navigate them to a particular screen on swipe back. |
Not working for ios14 . |
ANYONE LOOKING FOR AN ANSWER THAT WORKS TRY THIS!! |
Not working for iOS 14 - 14.2 |
Be careful, it's |
Nothing here seems to be working on iOS 14.3. Setting the |
If anyone is still having this issue, it could mean you are having a deep nested navigation ion your code. |
This works to me, thanks. |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
I found the problem. I faced this problem when I try to set this with the PUSH stack, not the NAVIGATE �stack |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
for those who are looking for a way to dynamically disable the this worked for me <Stack.Navigator
screenOptions={{
headerShown: false,
...TransitionPresets.SlideFromRightIOS,
gestureEnabled: true,
}}>
<Stack.Screen name="SwapScreen" component={SwapScreen} />
<Stack.Screen
name="ConfirmationSwap"
component={ConfirmationSwapScreen}
/>
</Stack.Navigator> for example inside of useEffect(
() => navigation.getParent()?.setOptions({ gestureEnabled: CONDITION }),
[navigation, CONDITION],
); |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
The solution is to set gestureEnabled to false in the parent Stack Navigator(not current Stack Navigator) screen and setting gestureEnabled to true for the screens which need the gesture in the current stack or directly in the current stack navigator. Worked for me with React Navigation 5. This is a little bit hacky but working for me: Parent Stack => Current Stack => Screen 1, Screen 2, Screen 3... Here set gestureEnabled to false in Parent Stack Navigator's screen(which is Current Stack), set gestureEnabled to true in |
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
nothing worked for me. But @fedeerbes solution of disabling it dynamically worked.
|
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
This worked for me. React Navigation 5. So, the main/root stack navigator has a nested navigator KYCNavigation. There you put this code: <Stack.Screen Then in the KYCNavigation stack you place this code:
After that for every screen you can specify behavior like this: <Stack.Screen
|
Hey! This issue is closed and isn't watched by the core team. You are welcome to discuss the issue with others in this thread, but if you think this issue is still valid and needs to be tracked, please open a new issue with a repro. |
I have 2 screens A and B in stack navigator. When i click button on screen A, it will navigate to screen B. On screen B, I want to disable the swipe back action. I just want that when i press left button in navigation, i will navigate back to screen A.
Thanks in advance!
The text was updated successfully, but these errors were encountered: