Unverified Commit e581435d authored by liyuqian's avatar liyuqian Committed by GitHub

Reland: Skip painting hidden children of a sliver list (#18539)

* Revert "manual rollback of of 18530 (#18531)"

This reverts commit 3f79f8cb.

* Fix the offset calculation

* Add a unit test
parent 9f8a70be
...@@ -524,7 +524,13 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver ...@@ -524,7 +524,13 @@ abstract class RenderSliverMultiBoxAdaptor extends RenderSliver
); );
if (addExtent) if (addExtent)
childOffset += mainAxisUnit * paintExtentOf(child); childOffset += mainAxisUnit * paintExtentOf(child);
context.paintChild(child, childOffset);
// If the child's visible interval (mainAxisLowerBound, mainAxisLowerBound + paintExtentOf(child))
// does not intersect the paint extent interval (0, constraints.remainingPaintExtent), it's hidden.
final double mainAxisLowerBound = mainAxisDelta + (addExtent ? paintExtentOf(child) : 0);
if (mainAxisLowerBound < constraints.remainingPaintExtent && mainAxisLowerBound + paintExtentOf(child) > 0)
context.paintChild(child, childOffset);
child = childAfter(child); child = childAfter(child);
} }
} }
......
...@@ -307,14 +307,14 @@ void main() { ...@@ -307,14 +307,14 @@ void main() {
' │ constraints: BoxConstraints(w=800.0, h=400.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
' │ size: Size(800.0, 400.0)\n' ' │ size: Size(800.0, 400.0)\n'
' │\n' ' │\n'
' └─child with index 2: RenderLimitedBox#00000\n' ' └─child with index 2: RenderLimitedBox#00000 NEEDS-PAINT\n'
' │ parentData: index=2; layoutOffset=800.0\n' ' │ parentData: index=2; layoutOffset=800.0\n'
' │ constraints: BoxConstraints(w=800.0, h=400.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
' │ size: Size(800.0, 400.0)\n' ' │ size: Size(800.0, 400.0)\n'
' │ maxWidth: 400.0\n' ' │ maxWidth: 400.0\n'
' │ maxHeight: 400.0\n' ' │ maxHeight: 400.0\n'
' │\n' ' │\n'
' └─child: RenderCustomPaint#00000\n' ' └─child: RenderCustomPaint#00000 NEEDS-PAINT\n'
' parentData: <none> (can use size)\n' ' parentData: <none> (can use size)\n'
' constraints: BoxConstraints(w=800.0, h=400.0)\n' ' constraints: BoxConstraints(w=800.0, h=400.0)\n'
' size: Size(800.0, 400.0)\n' ' size: Size(800.0, 400.0)\n'
...@@ -412,14 +412,14 @@ void main() { ...@@ -412,14 +412,14 @@ void main() {
' │ cacheExtent: 1100.0)\n' ' │ cacheExtent: 1100.0)\n'
' │ currently live children: 4 to 7\n' ' │ currently live children: 4 to 7\n'
' │\n' ' │\n'
' ├─child with index 4: RenderLimitedBox#00000\n' ' ├─child with index 4: RenderLimitedBox#00000 NEEDS-PAINT\n'
' │ │ parentData: index=4; layoutOffset=1600.0\n' ' │ │ parentData: index=4; layoutOffset=1600.0\n'
' │ │ constraints: BoxConstraints(w=800.0, h=400.0)\n' ' │ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
' │ │ size: Size(800.0, 400.0)\n' ' │ │ size: Size(800.0, 400.0)\n'
' │ │ maxWidth: 400.0\n' ' │ │ maxWidth: 400.0\n'
' │ │ maxHeight: 400.0\n' ' │ │ maxHeight: 400.0\n'
' │ │\n' ' │ │\n'
' │ └─child: RenderCustomPaint#00000\n' ' │ └─child: RenderCustomPaint#00000 NEEDS-PAINT\n'
' │ parentData: <none> (can use size)\n' ' │ parentData: <none> (can use size)\n'
' │ constraints: BoxConstraints(w=800.0, h=400.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
' │ size: Size(800.0, 400.0)\n' ' │ size: Size(800.0, 400.0)\n'
...@@ -448,14 +448,14 @@ void main() { ...@@ -448,14 +448,14 @@ void main() {
' │ constraints: BoxConstraints(w=800.0, h=400.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
' │ size: Size(800.0, 400.0)\n' ' │ size: Size(800.0, 400.0)\n'
' │\n' ' │\n'
' ├─child with index 7: RenderLimitedBox#00000\n' ' ├─child with index 7: RenderLimitedBox#00000 NEEDS-PAINT\n'
' ╎ │ parentData: index=7; layoutOffset=2800.0\n' ' ╎ │ parentData: index=7; layoutOffset=2800.0\n'
' ╎ │ constraints: BoxConstraints(w=800.0, h=400.0)\n' ' ╎ │ constraints: BoxConstraints(w=800.0, h=400.0)\n'
' ╎ │ size: Size(800.0, 400.0)\n' ' ╎ │ size: Size(800.0, 400.0)\n'
' ╎ │ maxWidth: 400.0\n' ' ╎ │ maxWidth: 400.0\n'
' ╎ │ maxHeight: 400.0\n' ' ╎ │ maxHeight: 400.0\n'
' ╎ │\n' ' ╎ │\n'
' ╎ └─child: RenderCustomPaint#00000\n' ' ╎ └─child: RenderCustomPaint#00000 NEEDS-PAINT\n'
' ╎ parentData: <none> (can use size)\n' ' ╎ parentData: <none> (can use size)\n'
' ╎ constraints: BoxConstraints(w=800.0, h=400.0)\n' ' ╎ constraints: BoxConstraints(w=800.0, h=400.0)\n'
' ╎ size: Size(800.0, 400.0)\n' ' ╎ size: Size(800.0, 400.0)\n'
......
...@@ -459,5 +459,36 @@ void main() { ...@@ -459,5 +459,36 @@ void main() {
final RenderSliverList list = tester.renderObject(find.byType(SliverList)); final RenderSliverList list = tester.renderObject(find.byType(SliverList));
expect(list, paintsExactlyCountTimes(#drawParagraph, 2)); expect(list, paintsExactlyCountTimes(#drawParagraph, 2));
}, skip: true); });
testWidgets('ListView should paint with offset', (WidgetTester tester) async {
await tester.pumpWidget(
new MaterialApp(
home: new Scaffold(
body: new Container(
height: 500.0,
child: new CustomScrollView(
controller: new ScrollController(initialScrollOffset: 120.0),
slivers: <Widget>[
const SliverAppBar(
expandedHeight: 250.0,
),
new SliverList(
delegate: new ListView.builder(
itemExtent: 100.0,
itemCount: 100,
itemBuilder: (_, __) => new Container(
height: 40.0,
child: const Text('hey'),
)).childrenDelegate),
],
)
)
)
)
);
final RenderObject renderObject = tester.renderObject(find.byType(Scrollable));
expect(renderObject, paintsExactlyCountTimes(#drawParagraph, 10));
});
} }
...@@ -82,7 +82,7 @@ void main() { ...@@ -82,7 +82,7 @@ void main() {
' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ │ layer: OffsetLayer#00000\n' ' │ │ layer: OffsetLayer#00000\n'
' │ │ size: Size(800.0, 600.0)\n' ' │ │ size: Size(800.0, 600.0)\n'
' │ │ metrics: 75.0% useful (1 bad vs 3 good)\n' ' │ │ metrics: 66.7% useful (1 bad vs 2 good)\n'
' │ │ diagnosis: insufficient data to draw conclusion (less than five\n' ' │ │ diagnosis: insufficient data to draw conclusion (less than five\n'
' │ │ repaints)\n' ' │ │ repaints)\n'
' │ │\n' ' │ │\n'
...@@ -103,9 +103,9 @@ void main() { ...@@ -103,9 +103,9 @@ void main() {
' └─child with index 1: RenderRepaintBoundary#00000\n' ' └─child with index 1: RenderRepaintBoundary#00000\n'
' │ parentData: index=1; layoutOffset=600.0\n' ' │ parentData: index=1; layoutOffset=600.0\n'
' │ constraints: BoxConstraints(w=800.0, h=600.0)\n' ' │ constraints: BoxConstraints(w=800.0, h=600.0)\n'
' │ layer: OffsetLayer#00000\n' ' │ layer: OffsetLayer#00000 DETACHED\n'
' │ size: Size(800.0, 600.0)\n' ' │ size: Size(800.0, 600.0)\n'
' │ metrics: 75.0% useful (1 bad vs 3 good)\n' ' │ metrics: 50.0% useful (1 bad vs 1 good)\n'
' │ diagnosis: insufficient data to draw conclusion (less than five\n' ' │ diagnosis: insufficient data to draw conclusion (less than five\n'
' │ repaints)\n' ' │ repaints)\n'
' │\n' ' │\n'
......
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