Reland "Remove single-view assumption from ScrollPhysics (#117503)" (#117916)

This reverts commit c956121ac0.
This commit is contained in:
Michael Goderbauer
2023-01-03 13:34:08 -08:00
committed by GitHub
parent 084be5e6db
commit fdc25a1700
16 changed files with 102 additions and 41 deletions

View File

@@ -371,14 +371,14 @@ class _SnappingScrollPhysics extends ClampingScrollPhysics {
return _SnappingScrollPhysics(parent: buildParent(ancestor), midScrollOffset: midScrollOffset);
}
Simulation _toMidScrollOffsetSimulation(double offset, double dragVelocity) {
Simulation _toMidScrollOffsetSimulation(double offset, double dragVelocity, ScrollMetrics metrics) {
final double velocity = math.max(dragVelocity, minFlingVelocity);
return ScrollSpringSimulation(spring, offset, midScrollOffset, velocity, tolerance: tolerance);
return ScrollSpringSimulation(spring, offset, midScrollOffset, velocity, tolerance: toleranceFor(metrics));
}
Simulation _toZeroScrollOffsetSimulation(double offset, double dragVelocity) {
Simulation _toZeroScrollOffsetSimulation(double offset, double dragVelocity, ScrollMetrics metrics) {
final double velocity = math.max(dragVelocity, minFlingVelocity);
return ScrollSpringSimulation(spring, offset, 0.0, velocity, tolerance: tolerance);
return ScrollSpringSimulation(spring, offset, 0.0, velocity, tolerance: toleranceFor(metrics));
}
@override
@@ -396,10 +396,10 @@ class _SnappingScrollPhysics extends ClampingScrollPhysics {
return simulation;
}
if (dragVelocity > 0.0) {
return _toMidScrollOffsetSimulation(offset, dragVelocity);
return _toMidScrollOffsetSimulation(offset, dragVelocity, position);
}
if (dragVelocity < 0.0) {
return _toZeroScrollOffsetSimulation(offset, dragVelocity);
return _toZeroScrollOffsetSimulation(offset, dragVelocity, position);
}
} else {
// The user ended the drag with little or no velocity. If they
@@ -408,10 +408,10 @@ class _SnappingScrollPhysics extends ClampingScrollPhysics {
// otherwise snap to zero.
final double snapThreshold = midScrollOffset / 2.0;
if (offset >= snapThreshold && offset < midScrollOffset) {
return _toMidScrollOffsetSimulation(offset, dragVelocity);
return _toMidScrollOffsetSimulation(offset, dragVelocity, position);
}
if (offset > 0.0 && offset < snapThreshold) {
return _toZeroScrollOffsetSimulation(offset, dragVelocity);
return _toZeroScrollOffsetSimulation(offset, dragVelocity, position);
}
}
return simulation;