Repository navigation
[flutter] reject mouse drags by default in scrollables #81569
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
Changes from all commits
5efce5c
5085988
7b33429
8e8954f
774016b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { | |
| PointerDeviceKind? kind, | ||
| this.dragStartBehavior = DragStartBehavior.start, | ||
| this.velocityTrackerBuilder = _defaultBuilder, | ||
| this.supportedDevices = _kAllPointerDeviceKinds | ||
| }) : assert(dragStartBehavior != null), | ||
| super(debugOwner: debugOwner, kind: kind); | ||
|
|
||
|
|
@@ -200,6 +201,11 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { | |
| /// match the native behavior on that platform. | ||
| GestureVelocityTrackerBuilder velocityTrackerBuilder; | ||
|
|
||
| /// The device types that this gesture recognizer will accept drags from. | ||
| /// | ||
| /// If not specified, defaults to all pointer kinds. | ||
| Set<PointerDeviceKind> supportedDevices; | ||
|
|
||
| _DragState _state = _DragState.ready; | ||
| late OffsetPair _initialPosition; | ||
| late OffsetPair _pendingDragOffset; | ||
|
|
@@ -230,6 +236,9 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { | |
|
|
||
| @override | ||
| bool isPointerAllowed(PointerEvent event) { | ||
| if (!supportedDevices.contains(event.kind)) { | ||
| return false; | ||
| } | ||
| if (_initialButtons == null) { | ||
| switch (event.buttons) { | ||
| case kPrimaryButton: | ||
|
|
@@ -508,7 +517,8 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer { | |
| VerticalDragGestureRecognizer({ | ||
| Object? debugOwner, | ||
| PointerDeviceKind? kind, | ||
| }) : super(debugOwner: debugOwner, kind: kind); | ||
| Set<PointerDeviceKind> supportedDevices = _kAllPointerDeviceKinds, | ||
| }) : super(debugOwner: debugOwner, kind: kind, supportedDevices: supportedDevices); | ||
|
|
||
| @override | ||
| bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) { | ||
|
|
@@ -532,6 +542,10 @@ class VerticalDragGestureRecognizer extends DragGestureRecognizer { | |
| String get debugDescription => 'vertical drag'; | ||
| } | ||
|
|
||
| const Set<PointerDeviceKind> _kAllPointerDeviceKinds = <PointerDeviceKind>{ | ||
| ...PointerDeviceKind.values, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know we could do this!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TIL!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤩 |
||
| }; | ||
|
|
||
| /// Recognizes movement in the horizontal direction. | ||
| /// | ||
| /// Used for horizontal scrolling. | ||
|
|
@@ -549,7 +563,8 @@ class HorizontalDragGestureRecognizer extends DragGestureRecognizer { | |
| HorizontalDragGestureRecognizer({ | ||
| Object? debugOwner, | ||
| PointerDeviceKind? kind, | ||
| }) : super(debugOwner: debugOwner, kind: kind); | ||
| Set<PointerDeviceKind> supportedDevices = _kAllPointerDeviceKinds, | ||
| }) : super(debugOwner: debugOwner, kind: kind, supportedDevices: supportedDevices); | ||
|
|
||
| @override | ||
| bool isFlingGesture(VelocityEstimate estimate, PointerDeviceKind kind) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's weird that that there's a
kindargument here too. You should document the interplay between these two (that either can be used to disallow a pointer type). Maybe even use an example, like what happens if they specify:Might also make sense to add an assert that they're not specifying a combo that doesn't make any sense.
You could even try to change GestureRecognizer.kind to be "kinds" and a Set (ref: #78853), but then we're in breaking change territory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinds is definitely odd. If I had the chance I would probably re-do how we do touch slop entirely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having
kindsandsupportedDeviceson here is odd. The docs forkind:and
supportedDevicesalso read pretty similar in what they do. A little more documentation contrasting the two is a good idea.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am wondering whether we should deprecate
kindaltogether now and redirect people tosupportedDevicesto simplify the API.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I was thinking, we should deprecate
kind. I can write a dart fix and a migration guide to help. :) I already wrote a really similar one for some other recent changes toScrollBehavior.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Touched base with @jonahwilliams. I'll open a follow up change to see what this will look like. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @renancaraujo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow up is in #81858
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @tvolkert for the FYI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just coming back around to close the loop on this, flutter/website#5771 has a migration guide for those seeking to restore the prior behavior. :)