Skip to content

Use Device specific gesture configuration for scroll views #87604

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 18 commits into from
Aug 9, 2021

Conversation

jonahwilliams
Copy link
Contributor

@jonahwilliams jonahwilliams commented Aug 4, 2021

Fixes #87322

Wires up the window specific GestureSettings into a dpr transformed DeviceGestureSettings. This can be configured on the base GestureDetector, and then each gesture detector can choose which (if any) configuration it wants to use.

@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. labels Aug 4, 2021
@google-cla google-cla bot added the cla: yes label Aug 4, 2021
@jonahwilliams jonahwilliams marked this pull request as ready for review August 6, 2021 16:55
@jonahwilliams jonahwilliams changed the title [WIP] device gestures Use Device specific gesture configuration for scroll views Aug 6, 2021
@jonahwilliams
Copy link
Contributor Author

I don't really want to hit everything at once, but making this optional for the sake of backwards compat - maybe we can migrate to this over time. @goderbauer for thoughts?

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.

In every place where null is passed over the real device value a comment would be good explaining why we want the framework fallback rather than the device-provided value.

switch (kind) {
case PointerDeviceKind.mouse:
return kPrecisePointerPanSlop;
case PointerDeviceKind.stylus:
case PointerDeviceKind.invertedStylus:
case PointerDeviceKind.unknown:
case PointerDeviceKind.touch:
return kPanSlop;
return deviceTouchSlop != null ? (2 * deviceTouchSlop) : kPanSlop;
Copy link
Member

Choose a reason for hiding this comment

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

Why 2x?

switch (kind) {
case PointerDeviceKind.mouse:
return kPrecisePointerPanSlop;
case PointerDeviceKind.stylus:
case PointerDeviceKind.invertedStylus:
case PointerDeviceKind.unknown:
case PointerDeviceKind.touch:
return kPanSlop;
return deviceTouchSlop != null ? (2 * deviceTouchSlop) : kPanSlop;
}
}

Copy link
Member

Choose a reason for hiding this comment

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

What about the scaleSlop below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite sure what to do with the scale slop right now.

@@ -249,7 +249,7 @@ class ForcePressGestureRecognizer extends OneSequenceGestureRecognizer {
if (pressure > startPressure) {
_state = _ForceState.started;
resolve(GestureDisposition.accepted);
} else if (event.delta.distanceSquared > computeHitSlop(event.kind)) {
} else if (event.delta.distanceSquared > computeHitSlop(event.kind, null)) {
Copy link
Member

Choose a reason for hiding this comment

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

Why null over gestureSettings.touchSlop?

@@ -497,17 +504,17 @@ class VerticalMultiDragGestureRecognizer extends MultiDragGestureRecognizer {

@override
MultiDragPointerState createNewPointerState(PointerDownEvent event) {
return _VerticalPointerState(event.position, event.kind);
return _VerticalPointerState(event.position, event.kind, null);
Copy link
Member

Choose a reason for hiding this comment

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

why null?

@@ -2099,28 +2099,28 @@ class PointerCancelEvent extends PointerEvent with _PointerEventDescription, _Co
}

/// Determine the appropriate hit slop pixels based on the [kind] of pointer.
double computeHitSlop(PointerDeviceKind kind) {
double computeHitSlop(PointerDeviceKind kind, double? deviceTouchSlop) {
Copy link
Member

Choose a reason for hiding this comment

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

should these just take a DeviceGestureSettings obj and the method can pick the appropriate value from it?

@@ -244,6 +246,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
event: event,
entry: GestureBinding.instance!.gestureArena.add(event.pointer, this),
doubleTapMinTime: kDoubleTapMinTime,
touchSlop: null,
Copy link
Member

Choose a reason for hiding this comment

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

Why null?

@@ -879,6 +885,7 @@ class SerialTapGestureRecognizer extends GestureRecognizer {
invokeCallback<void>('onSerialTapDown', () => onSerialTapDown!(details));
}
final _TapTracker tracker = _TapTracker(
touchSlop: null,
Copy link
Member

Choose a reason for hiding this comment

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

Why null?

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

final double? touchSlop;

/// The touch slop value for pan gestures, in logical pixels, or `null` if it
/// was not set.
Copy link
Member

Choose a reason for hiding this comment

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

Looks like there is no way to actually set it independently? Maybe document that it's either null or 2* touchSlop if touchSlop is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. In the future we could support setting it separately if need be.

@@ -104,6 +105,7 @@ class MediaQueryData {
this.disableAnimations = false,
this.boldText = false,
this.navigationMode = NavigationMode.traditional,
this.gestureSettings = const DeviceGestureSettings(touchSlop: 16.0)
Copy link
Member

Choose a reason for hiding this comment

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

Can this use kTouchSlop instead of hard-coding 16?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

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 framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Flutter should use the platform configured touch slop value for Android
3 participants