Skip to content

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented May 15, 2019

Description

Currently a modal route is dismissed by callback onTap. This has 2 problems:

  • It should be dismissed by tap down instead of tap up.
  • After Redo#2: Add buttons to gestures #31935, onTap* will only respond to primary buttons, which means secondary (and other) buttons will no longer able to dismiss modals.

To fix this, we need a tap gesture recognizer that responds to any buttons. However, adding onAnyTap* as a public API to TapGR might not be a good idead for 2 reasons:

  1. It's the only occasion we've found onAnyTap* needed for now. Might not worth the cost of adding a full set of public API, especially considering...
  2. onAnyTap* is easy to misuse (because it competes in all events)

Instead ModalBarrier will use a private recognizer _AnyTapGestureRecognizer that claims victor and calls onAnyTapDown immediately after it receives any PointerDownEvent.

Changes

  • Methods tap, press, and related ones in WidgetController support customizing buttons.
  • Add private classes _AnyTapGestureRecognizer and _ModalBarrierGestureDetector.
  • ModalBarrier uses _ModalBarrierGestureDetector.onAnyTapDown to dismiss.

Related Issues

  • None

Tests

I added the following tests:

  • ModalBarrier pops the Navigator when dismissed by non-primary buttons

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.

@Piinks Piinks added a: desktop Running on desktop framework flutter/packages/flutter repository. See also f: labels. labels May 16, 2019
@dkwingsmt dkwingsmt changed the title WIP: Dismiss modal with any button press Dismiss modal with any button press May 21, 2019
@dkwingsmt
Copy link
Contributor Author

Reopen PR since the blocker has been merged

@dkwingsmt dkwingsmt reopened this Jul 8, 2019
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

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

LGTM

@dnfield
Copy link
Contributor

dnfield commented Jul 17, 2019

Github lies, this is green - @dkwingsmt are you ready to merge this?

@dkwingsmt
Copy link
Contributor Author

@dnfield Let me sync with master just in case...

@dkwingsmt dkwingsmt merged commit 1aa4628 into flutter:master Jul 18, 2019
@dkwingsmt dkwingsmt deleted the modal-dismissed-by-any-button branch July 18, 2019 22:33
dkwingsmt added a commit that referenced this pull request Jul 24, 2019
dkwingsmt added a commit that referenced this pull request Jul 24, 2019
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
This PR makes ModalBarrier dismiss modal with any button press instead of primary button up, by making it use a private recognizer _AnyTapGestureRecognizer that claims victor and calls onAnyTapDown immediately after it receives any PointerDownEvent.
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

a: desktop Running on desktop framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants