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 .
This commit is contained in:
Hans Muller 2015-07-14 15:36:42 -07:00
parent 64c5420007
commit 05cd2e92ab
3 changed files with 16 additions and 6 deletions

View File

@ -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) {

View File

@ -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;
}

View File

@ -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() {