From 461b191487688c93193894aa92cdf01f0d18a4d0 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 22 Sep 2015 13:34:57 -0700 Subject: [PATCH 1/3] Added velocity and distance thresholds to ScrollSimulation, ScrollBehavior --- .../lib/src/animation/scroll_behavior.dart | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/animation/scroll_behavior.dart b/packages/flutter/lib/src/animation/scroll_behavior.dart index 14d47b0450..d800b82cfd 100644 --- a/packages/flutter/lib/src/animation/scroll_behavior.dart +++ b/packages/flutter/lib/src/animation/scroll_behavior.dart @@ -3,6 +3,7 @@ // found in the LICENSE file. import 'dart:math' as math; +import 'dart:sky' as sky; import 'package:newton/newton.dart'; @@ -95,10 +96,21 @@ class UnboundedBehavior extends ExtentScrollBehavior { } Simulation _createDefaultScrollSimulation(double position, double velocity, double minScrollOffset, double maxScrollOffset) { - double velocityPerSecond = velocity * _kSecondsPerMillisecond; - SpringDescription spring = new SpringDescription.withDampingRatio( - mass: 1.0, springConstant: 170.0, ratio: 1.1); - return new ScrollSimulation(position, velocityPerSecond, minScrollOffset, maxScrollOffset, spring, _kScrollDrag); + double startVelocity = velocity * _kSecondsPerMillisecond; + + // Assume that we're rendering at atleast 15 FPS. Stop when we're + // scrolling less than one logical pixel per frame. We're essentially + // normalizing by the devicePixelRatio so that the threshold has the + // same effect independent of the device's pixel density. + double endVelocity = 15.0 * sky.view.devicePixelRatio; + + // Similar to endVelocity. Stop scrolling when we're this close to + // destiniation scroll offset. + double endDistance = 0.5 * sky.view.devicePixelRatio; + + SpringDescription spring = new SpringDescription.withDampingRatio(mass: 1.0, springConstant: 170.0, ratio: 1.1); + return new ScrollSimulation( + position, startVelocity, endVelocity, endDistance, minScrollOffset, maxScrollOffset, spring, _kScrollDrag); } /// A scroll behavior that lets the user scroll beyond the scroll bounds with some resistance From 720a913e1053983e9e0f333fe719847d76e058fc Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 22 Sep 2015 14:50:27 -0700 Subject: [PATCH 2/3] replace endDistance and endVelocity parameters with tolerance --- packages/flutter/lib/src/animation/scroll_behavior.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/animation/scroll_behavior.dart b/packages/flutter/lib/src/animation/scroll_behavior.dart index d800b82cfd..09db0c7f07 100644 --- a/packages/flutter/lib/src/animation/scroll_behavior.dart +++ b/packages/flutter/lib/src/animation/scroll_behavior.dart @@ -108,9 +108,11 @@ Simulation _createDefaultScrollSimulation(double position, double velocity, doub // destiniation scroll offset. double endDistance = 0.5 * sky.view.devicePixelRatio; + Tolerance tolerance = new Tolerance(velocity: endVelocity, distance: endDistance); SpringDescription spring = new SpringDescription.withDampingRatio(mass: 1.0, springConstant: 170.0, ratio: 1.1); return new ScrollSimulation( - position, startVelocity, endVelocity, endDistance, minScrollOffset, maxScrollOffset, spring, _kScrollDrag); + position, startVelocity, minScrollOffset, maxScrollOffset, spring, _kScrollDrag, tolerance); + } /// A scroll behavior that lets the user scroll beyond the scroll bounds with some resistance From abd7059ffa3fda274002af4217a0541df57d73ae Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 22 Sep 2015 15:08:13 -0700 Subject: [PATCH 3/3] Set simulation tolerance field --- packages/flutter/lib/src/animation/scroll_behavior.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/flutter/lib/src/animation/scroll_behavior.dart b/packages/flutter/lib/src/animation/scroll_behavior.dart index 09db0c7f07..337b3d4883 100644 --- a/packages/flutter/lib/src/animation/scroll_behavior.dart +++ b/packages/flutter/lib/src/animation/scroll_behavior.dart @@ -108,11 +108,11 @@ Simulation _createDefaultScrollSimulation(double position, double velocity, doub // destiniation scroll offset. double endDistance = 0.5 * sky.view.devicePixelRatio; - Tolerance tolerance = new Tolerance(velocity: endVelocity, distance: endDistance); SpringDescription spring = new SpringDescription.withDampingRatio(mass: 1.0, springConstant: 170.0, ratio: 1.1); - return new ScrollSimulation( - position, startVelocity, minScrollOffset, maxScrollOffset, spring, _kScrollDrag, tolerance); - + ScrollSimulation simulation = + new ScrollSimulation(position, startVelocity, minScrollOffset, maxScrollOffset, spring, _kScrollDrag) + ..tolerance = new Tolerance(velocity: endVelocity, distance: endDistance); + return simulation; } /// A scroll behavior that lets the user scroll beyond the scroll bounds with some resistance