react-native-gesture-handler
react-native-gesture-handler copied to clipboard
Cancel event for all Gestures
Description
Would be very helpful if we had a .cancel()
event for all the gestures to be able to cancel the one of the active events while using others.
Let's say we have 3 gestures running simultaneously, Pinch, Pan, LongPress
and let's say i wan't to cancel the LongPress
event after a swipe
With current implementation you can do this ofc, but it is very tricky.
Instead if we had a cancel
event,
For example:
const longPress = Gesture.LongPress()
.onStart(event => {
console.log("LONG PRESS START");
})
.onTouchCancelled(() => {
console.log("LONG PRESS CANCELLED);
});
const pan = useMemo(
() =>
Gesture.Pan()
.onUpdate(e => {
if (translateX.value > 50) { // if translate is more than 50,
longPress.cancel(); // cancel long press
}
translateX.value = e.translationX;
})
Steps to reproduce
Snack or a link to a repository
Gesture Handler version
2.14.0
React Native version
0.72.4
Platforms
Android, iOS
JavaScript runtime
None
Workflow
None
Architecture
None
Build type
None
Device
None
Device model
No response
Acknowledgements
Yes
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?
Hey! 👋
It looks like you've omitted a few important sections from the issue template.
Please complete Steps to reproduce and Snack or a link to a repository sections.
It's certainly something we could explore in the future, but I cannot promise anything at this moment. You could accomplish something similar using .enabled()
modifier. (Setting it to false
and then to true
again should cancel the gesture).
It's certainly something we could explore in the future, but I cannot promise anything at this moment. You could accomplish something similar using
.enabled()
modifier. (Setting it tofalse
and then totrue
again should cancel the gesture).
unfortunately, this trick doesn't work as i expected. It is not cancelling the gesture, i can keep panning.
I created a sharedValue called isEnabled
default is true.
pass it to .enabled(isEnabled.value)
in onUpdate
if translationX > 50 && isEnabled.value = false
it does not stops my gesture when i reach 50.
This needs to be a state unfortunately, since shared value will not update the gesture config.