Skip to content

Gestures: tap and double tap on the same View #7281

@MCurran16

Description

@MCurran16

Environment

  • CLI: latest
  • Cross-platform modules: 5.4.0
  • Android Runtime: 5.4.0
  • iOS Runtime: 5.4.0

Describe the bug
When you have a tap and double tap gesture recognizer on a view and you attempt to double tap, the tap handler fires. The tap gesture event should not fire if you're attempting a double tap. Take a look at the "Additional context" for the commit that allowed this.

To Reproduce

export class TestLayout extends StackLayout {
    onLoaded() {
        super.onLoaded();

        this.on(GestureTypes.tap, () => console.log('Tapped'));
        this.on(GestureTypes.doubleTap, () => console.log('Double tapped'));
    }
}

If you attempt to double tap on the TestLayout, the console will show:

Tapped
Double tapped

Expected behavior
If you try to double tap on a view with a tap gesture recognizer and a double tap gesture recognizer, the double tap event should fire and the tap should not.

Additional context

I have been working through this issue with @MartoYankov .

Here is the commit that allowed simultaneous gesture events

Here are the docs to the delegate method that could be implemented for iOS

  • I have already implemented this ^ for iOS (see below). The issue now is getting the same functionality for Android.

Potential solution (iOS)

gestures.ios.ts

class UIGestureRecognizerDelegateImpl extends NSObject implements UIGestureRecognizerDelegate {
    public static ObjCProtocols = [UIGestureRecognizerDelegate];

    public gestureRecognizerShouldRecognizeSimultaneouslyWithGestureRecognizer(gestureRecognizer: UIGestureRecognizer, otherGestureRecognizer: UIGestureRecognizer): boolean {
        // If both gesture recognizers are of type UITapGestureRecognizer, do not allow
        // simultaneous recognition.
        if (gestureRecognizer instanceof UITapGestureRecognizer && otherGestureRecognizer instanceof UITapGestureRecognizer) {
            return false;
        }
        return true;
    }

    public gestureRecognizerShouldRequireFailureOfGestureRecognizer(gestureRecognizer: UIGestureRecognizer, otherGestureRecognizer: UIGestureRecognizer): boolean {
        // If both gesture recognizers are of type UITapGestureRecognizer & one of them is a doubleTap,
        // we must require a failure.
        if (gestureRecognizer instanceof UITapGestureRecognizer
            && otherGestureRecognizer instanceof UITapGestureRecognizer
            && otherGestureRecognizer.numberOfTapsRequired === 2) {
            return true;
        }
        return false;
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions