提交 fc1c6821 编写于 作者: A Adam Barth

Merge pull request #424 from abarth/scrollable_block_cannot_overscroll

ScrollableBlock should be able to overscroll
...@@ -54,15 +54,6 @@ Simulation createDefaultScrollSimulation(double position, double velocity, doubl ...@@ -54,15 +54,6 @@ Simulation createDefaultScrollSimulation(double position, double velocity, doubl
return new ScrollSimulation(position, velocityPerSecond, minScrollOffset, maxScrollOffset, spring, drag); return new ScrollSimulation(position, velocityPerSecond, minScrollOffset, maxScrollOffset, spring, drag);
} }
class FlingBehavior extends BoundedBehavior {
FlingBehavior({ double contentsSize: 0.0, double containerSize: 0.0 })
: super(contentsSize: contentsSize, containerSize: containerSize);
Simulation release(double position, double velocity) {
return createDefaultScrollSimulation(position, velocity, minScrollOffset, maxScrollOffset);
}
}
class OverscrollBehavior extends BoundedBehavior { class OverscrollBehavior extends BoundedBehavior {
OverscrollBehavior({ double contentsSize: 0.0, double containerSize: 0.0 }) OverscrollBehavior({ double contentsSize: 0.0, double containerSize: 0.0 })
: super(contentsSize: contentsSize, containerSize: containerSize); : super(contentsSize: contentsSize, containerSize: containerSize);
...@@ -79,11 +70,27 @@ class OverscrollBehavior extends BoundedBehavior { ...@@ -79,11 +70,27 @@ class OverscrollBehavior extends BoundedBehavior {
// Notice that we clamp 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 // reduce the portion of scrollDelta that's applied beyond 0.0. We
// do similar things for overscroll in the other direction. // do similar things for overscroll in the other direction.
if (newScrollOffset < 0.0) { if (newScrollOffset < minScrollOffset) {
newScrollOffset -= (newScrollOffset - math.min(0.0, scrollOffset)) / 2.0; newScrollOffset -= (newScrollOffset - math.min(minScrollOffset, scrollOffset)) / 2.0;
} else if (newScrollOffset > maxScrollOffset) { } else if (newScrollOffset > maxScrollOffset) {
newScrollOffset -= (newScrollOffset - math.max(maxScrollOffset, scrollOffset)) / 2.0; newScrollOffset -= (newScrollOffset - math.max(maxScrollOffset, scrollOffset)) / 2.0;
} }
return newScrollOffset; return newScrollOffset;
} }
} }
class OverscrollWhenScrollableBehavior extends OverscrollBehavior {
bool get isScrollable => contentsSize > containerSize;
Simulation release(double position, double velocity) {
if (isScrollable || position < minScrollOffset || position > maxScrollOffset)
return super.release(position, velocity);
return null;
}
double applyCurve(double scrollOffset, double scrollDelta) {
if (isScrollable)
return super.applyCurve(scrollOffset, scrollDelta);
return minScrollOffset;
}
}
...@@ -224,8 +224,8 @@ class ScrollableViewport extends Scrollable { ...@@ -224,8 +224,8 @@ class ScrollableViewport extends Scrollable {
super.syncFields(source); super.syncFields(source);
} }
ScrollBehavior createScrollBehavior() => new FlingBehavior(); ScrollBehavior createScrollBehavior() => new OverscrollWhenScrollableBehavior();
FlingBehavior get scrollBehavior => super.scrollBehavior; OverscrollWhenScrollableBehavior get scrollBehavior => super.scrollBehavior;
double _viewportHeight = 0.0; double _viewportHeight = 0.0;
double _childHeight = 0.0; double _childHeight = 0.0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册