How does your Swipeable Component work? #2501
-
I want to build my own Swipeable component. I want the functionality to display another action when the user overshoots the Swipe. Like apple has it in their Mail app. When you do a little swipe it shows those 3 buttons but when you drag further, at some point the most right button grows to takes up the whole space and the other buttons disappear. So now I have tried for such a long time and can't get to figure out how to handle the Swipable component inside a Scrollview.
It calculates the Slope of the Gesture. if the slope is larger then some threshold it does nothing and when the slope is smaller than the threshold it disables scrolling by I think I got it pretty far, but now I am stuck at the point where when I swipe really fast the ScrollView wants to start scrolling. Even if the Slope is smaller than the threshold, meaning that it should not scroll. https://github.com/software-mansion/react-native-gesture-handler/assets/87496469/fe805d84-8b8a-4993-a29d-20a06f8f4112 My question to you: How do you handle the Swipeable inside a scrollview so that they don't run at the same time and only one is active when for example the slope of the swipe is below or above some threshold . I tried understanding your code inside the repo but there are so many parts to it. Would love to here from you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Each of those shifts is caused by the fact that We do this by setting the activation offset on the gesture itself. This way, the gesture will not activate unless the finger is moved by the required distance on the horizontal axis and you can scroll freely. When you move the finger enough horizontally, the gesture activation cancels the scroll view it's nested in and since it happens synchronously on the native side, there's no flicker visible. |
Beta Was this translation helpful? Give feedback.
Each of those shifts is caused by the fact that
setNativeProps
is asynchronous, so by the time the props are actually updated and the scroll is stopped, it already moved a bit.We do this by setting the activation offset on the gesture itself. This way, the gesture will not activate unless the finger is moved by the required distance on the horizontal axis and you can scroll freely. When you move the finger enough horizontally, the gesture activation cancels the scroll view it's nested in and since it happens synchronously on the native side, there's no flicker visible.