Skip to content
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

Cancel event for all Gestures #2733

Open
Bayramito opened this issue Jan 29, 2024 · 5 comments
Open

Cancel event for all Gestures #2733

Bayramito opened this issue Jan 29, 2024 · 5 comments
Labels
Feature request Missing info Missing repro Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS

Comments

@Bayramito
Copy link

Bayramito commented Jan 29, 2024

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

@github-actions github-actions bot added Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS Missing repro labels Jan 29, 2024
Copy link

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?

Copy link

github-actions bot commented Jan 29, 2024

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.

@j-piasecki
Copy link
Member

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

@Bayramito
Copy link
Author

Bayramito commented Jan 31, 2024

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.

@j-piasecki
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Missing info Missing repro Platform: Android This issue is specific to Android Platform: iOS This issue is specific to iOS
Projects
None yet
Development

No branches or pull requests

3 participants