Unverified Commit 82cb7493 authored by Kohei Seino's avatar Kohei Seino Committed by GitHub

ScaleGestureRecognizer: make pointerCount public (#127310)

make `pointCount` in `ScaleGestureRecognizer` public to handle pointer event depending on the number of pointers.

https://github.com/flutter/flutter/issues/127309
parent 4a3ab682
...@@ -393,6 +393,14 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -393,6 +393,14 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
/// {@endtemplate} /// {@endtemplate}
Offset trackpadScrollToScaleFactor; Offset trackpadScrollToScaleFactor;
/// 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.
int get pointerCount {
return _pointerPanZooms.length + _pointerQueue.length;
}
late Offset _initialFocalPoint; late Offset _initialFocalPoint;
Offset? _currentFocalPoint; Offset? _currentFocalPoint;
late double _initialSpan; late double _initialSpan;
...@@ -443,10 +451,6 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -443,10 +451,6 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
return scale; return scale;
} }
int get _pointerCount {
return _pointerPanZooms.length + _pointerQueue.length;
}
double _computeRotationFactor() { double _computeRotationFactor() {
double factor = 0.0; double factor = 0.0;
if (_initialLine != null && _currentLine != null) { if (_initialLine != null && _currentLine != null) {
...@@ -566,7 +570,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -566,7 +570,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
for (final _PointerPanZoomData p in _pointerPanZooms.values) { for (final _PointerPanZoomData p in _pointerPanZooms.values) {
focalPoint += p.focalPoint; focalPoint += p.focalPoint;
} }
_currentFocalPoint = _pointerCount > 0 ? focalPoint / _pointerCount.toDouble() : Offset.zero; _currentFocalPoint = pointerCount > 0 ? focalPoint / pointerCount.toDouble() : Offset.zero;
if (previousFocalPoint == null) { if (previousFocalPoint == null) {
_localFocalPoint = PointerEvent.transformPosition( _localFocalPoint = PointerEvent.transformPosition(
...@@ -662,9 +666,9 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -662,9 +666,9 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if (pixelsPerSecond.distanceSquared > kMaxFlingVelocity * kMaxFlingVelocity) { if (pixelsPerSecond.distanceSquared > kMaxFlingVelocity * kMaxFlingVelocity) {
velocity = Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * kMaxFlingVelocity); velocity = Velocity(pixelsPerSecond: (pixelsPerSecond / pixelsPerSecond.distance) * kMaxFlingVelocity);
} }
invokeCallback<void>('onEnd', () => onEnd!(ScaleEndDetails(velocity: velocity, scaleVelocity: _scaleVelocityTracker?.getVelocity().pixelsPerSecond.dx ?? -1, pointerCount: _pointerCount))); invokeCallback<void>('onEnd', () => onEnd!(ScaleEndDetails(velocity: velocity, scaleVelocity: _scaleVelocityTracker?.getVelocity().pixelsPerSecond.dx ?? -1, pointerCount: pointerCount)));
} else { } else {
invokeCallback<void>('onEnd', () => onEnd!(ScaleEndDetails(scaleVelocity: _scaleVelocityTracker?.getVelocity().pixelsPerSecond.dx ?? -1, pointerCount: _pointerCount))); invokeCallback<void>('onEnd', () => onEnd!(ScaleEndDetails(scaleVelocity: _scaleVelocityTracker?.getVelocity().pixelsPerSecond.dx ?? -1, pointerCount: pointerCount)));
} }
} }
_state = _ScaleState.accepted; _state = _ScaleState.accepted;
...@@ -706,7 +710,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -706,7 +710,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
focalPoint: _currentFocalPoint!, focalPoint: _currentFocalPoint!,
localFocalPoint: _localFocalPoint, localFocalPoint: _localFocalPoint,
rotation: _computeRotationFactor(), rotation: _computeRotationFactor(),
pointerCount: _pointerCount, pointerCount: pointerCount,
focalPointDelta: _delta, focalPointDelta: _delta,
)); ));
}); });
...@@ -721,7 +725,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -721,7 +725,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
onStart!(ScaleStartDetails( onStart!(ScaleStartDetails(
focalPoint: _currentFocalPoint!, focalPoint: _currentFocalPoint!,
localFocalPoint: _localFocalPoint, localFocalPoint: _localFocalPoint,
pointerCount: _pointerCount, pointerCount: pointerCount,
)); ));
}); });
} }
......
...@@ -79,6 +79,7 @@ void main() { ...@@ -79,6 +79,7 @@ void main() {
updatedDelta = null; updatedDelta = null;
expect(didEndScale, isFalse); expect(didEndScale, isFalse);
expect(didTap, isFalse); expect(didTap, isFalse);
expect(scale.pointerCount, 1);
// Two-finger scaling // Two-finger scaling
final TestPointer pointer2 = TestPointer(2); final TestPointer pointer2 = TestPointer(2);
...@@ -87,6 +88,7 @@ void main() { ...@@ -87,6 +88,7 @@ void main() {
tap.addPointer(down2); tap.addPointer(down2);
tester.closeArena(2); tester.closeArena(2);
tester.route(down2); tester.route(down2);
expect(scale.pointerCount, 2);
expect(didEndScale, isTrue); expect(didEndScale, isTrue);
didEndScale = false; didEndScale = false;
......
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