Skip to content

Refactor: Base tap gesture recognizer - #41329

Merged
dkwingsmt merged 17 commits into
flutter:masterfrom
dkwingsmt:any-tap-competence
Oct 2, 2019
Merged

Refactor: Base tap gesture recognizer#41329
dkwingsmt merged 17 commits into
flutter:masterfrom
dkwingsmt:any-tap-competence

Conversation

@dkwingsmt

@dkwingsmt dkwingsmt commented Sep 26, 2019

Copy link
Copy Markdown
Contributor

Description

Currently TapGestureRecognizer only defines taps of primary button and taps of secondary button, and leaves no customization for other configurations. For example, ModalBarrier needs a tap recognizer that recognizes the tap down of any button, therefore it has to copy the code and remove unnecessary parts. Not only is it redundant, but it has also caused bugs, such as in #41178 (comment).

This PR extracts the logic of TapGestureRecognizer into an abstract class BaseTapGestureRecognizer, so that it is much easier to customize. BaseTapGestureRecognizer still requires that the button is consistent throughout the gesture, but it's not opinionated on which buttons to accept, nor does it know what to on each event. In this way, TapGestureRecognizer and _AnyTapGestureRecognizer can be easily defined, and the logic of tap is also clearer.

Related Issues

Tests

I added the following tests:

  • ModalBarrier may pop the Navigator when competing with other gestures

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Sep 26, 2019
@dkwingsmt dkwingsmt added the f: gestures flutter/packages/flutter/gestures repository. label Sep 26, 2019

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Th looks fine with a couple of nits.

Just to re-confirm: This does not address the issue that different operating systems handle Modal dismissal differently, right? E.g. on iOS and Android 10 a tapUp is required to dismiss, on Android prior to 10 a tapDown is enough?

Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
///
/// A tap is defined as a sequence of events that starts with a down, followed
/// by optional moves, then ends with an up. All move events must contain the
/// same `buttons` with the down event, and must not be too far from the initial

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// same `buttons` with the down event, and must not be too far from the initial
/// same `buttons` as the down event, and must not be too far from the initial

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buttons for the up event don't matter? Do all buttons have to come up at the same time?

@dkwingsmt dkwingsmt Sep 27, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Up events always have buttons: 0.
  2. If the pointer's buttons changes to a different non-zero value, it's considered a Move event. (for example, if buttons changes from 2 | 1 to 1, then there will be a Move event with buttons: 1)

Therefore, since multiple buttons will almost always be pressed or released one at a time, BaseTapGestureRecognizer will not accept multi-button taps (which was an intentional design when we added button constraint to gestures)

Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
@dkwingsmt

Copy link
Copy Markdown
Contributor Author

This does not address the issue that different operating systems handle Modal dismissal differently, right?

No (but it does make it a little easier to do).
I'm aware of the issue, and I'm just about to ask how we decide to handle it :) We can do it in a separate PR.

@dkwingsmt

dkwingsmt commented Sep 27, 2019

Copy link
Copy Markdown
Contributor Author

@goderbauer All comments have been taken care of. PTAL

@goderbauer goderbauer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread packages/flutter/lib/src/gestures/tap.dart Outdated
@chunhtai

Copy link
Copy Markdown
Contributor

is this something MultiTapGestureRecognizer can achieve?

@dkwingsmt

Copy link
Copy Markdown
Contributor Author

@chunhtai Which goal are you suggesting to achieve using MultiTapGR?
If it's "accepting any button", well MultiTapGR is also regulated by buttons (e.g. DoubleTapGR.onDoubleTap only accepts primary buttons), so it does not come with button customizability (we need to add it when the time comes).
If it's "fixing the Android barrier model behavior", then I don't quite get you suggestion.

Can you further illustrate?

@chunhtai

chunhtai commented Oct 1, 2019

Copy link
Copy Markdown
Contributor

@chunhtai Which goal are you suggesting to achieve using MultiTapGR?
If it's "accepting any button", well MultiTapGR is also regulated by buttons (e.g. DoubleTapGR.onDoubleTap only accepts primary buttons), so it does not come with button customizability (we need to add it when the time comes).
If it's "fixing the Android barrier model behavior", then I don't quite get you suggestion.

Can you further illustrate?

now i think of it, i think multitap might not be a good idea. nvm

@dkwingsmt
dkwingsmt merged commit 0b0942a into flutter:master Oct 2, 2019
@dkwingsmt
dkwingsmt deleted the any-tap-competence branch October 2, 2019 22:29
Inconnu08 pushed a commit to Inconnu08/flutter that referenced this pull request Nov 26, 2019
* Extracts the logic of TapGestureRecognizer into an abstract class BaseTapGestureRecognizer
* Fixes ModalBarrier unable to dismiss when competing
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants