Unverified Commit 9e0ad4c6 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Fix paint offset in reverse for 2D (#128724)

Fixes https://github.com/flutter/flutter/issues/128723

The paint offset was incorrectly being computed when one or both axis was in the reverse direction. Instead of using the paint extent, the child's size should be used.
parent 9af6bae6
......@@ -1149,7 +1149,6 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
childParentData.paintOffset = computeAbsolutePaintOffsetFor(
child,
layoutOffset: childParentData.layoutOffset!,
paintExtent: childParentData._paintExtent!,
);
// If the child is partially visible, or not visible at all, there is
// visual overflow.
......@@ -1243,14 +1242,15 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
Offset computeAbsolutePaintOffsetFor(
RenderBox child, {
required Offset layoutOffset,
required Size paintExtent,
}) {
assert(hasSize); // this is only usable once we have a size
// This is only usable once we have sizes.
assert(hasSize);
assert(child.hasSize);
final double xOffset;
final double yOffset;
switch (verticalAxisDirection) {
case AxisDirection.up:
yOffset = viewportDimension.height - (layoutOffset.dy + paintExtent.height);
yOffset = viewportDimension.height - (layoutOffset.dy + child.size.height);
case AxisDirection.down:
yOffset = layoutOffset.dy;
case AxisDirection.right:
......@@ -1261,7 +1261,7 @@ abstract class RenderTwoDimensionalViewport extends RenderBox implements RenderA
case AxisDirection.right:
xOffset = layoutOffset.dx;
case AxisDirection.left:
xOffset = viewportDimension.width - (layoutOffset.dx + paintExtent.width);
xOffset = viewportDimension.width - (layoutOffset.dx + child.size.width);
case AxisDirection.up:
case AxisDirection.down:
throw Exception('This should not happen');
......
......@@ -1189,7 +1189,8 @@ void main() {
}, variant: TargetPlatformVariant.all());
testWidgets('sets up parent data', (WidgetTester tester) async {
// Also tests computeChildPaintOffset & computeChildPaintExtent
// Also tests computeAbsolutePaintOffsetFor & computeChildPaintExtent
// Regression test for https://github.com/flutter/flutter/issues/128723
final Map<ChildVicinity, UniqueKey> childKeys = <ChildVicinity, UniqueKey>{};
final TwoDimensionalChildBuilderDelegate delegate = TwoDimensionalChildBuilderDelegate(
maxXIndex: 5,
......@@ -1250,7 +1251,7 @@ void main() {
childParentData = parentDataOf(viewport.lastChild!);
expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5));
expect(childParentData.isVisible, isFalse);
expect(childParentData.paintOffset, const Offset(1000.0, -400.0));
expect(childParentData.paintOffset, const Offset(1000.0, -600.0));
expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0));
// - horizontal reverse
......@@ -1271,7 +1272,7 @@ void main() {
childParentData = parentDataOf(viewport.lastChild!);
expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5));
expect(childParentData.isVisible, isFalse);
expect(childParentData.paintOffset, const Offset(-200.0, 1000.0));
expect(childParentData.paintOffset, const Offset(-400.0, 1000.0));
expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0));
// - both reverse
......@@ -1293,7 +1294,7 @@ void main() {
childParentData = parentDataOf(viewport.lastChild!);
expect(childParentData.vicinity, const ChildVicinity(xIndex: 5, yIndex: 5));
expect(childParentData.isVisible, isFalse);
expect(childParentData.paintOffset, const Offset(-200.0, -400.0));
expect(childParentData.paintOffset, const Offset(-400.0, -600.0));
expect(childParentData.layoutOffset, const Offset(1000.0, 1000.0));
// Change the scroll positions to test partially visible.
......
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