Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support trackpad gestures in framework #89944

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

Merged
merged 11 commits into from
Apr 13, 2022

Conversation

moffatman
Copy link
Contributor

@moffatman moffatman commented Sep 12, 2021

This commit adds support for new pointer events to convey trackpad gesture information. These new events will trigger existing widgets that expect scale or pan gestures.

  1. Three new types of events (PointerPanZoomStartEvent, PointerPanZoomUpdateEvent, PointerPanZoomEndEvent) to convey the states of a trackpad gesture
  2. GestureRecognizers can handle pointer flows (the relevant ones DragGestureRecognizer and ScaleGestureRecognizer have been updated)
  3. GestureDetector has been updated so that onScale, onPan, onVerticalDrag, and onHorizontalDrag will trigger from trackpad gestures

Design Document

Engine PR: flutter/engine#28571

Addresses #23604
Closes #63084

Widgets that use GestureRecognizers directly instead of GestureDetector will need to handle the onPointerPanZoomStart callback of Listener with their GestureRecognizers to receive trackpad gesture events.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. tool Affects the "flutter" command-line tool. See also t: labels. labels Sep 12, 2021
@google-cla google-cla bot added the cla: yes label Sep 12, 2021
@flutter-dashboard flutter-dashboard bot added the f: gestures flutter/packages/flutter/gestures repository. label Oct 21, 2021
@moffatman moffatman force-pushed the trackpad_gestures branch 2 times, most recently from 1dd37a9 to 7489668 Compare November 9, 2021 05:33
@moffatman moffatman force-pushed the trackpad_gestures branch 2 times, most recently from be93d39 to a9268a7 Compare January 14, 2022 22:47
@moffatman moffatman marked this pull request as ready for review January 21, 2022 15:18
@christopherfujino christopherfujino removed the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 3, 2022
@christopherfujino
Copy link
Contributor

I'm removing the tool label, as the only tool change is a single key in an XML config template.

@moffatman moffatman force-pushed the trackpad_gestures branch 2 times, most recently from 27bf470 to c845637 Compare February 10, 2022 15:14
@moffatman moffatman force-pushed the trackpad_gestures branch 4 times, most recently from f70655e to 20a63c0 Compare February 18, 2022 02:50
Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long. Only minor changes requested.

Thanks for preparing this huge PR!

@@ -6108,6 +6111,15 @@ class Listener extends SingleChildRenderObjectWidget {
/// no longer directed towards this receiver.
final PointerCancelEventListener? onPointerCancel;

/// Called when a pan/zoom begins such as from a trackpad gesture
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel like using "/" in official names. I'm thinking if we can use pan-zoom. But let's see what others think before making the change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I mentioned this elsewhere, but this also includes rotation, right?

Otherwise to me, pan/zoom seems like pan or zoom, and pan-zoom seems like pan and zoom. In my testing on my Macbook, it seems like a 2 finder pan gesture is treated separately from a pinch-to-zoom, so maybe pan/zoom is most accurate? See my discussion about combining gestures like this in my main review comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, add periods at the end of these 3 comments.

@moffatman moffatman force-pushed the trackpad_gestures branch 2 times, most recently from a4302fe to 248c3ae Compare April 12, 2022 19:52
@alexeylopukh
Copy link

The list scroll should stop on a tap. Now this is especially inconvenient, if you push the list a little, it will scroll for several seconds and at this time you can’t click anything in the list + you can’t stop it.

@jmagman
Copy link
Member

jmagman commented May 3, 2022

@alexeylopukh can you file a new issue describing what you're seeing and what should happen instead?

@theniceboy
Copy link
Contributor

This PR introduces a breaking change @dkwingsmt

Listener(
  onPointerSignal: (sig) {
    if (sig is PointerScrollEvent) { /* this is no longer triggered on trackpad scroll*/ }
  },
)

github-merge-queue bot pushed a commit that referenced this pull request Feb 25, 2025
…163898)

[ScrollBehavior.dragDevices](https://api.flutter.dev/flutter/widgets/ScrollBehavior/dragDevices.html)
docs say

> By default only PointerDeviceKind.touch, PointerDeviceKind.stylus, and
PointerDeviceKind.invertedStylus are configured to create drag gestures.

However, `PointerDeviceKind.trackpad` is also included by default
#89944


https://github.com/flutter/flutter/blob/401ab831ee56bb31b8beceb0a08bc3293f1a9788/packages/flutter/lib/src/widgets/scroll_configuration.dart#L115-L119


https://github.com/flutter/flutter/blob/401ab831ee56bb31b8beceb0a08bc3293f1a9788/packages/flutter/lib/src/widgets/scroll_configuration.dart#L33

Update the comment to include `trackpad`:
> By default only PointerDeviceKind.touch, PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus, **and PointerDeviceKind.trackpad** are
configured to create drag gestures.



## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [x] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [x] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [x] I signed the [CLA].
- [x] I listed at least one issue that this PR fixes in the description
above.
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [x] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems f: focus Focus traversal, gaining or losing focus f: gestures flutter/packages/flutter/gestures repository. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[InteractiveViewer] Support trackpad gestures pinch zoom and two finger scroll
8 participants