Merge pull request #1342 from apwilson/fling

Add fling to Scrollable.
This commit is contained in:
Andrew Wilson 2015-09-25 11:18:53 -07:00
commit 75061728e6

View File

@ -163,6 +163,14 @@ abstract class Scrollable extends StatefulComponent {
return scrollTo(newScrollOffset, duration: duration, curve: curve); return scrollTo(newScrollOffset, duration: duration, curve: curve);
} }
void fling(Offset velocity) {
if (velocity != Offset.zero) {
_startToEndAnimation(velocity: _scrollVelocity(velocity));
} else if (!_toEndAnimation.isAnimating && (_toOffsetAnimation == null || !_toOffsetAnimation.isAnimating)) {
settleScrollOffset();
}
}
void settleScrollOffset() { void settleScrollOffset() {
_startToEndAnimation(); _startToEndAnimation();
} }
@ -185,11 +193,7 @@ abstract class Scrollable extends StatefulComponent {
} }
void _handleDragEnd(Offset velocity) { void _handleDragEnd(Offset velocity) {
if (velocity != Offset.zero) { fling(velocity);
_startToEndAnimation(velocity: _scrollVelocity(velocity));
} else if (!_toEndAnimation.isAnimating && (_toOffsetAnimation == null || !_toOffsetAnimation.isAnimating)) {
settleScrollOffset();
}
} }
final List<ScrollListener> _listeners = new List<ScrollListener>(); final List<ScrollListener> _listeners = new List<ScrollListener>();
@ -566,7 +570,7 @@ class PageableList<T> extends ScrollableList<T> {
.clamp(scrollBehavior.minScrollOffset, scrollBehavior.maxScrollOffset); .clamp(scrollBehavior.minScrollOffset, scrollBehavior.maxScrollOffset);
} }
void _handleDragEnd(sky.Offset velocity) { void fling(sky.Offset velocity) {
double scrollVelocity = _scrollVelocity(velocity); double scrollVelocity = _scrollVelocity(velocity);
double newScrollOffset = _snapScrollOffset(scrollOffset + scrollVelocity.sign * itemExtent) double newScrollOffset = _snapScrollOffset(scrollOffset + scrollVelocity.sign * itemExtent)
.clamp(_snapScrollOffset(scrollOffset - itemExtent / 2.0), .clamp(_snapScrollOffset(scrollOffset - itemExtent / 2.0),