From 05cd2e92ab8736c174ff8d9eec1ab2380764e372 Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Tue, 14 Jul 2015 15:36:42 -0700 Subject: [PATCH] Correct bottom overscroll in VariableHeightScrollable Also updated the createDefaultScrollSimulation() springConstant and drag parameters to make non-overscroll fling scrolls slowdown faster and overscrolls snap back into place a little more snappily. R=abarth@chromium.org Review URL: https://codereview.chromium.org/1241733002 . --- sdk/lib/animation/scroll_behavior.dart | 6 +++--- sdk/lib/widgets/scrollable.dart | 1 + sdk/lib/widgets/variable_height_scrollable.dart | 15 ++++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/sdk/lib/animation/scroll_behavior.dart b/sdk/lib/animation/scroll_behavior.dart index b69c05db0ab..b01713c888d 100644 --- a/sdk/lib/animation/scroll_behavior.dart +++ b/sdk/lib/animation/scroll_behavior.dart @@ -49,8 +49,8 @@ class BoundedBehavior extends ScrollBehavior { Simulation createDefaultScrollSimulation(double position, double velocity, double minScrollOffset, double maxScrollOffset) { double velocityPerSecond = velocity * _kSecondsPerMillisecond; SpringDescription spring = new SpringDescription.withDampingRatio( - mass: 1.0, springConstant: 85.0, ratio: 1.1); - double drag = 0.4; + mass: 1.0, springConstant: 170.0, ratio: 1.1); + double drag = 0.025; return new ScrollSimulation(position, velocityPerSecond, minScrollOffset, maxScrollOffset, spring, drag); } @@ -76,7 +76,7 @@ class OverscrollBehavior extends BoundedBehavior { // If we're overscrolling, we want move the scroll offset 2x // slower than we would otherwise. Therefore, we "rewind" the // newScrollOffset by half the amount that we moved it above. - // Notice that we clap the "old" value to 0.0 so that we only + // Notice that we clamp the "old" value to 0.0 so that we only // reduce the portion of scrollDelta that's applied beyond 0.0. We // do similar things for overscroll in the other direction. if (newScrollOffset < 0.0) { diff --git a/sdk/lib/widgets/scrollable.dart b/sdk/lib/widgets/scrollable.dart index 1195a6a9b86..6a687b5fa67 100644 --- a/sdk/lib/widgets/scrollable.dart +++ b/sdk/lib/widgets/scrollable.dart @@ -13,6 +13,7 @@ import 'package:sky/widgets/basic.dart'; const double _kMillisecondsPerSecond = 1000.0; double _velocityForFlingGesture(double eventVelocity) { + // eventVelocity is pixels/second, config min,max limits are pixels/ms return eventVelocity.clamp(-config.kMaxFlingVelocity, config.kMaxFlingVelocity) / _kMillisecondsPerSecond; } diff --git a/sdk/lib/widgets/variable_height_scrollable.dart b/sdk/lib/widgets/variable_height_scrollable.dart index ed74d11ca23..58653aeabfa 100644 --- a/sdk/lib/widgets/variable_height_scrollable.dart +++ b/sdk/lib/widgets/variable_height_scrollable.dart @@ -19,9 +19,12 @@ class VariableHeightScrollable extends Scrollable { IndexedBuilder builder; Object token; + bool _contentsChanged = true; void syncFields(VariableHeightScrollable source) { builder = source.builder; + if (token != source.token) + _contentsChanged = true; token = source.token; super.syncFields(source); } @@ -40,9 +43,15 @@ class VariableHeightScrollable extends Scrollable { bool didReachLastChild ) { assert(childOffsets.length > 0); - scrollBehavior.contentsSize = didReachLastChild ? childOffsets.last : double.INFINITY; - if (didReachLastChild && scrollOffset > scrollBehavior.maxScrollOffset) - settleScrollOffset(); + if (didReachLastChild) { + scrollBehavior.contentsSize = childOffsets.last; + if (_contentsChanged && scrollOffset > scrollBehavior.maxScrollOffset) { + _contentsChanged = false; + settleScrollOffset(); + } + } else { + scrollBehavior.contentsSize = double.INFINITY; + } } Widget buildContent() {