Unverified Commit 548843b9 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Revert "[Velocity Tracker] Fix: Issue 97761: Flutter Scrolling does not match...

Revert "[Velocity Tracker] Fix: Issue 97761: Flutter Scrolling does not match iOS; inadvertent scrolling when user lifts up finger" (#136905)

Reverts flutter/flutter#132291

We have found this introduced flakiness in many of our tests.

Fixes https://github.com/flutter/flutter/issues/135728
parent fd160466
...@@ -149,17 +149,12 @@ class VelocityTracker { ...@@ -149,17 +149,12 @@ class VelocityTracker {
/// The kind of pointer this tracker is for. /// The kind of pointer this tracker is for.
final PointerDeviceKind kind; final PointerDeviceKind kind;
// Time difference since the last sample was added
final Stopwatch _sinceLastSample = Stopwatch();
// Circular buffer; current sample at _index. // Circular buffer; current sample at _index.
final List<_PointAtTime?> _samples = List<_PointAtTime?>.filled(_historySize, null); final List<_PointAtTime?> _samples = List<_PointAtTime?>.filled(_historySize, null);
int _index = 0; int _index = 0;
/// Adds a position as the given time to the tracker. /// Adds a position as the given time to the tracker.
void addPosition(Duration time, Offset position) { void addPosition(Duration time, Offset position) {
_sinceLastSample.start();
_sinceLastSample.reset();
_index += 1; _index += 1;
if (_index == _historySize) { if (_index == _historySize) {
_index = 0; _index = 0;
...@@ -174,16 +169,6 @@ class VelocityTracker { ...@@ -174,16 +169,6 @@ class VelocityTracker {
/// ///
/// Returns null if there is no data on which to base an estimate. /// Returns null if there is no data on which to base an estimate.
VelocityEstimate? getVelocityEstimate() { VelocityEstimate? getVelocityEstimate() {
// no recent user movement?
if (_sinceLastSample.elapsedMilliseconds > VelocityTracker._assumePointerMoveStoppedMilliseconds) {
return const VelocityEstimate(
pixelsPerSecond: Offset.zero,
confidence: 1.0,
duration: Duration.zero,
offset: Offset.zero,
);
}
final List<double> x = <double>[]; final List<double> x = <double>[];
final List<double> y = <double>[]; final List<double> y = <double>[];
final List<double> w = <double>[]; final List<double> w = <double>[];
...@@ -210,7 +195,7 @@ class VelocityTracker { ...@@ -210,7 +195,7 @@ class VelocityTracker {
final double age = (newestSample.time - sample.time).inMicroseconds.toDouble() / 1000; final double age = (newestSample.time - sample.time).inMicroseconds.toDouble() / 1000;
final double delta = (sample.time - previousSample.time).inMicroseconds.abs().toDouble() / 1000; final double delta = (sample.time - previousSample.time).inMicroseconds.abs().toDouble() / 1000;
previousSample = sample; previousSample = sample;
if (age > _horizonMilliseconds || delta > VelocityTracker._assumePointerMoveStoppedMilliseconds) { if (age > _horizonMilliseconds || delta > _assumePointerMoveStoppedMilliseconds) {
break; break;
} }
...@@ -303,8 +288,6 @@ class IOSScrollViewFlingVelocityTracker extends VelocityTracker { ...@@ -303,8 +288,6 @@ class IOSScrollViewFlingVelocityTracker extends VelocityTracker {
@override @override
void addPosition(Duration time, Offset position) { void addPosition(Duration time, Offset position) {
_sinceLastSample.start();
_sinceLastSample.reset();
assert(() { assert(() {
final _PointAtTime? previousPoint = _touchSamples[_index]; final _PointAtTime? previousPoint = _touchSamples[_index];
if (previousPoint == null || previousPoint.time <= time) { if (previousPoint == null || previousPoint.time <= time) {
...@@ -343,16 +326,6 @@ class IOSScrollViewFlingVelocityTracker extends VelocityTracker { ...@@ -343,16 +326,6 @@ class IOSScrollViewFlingVelocityTracker extends VelocityTracker {
@override @override
VelocityEstimate getVelocityEstimate() { VelocityEstimate getVelocityEstimate() {
// no recent user movement?
if (_sinceLastSample.elapsedMilliseconds > VelocityTracker._assumePointerMoveStoppedMilliseconds) {
return const VelocityEstimate(
pixelsPerSecond: Offset.zero,
confidence: 1.0,
duration: Duration.zero,
offset: Offset.zero,
);
}
// The velocity estimated using this expression is an approximation of the // The velocity estimated using this expression is an approximation of the
// scroll velocity of an iOS scroll view at the moment the user touch was // scroll velocity of an iOS scroll view at the moment the user touch was
// released, not the final velocity of the iOS pan gesture recognizer // released, not the final velocity of the iOS pan gesture recognizer
...@@ -414,16 +387,6 @@ class MacOSScrollViewFlingVelocityTracker extends IOSScrollViewFlingVelocityTrac ...@@ -414,16 +387,6 @@ class MacOSScrollViewFlingVelocityTracker extends IOSScrollViewFlingVelocityTrac
@override @override
VelocityEstimate getVelocityEstimate() { VelocityEstimate getVelocityEstimate() {
// no recent user movement?
if (_sinceLastSample.elapsedMilliseconds > VelocityTracker._assumePointerMoveStoppedMilliseconds) {
return const VelocityEstimate(
pixelsPerSecond: Offset.zero,
confidence: 1.0,
duration: Duration.zero,
offset: Offset.zero,
);
}
// The velocity estimated using this expression is an approximation of the // The velocity estimated using this expression is an approximation of the
// scroll velocity of a macOS scroll view at the moment the user touch was // scroll velocity of a macOS scroll view at the moment the user touch was
// released. // released.
......
...@@ -144,22 +144,4 @@ void main() { ...@@ -144,22 +144,4 @@ void main() {
} }
} }
}); });
test('Assume zero velocity when there are no recent samples', () async {
final IOSScrollViewFlingVelocityTracker tracker = IOSScrollViewFlingVelocityTracker(PointerDeviceKind.touch);
Offset position = Offset.zero;
Duration time = Duration.zero;
const Offset positionDelta = Offset(0, -1);
const Duration durationDelta = Duration(seconds: 1);
for (int i = 0; i < 10; i+=1) {
position += positionDelta;
time += durationDelta;
tracker.addPosition(time, position);
}
await Future<void>.delayed(const Duration(milliseconds: 50));
expect(tracker.getVelocity().pixelsPerSecond, Offset.zero);
});
} }
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