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 {
/// {@endtemplate}
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;
Offset? _currentFocalPoint;
late double _initialSpan;
......@@ -443,10 +451,6 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
return scale;
}
int get _pointerCount {
return _pointerPanZooms.length + _pointerQueue.length;
}
double _computeRotationFactor() {
double factor = 0.0;
if (_initialLine != null && _currentLine != null) {
......@@ -566,7 +570,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
for (final _PointerPanZoomData p in _pointerPanZooms.values) {
focalPoint += p.focalPoint;
}
_currentFocalPoint = _pointerCount > 0 ? focalPoint / _pointerCount.toDouble() : Offset.zero;
_currentFocalPoint = pointerCount > 0 ? focalPoint / pointerCount.toDouble() : Offset.zero;
if (previousFocalPoint == null) {
_localFocalPoint = PointerEvent.transformPosition(
......@@ -662,9 +666,9 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
if (pixelsPerSecond.distanceSquared > kMaxFlingVelocity * 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 {
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;
......@@ -706,7 +710,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
focalPoint: _currentFocalPoint!,
localFocalPoint: _localFocalPoint,
rotation: _computeRotationFactor(),
pointerCount: _pointerCount,
pointerCount: pointerCount,
focalPointDelta: _delta,
));
});
......@@ -721,7 +725,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
onStart!(ScaleStartDetails(
focalPoint: _currentFocalPoint!,
localFocalPoint: _localFocalPoint,
pointerCount: _pointerCount,
pointerCount: pointerCount,
));
});
}
......
......@@ -79,6 +79,7 @@ void main() {
updatedDelta = null;
expect(didEndScale, isFalse);
expect(didTap, isFalse);
expect(scale.pointerCount, 1);
// Two-finger scaling
final TestPointer pointer2 = TestPointer(2);
......@@ -87,6 +88,7 @@ void main() {
tap.addPointer(down2);
tester.closeArena(2);
tester.route(down2);
expect(scale.pointerCount, 2);
expect(didEndScale, isTrue);
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