react-native-gesture-handler icon indicating copy to clipboard operation
react-native-gesture-handler copied to clipboard

How to disable left swipe gesture in react-native-gesture-handler/Swipeable?

Open luvnish19 opened this issue 2 years ago • 12 comments

Description

We are creating a component similar like Instagram where we have a Posts screen and Messaging screen. When perform swipe from right to left, screen navigates from Posts screen to Messaging screen. For swiping, we are using @react-navigation/material-top-tabs

In Messaging screen, Flatlist component is used to show conversations list where react-native-gesture-handler/Swipeable is used to show controls which are delete and mute button when user performs "right to left" swipe similar like Instagram which is working 100% fine but when trying to navigating back to post screen using left to right swipe on Flatlist then react-native-gesture-handler/Swipeable gesture executes and their "onSwipeableOpen" callback calls which should not execute so that smoothly translation should be perform from Messaging to Post Screen.

As well as there is no way to disable left to right swipe on FlatList. Is there any solution/ workaround or any suggestion to achieve this task?

Steps to reproduce

Take reference of Instagram where we have Posts screen and Conversations Screen

  1. Create 2 child components: Posts Screen and ** Conversations Screen** under Main component using @react-navigation/material-top-tabs
  2. Swipe to ** Conversations screen**. Flatlist is used to display Conversations and wrapped with react-native-gesture-handler/Swipeable
  3. Right swipe should work and left swipe should be disabled so that we could easily navigate back to the Posts Screen

Snack or a link to a repository

https://stackoverflow.com/questions/75369425/how-to-disable-left-swipe-gesture-in-react-native-gesture-handler-swipeable/75371366#75371366

Gesture Handler version

2.8.0

React Native version

0.70.6

Platforms

Android, iOS

JavaScript runtime

None

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

luvnish19 avatar Feb 07 '23 13:02 luvnish19

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

This is the maximum explaination.

luvnish19 avatar Feb 07 '23 13:02 luvnish19

You might be able to try:

renderLeftActions={() => null}

I have a list where I want to swipe right -> left to display a delete button, but I wanted to disable any other left -> right swiping, and that seemed to do the trick.

matthewwolfe avatar Feb 25 '23 17:02 matthewwolfe

I'm having the same issue too,It prevents the default right-swipe event for iOS to return to the previous page. How do you solve it?

devoutDisciple avatar Jun 13 '23 02:06 devoutDisciple

I'm also having this issue. I have a list of swipeable with a right action and no left action. However, when swiping from the left edge of the screen it blocks the ability to return to the previous page.

mblode avatar Jun 13 '23 13:06 mblode

I'm also having the same issue. I create a minimal reproduction snack

alexandcote avatar Jul 04 '23 13:07 alexandcote

Also having this issue. Has anyone come up with a fix?

paule89123 avatar Dec 03 '23 20:12 paule89123

Hi! @luvnish19, could you please prepare a reproduction? I've tried to use the one provided by @alexandcote, but it seems to work fine (as you can see on the video below)

https://github.com/software-mansion/react-native-gesture-handler/assets/63123542/0905fc29-a202-4bc1-af83-195dc1ee7d2d

m-bert avatar Jan 15 '24 08:01 m-bert

+1

alyosha avatar Jan 30 '24 06:01 alyosha

What I Do

image @alyosha I add dragOffsetFromLeftEdge to Swipeable, it works. It will disable the begin area of panGestureHandler to offset "dragOffsetFromLeftEdge". And then, iOS swipe right navigation will work~

Swipeable Components Source Code

image

PanGestureHandler API

image

codecomeon avatar Feb 04 '24 07:02 codecomeon

@m-bert I just tested it again on my device and I was able to replicate the issue.

I have an iPhone and I see you tried to replicate the issue on Android. Maybe the issue only affect iOS devices?

alexandcote avatar Feb 06 '24 22:02 alexandcote

I took some time and recorded a video

https://github.com/software-mansion/react-native-gesture-handler/assets/4728325/1552d3e9-2de3-4a85-b0eb-96ec28fdb9c6

alexandcote avatar Feb 07 '24 03:02 alexandcote

Thanks for pointing this out @alexandcote! You can disable left swipe by using dragOffsetFromLeftEdge, as @codecomeon already mentioned. For example:

 <Swipeable
        ...
        dragOffsetFromLeftEdge={Number.MAX_VALUE} 
      >

will effectively disable swipe from left.

Let me know if this is something that you were looking for!

m-bert avatar Feb 08 '24 09:02 m-bert