Unverified Commit 12b8d9db authored by Pascal Welsch's avatar Pascal Welsch Committed by GitHub

Reduce iOS scroll damping for lists with differently sized items (#59623)

parent 77b4505c
......@@ -533,7 +533,7 @@ class BouncingScrollPhysics extends ScrollPhysics {
return BouncingScrollSimulation(
spring: spring,
position: position.pixels,
velocity: velocity * 0.91, // TODO(abarth): We should move this constant closer to the drag end.
velocity: velocity,
leadingExtent: position.minScrollExtent,
trailingExtent: position.maxScrollExtent,
tolerance: tolerance,
......@@ -549,9 +549,8 @@ class BouncingScrollPhysics extends ScrollPhysics {
double get minFlingVelocity => kMinFlingVelocity * 2.0;
// Methodology:
// 1- Use https://github.com/flutter/scroll_overlay to test with Flutter and
// platform scroll views superimposed.
// 2- Record incoming speed and make rapid flings in the test app.
// 1- Use https://github.com/flutter/platform_tests/tree/master/scroll_overlay to test with
// Flutter and platform scroll views superimposed.
// 3- If the scrollables stopped overlapping at any moment, adjust the desired
// output value of this function at that input speed.
// 4- Feed new input/output set into a power curve fitter. Change function
......
......@@ -51,6 +51,8 @@ class BouncingScrollSimulation extends Simulation {
_springSimulation = _overscrollSimulation(position, velocity);
_springTime = double.negativeInfinity;
} else {
// Taken from UIScrollView.decelerationRate (.normal = 0.998)
// 0.998^1000 = ~0.135
_frictionSimulation = FrictionSimulation(0.135, position, velocity);
final double finalX = _frictionSimulation.finalX;
if (velocity > 0.0 && finalX > trailingExtent) {
......
......@@ -97,6 +97,26 @@ void main() {
);
});
test('ScrollPhysics scrolling subclasses - Creating the simulation doesn\'t alter the velocity for time 0', () {
final ScrollMetrics position = FixedScrollMetrics(
minScrollExtent: 0.0,
maxScrollExtent: 100.0,
pixels: 20.0,
viewportDimension: 500.0,
axisDirection: AxisDirection.down,
);
const BouncingScrollPhysics bounce = BouncingScrollPhysics();
const ClampingScrollPhysics clamp = ClampingScrollPhysics();
const PageScrollPhysics page = PageScrollPhysics();
// Calls to createBallisticSimulation may happen on every frame (i.e. when the maxScrollExtent changes)
// Changing velocity for time 0 may cause a sudden, unwanted damping/speedup effect
expect(bounce.createBallisticSimulation(position, 1000).dx(0), moreOrLessEquals(1000));
expect(clamp.createBallisticSimulation(position, 1000).dx(0), moreOrLessEquals(1000));
expect(page.createBallisticSimulation(position, 1000).dx(0), moreOrLessEquals(1000));
});
group('BouncingScrollPhysics test', () {
BouncingScrollPhysics physicsUnderTest;
......
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