Unverified Commit e05d0dd2 authored by Callum Moffat's avatar Callum Moffat Committed by GitHub

ScaleGestureRecognizer pointerCount=2 for trackpad gestures (#140745)

Now trackpad gestures will count as pointerCount=2 instead of 1. It makes it easier for people who want to have different behaviour for single-finger drag vs two-finger pan/zoom. Also fixed up `scale_test.dart` to verify `pointerCount` in more places.

Related: https://github.com/flutter/flutter/issues/13102
Fixes https://github.com/flutter/flutter/issues/140730
parent b0c5fc91
......@@ -230,7 +230,8 @@ class ScaleUpdateDetails {
/// The number of pointers being tracked by the gesture recognizer.
///
/// Typically this is the number of fingers being used to pan the widget using the gesture
/// recognizer.
/// recognizer. Due to platform limitations, trackpad gestures count as two fingers
/// even if more than two fingers are used.
final int pointerCount;
/// Recorded timestamp of the source pointer event that triggered the scale
......@@ -408,7 +409,10 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
/// Typically this is the number of fingers being used to pan the widget using the gesture
/// recognizer.
int get pointerCount {
return _pointerPanZooms.length + _pointerQueue.length;
// PointerPanZoom protocol doesn't contain the exact number of pointers
// used on the trackpad, as it isn't exposed by all platforms. However, it
// will always be at least two.
return (2 * _pointerPanZooms.length) + _pointerQueue.length;
}
late Offset _initialFocalPoint;
......@@ -583,7 +587,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
for (final _PointerPanZoomData p in _pointerPanZooms.values) {
focalPoint += p.focalPoint;
}
_currentFocalPoint = pointerCount > 0 ? focalPoint / pointerCount.toDouble() : Offset.zero;
_currentFocalPoint = focalPoint / math.max(1, _pointerLocations.length + _pointerPanZooms.length).toDouble();
if (previousFocalPoint == null) {
_localFocalPoint = PointerEvent.transformPosition(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment