Skip to content

Commit

Permalink
Merge pull request flutter#1342 from apwilson/fling
Browse files Browse the repository at this point in the history
Add fling to Scrollable.
  • Loading branch information
apwilson committed Sep 25, 2015
2 parents 2272c89 + d8ea1b1 commit 8669d11
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions sky/packages/sky/lib/src/widgets/scrollable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ abstract class Scrollable extends StatefulComponent {
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() {
_startToEndAnimation();
}
Expand All @@ -185,11 +193,7 @@ abstract class Scrollable extends StatefulComponent {
}

void _handleDragEnd(Offset velocity) {
if (velocity != Offset.zero) {
_startToEndAnimation(velocity: _scrollVelocity(velocity));
} else if (!_toEndAnimation.isAnimating && (_toOffsetAnimation == null || !_toOffsetAnimation.isAnimating)) {
settleScrollOffset();
}
fling(velocity);
}

final List<ScrollListener> _listeners = new List<ScrollListener>();
Expand Down Expand Up @@ -566,7 +570,7 @@ class PageableList<T> extends ScrollableList<T> {
.clamp(scrollBehavior.minScrollOffset, scrollBehavior.maxScrollOffset);
}

void _handleDragEnd(sky.Offset velocity) {
void fling(sky.Offset velocity) {
double scrollVelocity = _scrollVelocity(velocity);
double newScrollOffset = _snapScrollOffset(scrollOffset + scrollVelocity.sign * itemExtent)
.clamp(_snapScrollOffset(scrollOffset - itemExtent / 2.0),
Expand Down

0 comments on commit 8669d11

Please sign in to comment.