Unverified Commit 0cc2eff2 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Revert "[SingleChildScrollView] Correct the offset pixels if it is out of...

Revert "[SingleChildScrollView] Correct the offset pixels if it is out of range during layout" (#136744)
parent 0383d8ba
...@@ -495,14 +495,6 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix ...@@ -495,14 +495,6 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
size = constraints.constrain(child!.size); size = constraints.constrain(child!.size);
} }
if (offset.hasPixels) {
if (offset.pixels > _maxScrollExtent) {
offset.correctBy(_maxScrollExtent - offset.pixels);
} else if (offset.pixels < _minScrollExtent) {
offset.correctBy(_minScrollExtent - offset.pixels);
}
}
offset.applyViewportDimension(_viewportExtent); offset.applyViewportDimension(_viewportExtent);
offset.applyContentDimensions(_minScrollExtent, _maxScrollExtent); offset.applyContentDimensions(_minScrollExtent, _maxScrollExtent);
} }
......
...@@ -92,40 +92,19 @@ void main() { ...@@ -92,40 +92,19 @@ void main() {
expect(scrollable.position.pixels, equals(50.0)); expect(scrollable.position.pixels, equals(50.0));
}); });
testWidgetsWithLeakTracking('ClampingScrollPhysics handles out of bounds ScrollPosition - initialScrollOffset', (WidgetTester tester) async { testWidgetsWithLeakTracking('ClampingScrollPhysics handles out of bounds ScrollPosition', (WidgetTester tester) async {
Future<void> testOutOfBounds(ScrollPhysics physics, double initialOffset, double expectedOffset) async { Future<void> testOutOfBounds(ScrollPhysics physics, double initialOffset, double expectedOffset) async {
final ScrollController scrollController = ScrollController(initialScrollOffset: initialOffset); final ScrollController scrollController = ScrollController(initialScrollOffset: initialOffset);
addTearDown(scrollController.dispose); addTearDown(scrollController.dispose);
await tester.pumpWidget(buildFrame(physics, scrollController: scrollController)); await tester.pumpWidget(buildFrame(physics, scrollController: scrollController));
final ScrollableState scrollable = tester.state(find.byType(Scrollable)); final ScrollableState scrollable = tester.state(find.byType(Scrollable));
// The initialScrollOffset will be corrected during the first frame. expect(scrollable.position.pixels, equals(initialOffset));
await tester.pump(const Duration(seconds: 1)); // Allow overscroll to settle
expect(scrollable.position.pixels, equals(expectedOffset)); expect(scrollable.position.pixels, equals(expectedOffset));
} }
await testOutOfBounds(const ClampingScrollPhysics(), -400.0, 0.0); await testOutOfBounds(const ClampingScrollPhysics(), -400.0, 0.0);
await testOutOfBounds(const ClampingScrollPhysics(), 800.0, 50.0); await testOutOfBounds(const ClampingScrollPhysics(), 800.0, 50.0);
}); });
testWidgetsWithLeakTracking('ClampingScrollPhysics handles out of bounds ScrollPosition - jumpTo', (WidgetTester tester) async {
Future<void> testOutOfBounds(ScrollPhysics physics, double targetOffset, double endingOffset) async {
final ScrollController scrollController = ScrollController();
addTearDown(scrollController.dispose);
await tester.pumpWidget(buildFrame(physics, scrollController: scrollController));
final ScrollableState scrollable = tester.state(find.byType(Scrollable));
expect(scrollable.position.pixels, equals(0.0));
scrollController.jumpTo(targetOffset);
await tester.pump();
expect(scrollable.position.pixels, equals(targetOffset));
await tester.pump(const Duration(seconds: 1)); // Allow overscroll animation to settle
expect(scrollable.position.pixels, equals(endingOffset));
}
await testOutOfBounds(const ClampingScrollPhysics(), -400.0, 0.0);
await testOutOfBounds(const ClampingScrollPhysics(), 800.0, 50.0);
});
} }
...@@ -23,17 +23,12 @@ void main() { ...@@ -23,17 +23,12 @@ void main() {
} }
await tester.pumpWidget(buildFrame(1200.0)); await tester.pumpWidget(buildFrame(1200.0));
expect(events.length, 1); expect(events.length, 1);
ScrollMetricsNotification event = events[0] as ScrollMetricsNotification;
expect(event.metrics.extentBefore, 0.0);
expect(event.metrics.extentInside, 600.0);
expect(event.metrics.extentAfter, 600.0);
expect(event.metrics.extentTotal, 1200.0);
events.clear(); events.clear();
await tester.pumpWidget(buildFrame(1000.0)); await tester.pumpWidget(buildFrame(1000.0));
// Change the content dimensions will trigger a new event. // Change the content dimensions will trigger a new event.
expect(events.length, 1); expect(events.length, 1);
event = events[0] as ScrollMetricsNotification; ScrollMetricsNotification event = events[0] as ScrollMetricsNotification;
expect(event.metrics.extentBefore, 0.0); expect(event.metrics.extentBefore, 0.0);
expect(event.metrics.extentInside, 600.0); expect(event.metrics.extentInside, 600.0);
expect(event.metrics.extentAfter, 400.0); expect(event.metrics.extentAfter, 400.0);
...@@ -41,27 +36,24 @@ void main() { ...@@ -41,27 +36,24 @@ void main() {
events.clear(); events.clear();
final TestGesture gesture = await tester.startGesture(const Offset(100.0, 100.0)); final TestGesture gesture = await tester.startGesture(const Offset(100.0, 100.0));
await tester.pump(const Duration(seconds: 1)); expect(events.length, 1);
await gesture.moveBy(const Offset(-10.0, -10.0)); // user scroll do not trigger the ScrollContentMetricsNotification.
await tester.pump(const Duration(seconds: 1));
await gesture.up();
await tester.pump(const Duration(seconds: 1));
expect(events.length, 5);
// user scroll do not trigger the ScrollMetricsNotification.
expect(events[0] is ScrollStartNotification, true); expect(events[0] is ScrollStartNotification, true);
expect(events[1] is UserScrollNotification, true);
expect(events[2] is ScrollUpdateNotification, true); events.clear();
expect(events[3] is ScrollEndNotification, true); await gesture.moveBy(const Offset(-10.0, -10.0));
expect(events[4] is UserScrollNotification, true); expect(events.length, 2);
// User scroll do not trigger the ScrollContentMetricsNotification.
expect(events[0] is UserScrollNotification, true);
expect(events[1] is ScrollUpdateNotification, true);
events.clear(); events.clear();
// Change the content dimensions again. // Change the content dimensions again.
await tester.pumpWidget(buildFrame(500.0)); await tester.pumpWidget(buildFrame(500.0));
expect(events.length, 1); expect(events.length, 1);
event = events[0] as ScrollMetricsNotification; event = events[0] as ScrollMetricsNotification;
expect(event.metrics.extentBefore, 0.0); expect(event.metrics.extentBefore, 10.0);
expect(event.metrics.extentInside, 600.0); expect(event.metrics.extentInside, 590.0);
expect(event.metrics.extentAfter, 0.0); expect(event.metrics.extentAfter, 0.0);
expect(event.metrics.extentTotal, 600.0); expect(event.metrics.extentTotal, 600.0);
......
...@@ -1039,7 +1039,7 @@ void main() { ...@@ -1039,7 +1039,7 @@ void main() {
// Make the outer constraints larger that the scrollable widget is no longer able to scroll. // Make the outer constraints larger that the scrollable widget is no longer able to scroll.
await tester.pumpWidget(build(300.0)); await tester.pumpWidget(build(300.0));
expect(controller.position.pixels, 0.0); expect(controller.position.pixels, 100.0);
expect(controller.position.maxScrollExtent, 0.0); expect(controller.position.maxScrollExtent, 0.0);
// Hover over the scroll view and create a zero offset pointer scroll. // Hover over the scroll view and create a zero offset pointer scroll.
......
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