Unverified Commit 5fd9ef42 authored by Tae Hyung Kim's avatar Tae Hyung Kim Committed by GitHub

Fix SliverPersistentHeader interactions with SliverCrossAxisGroup (#127338)

This PR fixes `SliverCrossAxisGroup` so that once we calculate the total `scrollExtent` of the `SliverCrossAxisGroup`, we ensure that any child sliver is not painted outside of the "scroll extent" of the sliver group.

https://github.com/flutter/flutter/assets/2004742/670dc6f9-a3c6-4bcc-85d3-576cf7f33c6a

https://github.com/flutter/flutter/assets/2004742/0c9cd951-c133-4a8b-9e5e-89d0a69a4f59

Fixes #126958.
Fixes #126957.
parent 25360aed
...@@ -76,7 +76,6 @@ class RenderSliverCrossAxisGroup extends RenderSliver with ContainerRenderObject ...@@ -76,7 +76,6 @@ class RenderSliverCrossAxisGroup extends RenderSliver with ContainerRenderObject
final double extentPerFlexValue = remainingExtent / totalFlex; final double extentPerFlexValue = remainingExtent / totalFlex;
child = firstChild; child = firstChild;
double offset = 0.0;
// At this point, all slivers with constrained cross axis should already be laid out. // At this point, all slivers with constrained cross axis should already be laid out.
// Layout the rest and keep track of the child geometry with greatest scrollExtent. // Layout the rest and keep track of the child geometry with greatest scrollExtent.
...@@ -94,22 +93,35 @@ class RenderSliverCrossAxisGroup extends RenderSliver with ContainerRenderObject ...@@ -94,22 +93,35 @@ class RenderSliverCrossAxisGroup extends RenderSliver with ContainerRenderObject
} else { } else {
childExtent = child.geometry!.crossAxisExtent!; childExtent = child.geometry!.crossAxisExtent!;
} }
final SliverGeometry childLayoutGeometry = child.geometry!;
if (geometry!.scrollExtent < childLayoutGeometry.scrollExtent) {
geometry = childLayoutGeometry;
}
child = childAfter(child);
}
// Go back and correct any slivers using a negative paint offset if it tries
// to paint outside the bounds of the sliver group.
child = firstChild;
double offset = 0.0;
while (child != null) {
final SliverPhysicalParentData childParentData = child.parentData! as SliverPhysicalParentData;
final SliverGeometry childLayoutGeometry = child.geometry!;
final double remainingExtent = geometry!.scrollExtent - constraints.scrollOffset;
final double paintCorrection = childLayoutGeometry.paintExtent > remainingExtent
? childLayoutGeometry.paintExtent - remainingExtent
: 0.0;
final double childExtent = child.geometry!.crossAxisExtent ?? extentPerFlexValue * (childParentData.crossAxisFlex ?? 0);
// Set child parent data. // Set child parent data.
switch (constraints.axis) { switch (constraints.axis) {
case Axis.vertical: case Axis.vertical:
childParentData.paintOffset = Offset(offset, 0.0); childParentData.paintOffset = Offset(offset, -paintCorrection);
case Axis.horizontal: case Axis.horizontal:
childParentData.paintOffset = Offset(0.0, offset); childParentData.paintOffset = Offset(-paintCorrection, offset);
} }
offset += childExtent; offset += childExtent;
if (geometry!.scrollExtent < child.geometry!.scrollExtent) {
geometry = child.geometry;
}
child = childAfter(child); child = childAfter(child);
} }
// Set the geometry with the proper crossAxisExtent.
geometry = geometry!.copyWith(crossAxisExtent: constraints.crossAxisExtent);
} }
@override @override
......
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