Commit a90e2550 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Don't overshoot ballisitic scroll activities (#7670)

When we start a ballisitic scroll activity to correct an out-of-range scroll
offset, make sure we start with a velocity that is headed in the right
direction.
parent 9f28b4ff
......@@ -462,9 +462,9 @@ abstract class ClampingAbsoluteScrollPositionMixIn implements AbsoluteScrollPosi
Simulation createBallisticSimulation(double velocity) {
if (outOfRange) {
if (pixels > maxScrollExtent)
return new ScrollSpringSimulation(_defaultScrollSpring, pixels, maxScrollExtent, velocity);
return new ScrollSpringSimulation(_defaultScrollSpring, pixels, maxScrollExtent, math.min(0.0, velocity));
if (pixels < minScrollExtent)
return new ScrollSpringSimulation(_defaultScrollSpring, pixels, minScrollExtent, velocity);
return new ScrollSpringSimulation(_defaultScrollSpring, pixels, minScrollExtent, math.max(0.0, velocity));
assert(false);
}
if (!atEdge && velocity.abs() >= scrollTolerances.velocity) {
......
......@@ -62,7 +62,7 @@ void main() {
testWidgets('ScrollView control test', (WidgetTester tester) async {
List<String> log = <String>[];
await tester.pumpWidget(new ClipRect(child: new ScrollView(
await tester.pumpWidget(new ScrollView(
children: _kStates.map<Widget>((String state) {
return new GestureDetector(
onTap: () {
......@@ -77,7 +77,7 @@ void main() {
),
);
}).toList()
)));
));
await tester.tap(find.text('Alabama'));
expect(log, equals(<String>['Alabama']));
......@@ -95,4 +95,32 @@ void main() {
expect(log, equals(<String>['Massachusetts']));
log.clear();
});
testWidgets('ScrollView restart ballistic activity out of range', (WidgetTester tester) async {
Widget buildScrollView(int n) {
return new ScrollView(
children: _kStates.take(n).map<Widget>((String state) {
return new Container(
height: 200.0,
decoration: const BoxDecoration(
backgroundColor: const Color(0xFF0000FF),
),
child: new Text(state),
);
}).toList()
);
}
await tester.pumpWidget(buildScrollView(30));
await tester.fling(find.byType(ScrollView), const Offset(0.0, -4000.0), 4000.0);
await tester.pumpWidget(buildScrollView(15));
await tester.pump(const Duration(milliseconds: 10));
await tester.pump(const Duration(milliseconds: 10));
await tester.pump(const Duration(milliseconds: 10));
await tester.pump(const Duration(milliseconds: 10));
await tester.pumpUntilNoTransientCallbacks(const Duration(milliseconds: 100));
Viewport2 viewport = tester.widget(find.byType(Viewport2));
expect(viewport.offset.pixels, equals(2400.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