mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Deprecate VelocityTracker default constructor and added VelocityTracker.withKind constructor (#66043)
We've gotten feedback that the VelocityTracker change was disruptive, though it did not break any of the flutter framework or customer tests. In order to make the change non-breaking, PointerDeviceKind parameter can be made optional. Nevertheless, this parameter should be provided so that the existing touch handlers can use more accurate gestures on mouse/stylus inputs, so we can encourage this by deprecating the default constructor and pointing users towards the VelocityTracker.withKind constructor that takes a non-optional parameter
This commit is contained in:
parent
c61c8f303b
commit
b1d17c914d
@ -20,7 +20,7 @@ void main() {
|
|||||||
assert(false, "Don't run benchmarks in checked mode! Use 'flutter run --release'.");
|
assert(false, "Don't run benchmarks in checked mode! Use 'flutter run --release'.");
|
||||||
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
final BenchmarkResultPrinter printer = BenchmarkResultPrinter();
|
||||||
final List<TrackerBenchmark> benchmarks = <TrackerBenchmark>[
|
final List<TrackerBenchmark> benchmarks = <TrackerBenchmark>[
|
||||||
TrackerBenchmark(name: 'velocity_tracker_iteration', tracker: VelocityTracker(PointerDeviceKind.touch)),
|
TrackerBenchmark(name: 'velocity_tracker_iteration', tracker: VelocityTracker.withKind(PointerDeviceKind.touch)),
|
||||||
TrackerBenchmark(name: 'velocity_tracker_iteration_ios_fling', tracker: IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch)),
|
TrackerBenchmark(name: 'velocity_tracker_iteration_ios_fling', tracker: IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch)),
|
||||||
];
|
];
|
||||||
final Stopwatch watch = Stopwatch();
|
final Stopwatch watch = Stopwatch();
|
||||||
|
@ -376,7 +376,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
|
|||||||
void handlePrimaryPointer(PointerEvent event) {
|
void handlePrimaryPointer(PointerEvent event) {
|
||||||
if (!event.synthesized) {
|
if (!event.synthesized) {
|
||||||
if (event is PointerDownEvent) {
|
if (event is PointerDownEvent) {
|
||||||
_velocityTracker = VelocityTracker(event.kind);
|
_velocityTracker = VelocityTracker.withKind(event.kind);
|
||||||
_velocityTracker!.addPosition(event.timeStamp, event.localPosition);
|
_velocityTracker!.addPosition(event.timeStamp, event.localPosition);
|
||||||
}
|
}
|
||||||
if (event is PointerMoveEvent) {
|
if (event is PointerMoveEvent) {
|
||||||
|
@ -69,7 +69,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
|
|||||||
}) : assert(dragStartBehavior != null),
|
}) : assert(dragStartBehavior != null),
|
||||||
super(debugOwner: debugOwner, kind: kind);
|
super(debugOwner: debugOwner, kind: kind);
|
||||||
|
|
||||||
static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker(event.kind);
|
static VelocityTracker _defaultBuilder(PointerEvent event) => VelocityTracker.withKind(event.kind);
|
||||||
/// Configure the behavior of offsets sent to [onStart].
|
/// Configure the behavior of offsets sent to [onStart].
|
||||||
///
|
///
|
||||||
/// If set to [DragStartBehavior.start], the [onStart] callback will be called
|
/// If set to [DragStartBehavior.start], the [onStart] callback will be called
|
||||||
|
@ -30,7 +30,7 @@ abstract class MultiDragPointerState {
|
|||||||
/// The [initialPosition] argument must not be null.
|
/// The [initialPosition] argument must not be null.
|
||||||
MultiDragPointerState(this.initialPosition, this.kind)
|
MultiDragPointerState(this.initialPosition, this.kind)
|
||||||
: assert(initialPosition != null),
|
: assert(initialPosition != null),
|
||||||
_velocityTracker = VelocityTracker(kind);
|
_velocityTracker = VelocityTracker.withKind(kind);
|
||||||
|
|
||||||
/// The global coordinates of the pointer when the pointer contacted the screen.
|
/// The global coordinates of the pointer when the pointer contacted the screen.
|
||||||
final Offset initialPosition;
|
final Offset initialPosition;
|
||||||
|
@ -286,7 +286,7 @@ class ScaleGestureRecognizer extends OneSequenceGestureRecognizer {
|
|||||||
@override
|
@override
|
||||||
void addAllowedPointer(PointerEvent event) {
|
void addAllowedPointer(PointerEvent event) {
|
||||||
startTrackingPointer(event.pointer, event.transform);
|
startTrackingPointer(event.pointer, event.transform);
|
||||||
_velocityTrackers[event.pointer] = VelocityTracker(event.kind);
|
_velocityTrackers[event.pointer] = VelocityTracker.withKind(event.kind);
|
||||||
if (_state == _ScaleState.ready) {
|
if (_state == _ScaleState.ready) {
|
||||||
_state = _ScaleState.possible;
|
_state = _ScaleState.possible;
|
||||||
_initialSpan = 0.0;
|
_initialSpan = 0.0;
|
||||||
|
@ -149,7 +149,14 @@ class _PointAtTime {
|
|||||||
/// have been received.
|
/// have been received.
|
||||||
class VelocityTracker {
|
class VelocityTracker {
|
||||||
/// Create a new velocity tracker for a pointer [kind].
|
/// Create a new velocity tracker for a pointer [kind].
|
||||||
VelocityTracker(this.kind);
|
@Deprecated(
|
||||||
|
'Use VelocityTracker.withKind and provide the PointerDeviceKind associated with the gesture being tracked. '
|
||||||
|
'This feature was deprecated after v1.22.0-12.1.pre.'
|
||||||
|
)
|
||||||
|
VelocityTracker([this.kind = PointerDeviceKind.touch]);
|
||||||
|
|
||||||
|
/// Create a new velocity tracker for a pointer [kind].
|
||||||
|
VelocityTracker.withKind(this.kind);
|
||||||
|
|
||||||
static const int _assumePointerMoveStoppedMilliseconds = 40;
|
static const int _assumePointerMoveStoppedMilliseconds = 40;
|
||||||
static const int _historySize = 20;
|
static const int _historySize = 20;
|
||||||
@ -281,7 +288,7 @@ class VelocityTracker {
|
|||||||
/// the iOS method that reports the fling velocity when the touch is released.
|
/// the iOS method that reports the fling velocity when the touch is released.
|
||||||
class IOSScrollViewFlingVelocityTracker extends VelocityTracker {
|
class IOSScrollViewFlingVelocityTracker extends VelocityTracker {
|
||||||
/// Create a new IOSScrollViewFlingVelocityTracker.
|
/// Create a new IOSScrollViewFlingVelocityTracker.
|
||||||
IOSScrollViewFlingVelocityTracker(PointerDeviceKind kind) : super(kind);
|
IOSScrollViewFlingVelocityTracker(PointerDeviceKind kind) : super.withKind(kind);
|
||||||
|
|
||||||
/// The velocity estimation uses at most 4 `_PointAtTime` samples. The extra
|
/// The velocity estimation uses at most 4 `_PointAtTime` samples. The extra
|
||||||
/// samples are there to make the `VelocityEstimate.offset` sufficiently large
|
/// samples are there to make the `VelocityEstimate.offset` sufficiently large
|
||||||
|
@ -75,7 +75,7 @@ class ScrollBehavior {
|
|||||||
case TargetPlatform.fuchsia:
|
case TargetPlatform.fuchsia:
|
||||||
case TargetPlatform.linux:
|
case TargetPlatform.linux:
|
||||||
case TargetPlatform.windows:
|
case TargetPlatform.windows:
|
||||||
return (PointerEvent event) => VelocityTracker(event.kind);
|
return (PointerEvent event) => VelocityTracker.withKind(event.kind);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ void main() {
|
|||||||
];
|
];
|
||||||
|
|
||||||
test('Velocity tracker gives expected results', () {
|
test('Velocity tracker gives expected results', () {
|
||||||
final VelocityTracker tracker = VelocityTracker(PointerDeviceKind.touch);
|
final VelocityTracker tracker = VelocityTracker.withKind(PointerDeviceKind.touch);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (final PointerEvent event in velocityEventData) {
|
for (final PointerEvent event in velocityEventData) {
|
||||||
if (event is PointerDownEvent || event is PointerMoveEvent)
|
if (event is PointerDownEvent || event is PointerMoveEvent)
|
||||||
@ -64,7 +64,7 @@ void main() {
|
|||||||
|
|
||||||
test('Interrupted velocity estimation', () {
|
test('Interrupted velocity estimation', () {
|
||||||
// Regression test for https://github.com/flutter/flutter/pull/7510
|
// Regression test for https://github.com/flutter/flutter/pull/7510
|
||||||
final VelocityTracker tracker = VelocityTracker(PointerDeviceKind.touch);
|
final VelocityTracker tracker = VelocityTracker.withKind(PointerDeviceKind.touch);
|
||||||
for (final PointerEvent event in interruptedVelocityEventData) {
|
for (final PointerEvent event in interruptedVelocityEventData) {
|
||||||
if (event is PointerDownEvent || event is PointerMoveEvent)
|
if (event is PointerDownEvent || event is PointerMoveEvent)
|
||||||
tracker.addPosition(event.timeStamp, event.position);
|
tracker.addPosition(event.timeStamp, event.position);
|
||||||
@ -75,7 +75,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('No data velocity estimation', () {
|
test('No data velocity estimation', () {
|
||||||
final VelocityTracker tracker = VelocityTracker(PointerDeviceKind.touch);
|
final VelocityTracker tracker = VelocityTracker.withKind(PointerDeviceKind.touch);
|
||||||
expect(tracker.getVelocity(), Velocity.zero);
|
expect(tracker.getVelocity(), Velocity.zero);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ class RangeMaintainingTestScrollBehavior extends ScrollBehavior {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
GestureVelocityTrackerBuilder velocityTrackerBuilder(BuildContext context) {
|
GestureVelocityTrackerBuilder velocityTrackerBuilder(BuildContext context) {
|
||||||
return (PointerEvent event) => VelocityTracker(event.kind);
|
return (PointerEvent event) => VelocityTracker.withKind(event.kind);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -27,7 +27,7 @@ class TestScrollBehavior extends ScrollBehavior {
|
|||||||
@override
|
@override
|
||||||
GestureVelocityTrackerBuilder velocityTrackerBuilder(BuildContext context) {
|
GestureVelocityTrackerBuilder velocityTrackerBuilder(BuildContext context) {
|
||||||
lastCreatedBuilder = flag
|
lastCreatedBuilder = flag
|
||||||
? (PointerEvent ev) => VelocityTracker(ev.kind)
|
? (PointerEvent ev) => VelocityTracker.withKind(ev.kind)
|
||||||
: (PointerEvent ev) => IOSScrollViewFlingVelocityTracker(ev.kind);
|
: (PointerEvent ev) => IOSScrollViewFlingVelocityTracker(ev.kind);
|
||||||
return lastCreatedBuilder;
|
return lastCreatedBuilder;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user