Unverified Commit ba92cbed authored by xubaolin's avatar xubaolin Committed by GitHub

fix SingleChildScrollView clip bug (#63054)

parent 94319c7a
......@@ -568,7 +568,10 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
bool _shouldClipAtPaintOffset(Offset paintOffset) {
assert(child != null);
return paintOffset < Offset.zero || !(Offset.zero & size).contains((paintOffset & child.size).bottomRight);
return paintOffset.dx < 0 ||
paintOffset.dy < 0 ||
paintOffset.dx + child.size.width > size.width ||
paintOffset.dy + child.size.height > size.height;
}
@override
......
......@@ -40,6 +40,69 @@ class TestScrollController extends ScrollController {
}
void main() {
testWidgets('SingleChildScrollView overflow and clipRect test', (WidgetTester tester) async {
// the test widowSize is Size(800.0, 600.0)
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Container(height: 600.0,)
)
)
);
// 1st, check that the render object has received the default clip behavior.
final dynamic renderObject = tester.allRenderObjects.where((RenderObject o) => o.runtimeType.toString() == '_RenderSingleChildViewport').first;
expect(renderObject.clipBehavior, equals(Clip.hardEdge));
// 2nd, height == widow.height test: check that the painting context does not call pushClipRect .
TestClipPaintingContext context = TestClipPaintingContext();
renderObject.paint(context, Offset.zero);
expect(context.clipBehavior, equals(Clip.none));
// 3rd, height overflow test: check that the painting context call pushClipRect.
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Container(height: 600.1,)
)
)
);
renderObject.paint(context, Offset.zero);
expect(context.clipBehavior, equals(Clip.hardEdge));
// 4th, width == widow.width test: check that the painting context do not call pushClipRect.
context = TestClipPaintingContext();
expect(context.clipBehavior, equals(Clip.none)); // initial value
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(width: 800.0,)
)
)
);
renderObject.paint(context, Offset.zero);
expect(context.clipBehavior, equals(Clip.none));
// 5th, width overflow test: check that the painting context call pushClipRect.
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Container(width: 800.1,)
)
)
);
renderObject.paint(context, Offset.zero);
expect(context.clipBehavior, equals(Clip.hardEdge));
});
testWidgets('SingleChildScrollView respects clipBehavior', (WidgetTester tester) async {
await tester.pumpWidget(SingleChildScrollView(child: Container(height: 2000.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