Reland"Make RenderSliverGrid more accurately report overflow" (#107329)

This commit is contained in:
Dan Field 2022-07-08 15:07:06 -07:00 committed by GitHub
parent f614c59702
commit 3f173357c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 5 deletions

View File

@ -658,7 +658,6 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
leadingScrollOffset: leadingScrollOffset,
trailingScrollOffset: trailingScrollOffset,
);
final double paintExtent = calculatePaintOffset(
constraints,
from: math.min(constraints.scrollOffset, leadingScrollOffset),
@ -675,8 +674,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {
paintExtent: paintExtent,
maxPaintExtent: estimatedTotalExtent,
cacheExtent: cacheExtent,
// Conservative to avoid complexity.
hasVisualOverflow: true,
hasVisualOverflow: estimatedTotalExtent > paintExtent || constraints.scrollOffset > 0.0 || constraints.overlap != 0.0,
);
// We may have started the layout while scrolled to the end, which

View File

@ -645,13 +645,50 @@ void main() {
expect(counters[4], 2);
});
testWidgets('GridView does not report visual overflow unnecessarily', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
children: <Widget>[
Container(height: 200.0),
],
),
),
);
// 1st, check that the render object has received the default clip behavior.
final RenderViewport renderObject = tester.allRenderObjects.whereType<RenderViewport>().first;
expect(renderObject.clipBehavior, equals(Clip.hardEdge));
// The context will get Clip.none because there is no actual visual overflow.
final TestClipPaintingContext context = TestClipPaintingContext();
renderObject.paint(context, Offset.zero);
expect(context.clipBehavior, equals(Clip.none));
});
testWidgets('GridView respects clipBehavior', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
children: <Widget>[Container(height: 2000.0)],
children: <Widget>[
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
],
),
),
);
@ -672,7 +709,21 @@ void main() {
child: GridView(
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
clipBehavior: Clip.antiAlias,
children: <Widget>[Container(height: 2000.0)],
children: <Widget>[
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
Container(height: 2000.0),
],
),
),
);