Unverified Commit 8e58c51d authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Update viewport dimensions when scrollDirection changes (#61973)

parent 4b4287ba
...@@ -1321,16 +1321,6 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat ...@@ -1321,16 +1321,6 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat
return true; return true;
}()); }());
size = constraints.biggest; size = constraints.biggest;
// We ignore the return value of applyViewportDimension below because we are
// going to go through performLayout next regardless.
switch (axis) {
case Axis.vertical:
offset.applyViewportDimension(size.height);
break;
case Axis.horizontal:
offset.applyViewportDimension(size.width);
break;
}
} }
static const int _maxLayoutCycles = 10; static const int _maxLayoutCycles = 10;
...@@ -1342,6 +1332,17 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat ...@@ -1342,6 +1332,17 @@ class RenderViewport extends RenderViewportBase<SliverPhysicalContainerParentDat
@override @override
void performLayout() { void performLayout() {
// Ignore the return value of applyViewportDimension because we are
// doing a layout regardless.
switch (axis) {
case Axis.vertical:
offset.applyViewportDimension(size.height);
break;
case Axis.horizontal:
offset.applyViewportDimension(size.width);
break;
}
if (center == null) { if (center == null) {
assert(firstChild == null); assert(firstChild == null);
_minScrollExtent = 0.0; _minScrollExtent = 0.0;
......
...@@ -395,6 +395,9 @@ class _PagePosition extends ScrollPositionWithSingleContext implements PageMetri ...@@ -395,6 +395,9 @@ class _PagePosition extends ScrollPositionWithSingleContext implements PageMetri
@override @override
bool applyViewportDimension(double viewportDimension) { bool applyViewportDimension(double viewportDimension) {
final double oldViewportDimensions = this.viewportDimension; final double oldViewportDimensions = this.viewportDimension;
if (viewportDimension == oldViewportDimensions) {
return true;
}
final bool result = super.applyViewportDimension(viewportDimension); final bool result = super.applyViewportDimension(viewportDimension);
final double oldPixels = pixels; final double oldPixels = pixels;
final double page = (oldPixels == null || oldViewportDimensions == 0.0) ? _pageToUseOnStartup : getPageFromPixels(oldPixels, oldViewportDimensions); final double page = (oldPixels == null || oldViewportDimensions == 0.0) ? _pageToUseOnStartup : getPageFromPixels(oldPixels, oldViewportDimensions);
......
...@@ -537,4 +537,42 @@ void main() { ...@@ -537,4 +537,42 @@ void main() {
)); ));
handle.dispose(); handle.dispose();
}); });
testWidgets('Updates viewport dimensions when scroll direction changes', (WidgetTester tester) async {
// Regression test for https://github.com/flutter/flutter/issues/43380.
final ScrollController controller = ScrollController();
Widget buildListView({@required Axis scrollDirection}) {
assert(scrollDirection != null);
return Directionality(
textDirection: TextDirection.ltr,
child: Center(
child: Container(
height: 200.0,
width: 100.0,
child: ListView(
controller: controller,
scrollDirection: scrollDirection,
itemExtent: 50.0,
children: <Widget>[
Container(
height: 50.0,
width: 50.0,
),
],
),
),
),
);
}
await tester.pumpWidget(buildListView(scrollDirection: Axis.horizontal));
expect(controller.position.viewportDimension, 100.0);
await tester.pumpWidget(buildListView(scrollDirection: Axis.vertical));
expect(controller.position.viewportDimension, 200.0);
await tester.pumpWidget(buildListView(scrollDirection: Axis.horizontal));
expect(controller.position.viewportDimension, 100.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