Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions packages/flutter/lib/src/widgets/scroll_physics.dart
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

leadingExtent: position.minScrollExtent,
trailingExtent: position.maxScrollExtent,
tolerance: tolerance,
Expand All @@ -548,9 +548,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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for updating this!

// 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
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/widgets/scroll_simulation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions packages/flutter/test/widgets/scroll_physics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down