Commit 98a2c9b0 authored by Adam Barth's avatar Adam Barth

ScrollableBlock should be able to overscroll

When a ScrollableBlock can scroll, we want to be able to drag into the
overscroll region. Previously we could fling into the overscroll region, but we
couldn't actually drag there.
parent 763b423f
...@@ -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% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment