Skip to content

Commit

Permalink
Make _RenderCustomClip respect clipBehavior (#103748)
Browse files Browse the repository at this point in the history
  • Loading branch information
dnfield authored May 14, 2022
1 parent 8c4e92c commit 4f96419
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/flutter/lib/src/rendering/proxy_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1404,8 +1404,15 @@ abstract class _RenderCustomClip<T> extends RenderProxyBox {
}

@override
Rect describeApproximatePaintClip(RenderObject child) {
return _clipper?.getApproximateClipRect(size) ?? Offset.zero & size;
Rect? describeApproximatePaintClip(RenderObject child) {
switch (clipBehavior) {
case Clip.none:
return null;
case Clip.hardEdge:
case Clip.antiAlias:
case Clip.antiAliasWithSaveLayer:
return _clipper?.getApproximateClipRect(size) ?? Offset.zero & size;
}
}

Paint? _debugPaint;
Expand Down
25 changes: 25 additions & 0 deletions packages/flutter/test/rendering/proxy_box_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,31 @@ void main() {

expect(() => pumpFrame(phase: EnginePhase.composite), returnsNormally);
});

test('RenderCustomClip extenders respect clipBehavior when asked to describeApproximateClip', () {
final RenderBox child = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 200, height: 200));
final RenderClipRect renderClipRect = RenderClipRect(clipBehavior: Clip.none, child: child);
layout(renderClipRect);
expect(
renderClipRect.describeApproximatePaintClip(child),
null,
);
renderClipRect.clipBehavior = Clip.hardEdge;
expect(
renderClipRect.describeApproximatePaintClip(child),
Offset.zero & renderClipRect.size,
);
renderClipRect.clipBehavior = Clip.antiAlias;
expect(
renderClipRect.describeApproximatePaintClip(child),
Offset.zero & renderClipRect.size,
);
renderClipRect.clipBehavior = Clip.antiAliasWithSaveLayer;
expect(
renderClipRect.describeApproximatePaintClip(child),
Offset.zero & renderClipRect.size,
);
});
}

class _TestRectClipper extends CustomClipper<Rect> {
Expand Down

0 comments on commit 4f96419

Please sign in to comment.