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

Cancel event for all Gestures

Open Bayramito opened this issue 1 year ago • 5 comments

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

Bayramito avatar Jan 29 '24 09:01 Bayramito

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?

github-actions[bot] avatar Jan 29 '24 09:01 github-actions[bot]

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.

github-actions[bot] avatar Jan 29 '24 09:01 github-actions[bot]

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).

j-piasecki avatar Jan 31 '24 16:01 j-piasecki

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).

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.

Bayramito avatar Jan 31 '24 16:01 Bayramito

This needs to be a state unfortunately, since shared value will not update the gesture config.

j-piasecki avatar Jan 31 '24 16:01 j-piasecki