Skip to content

Clip child content to non-uniform border radii - #58490

Open
robert68-code wants to merge 1 commit into
react:mainfrom
robert68-code:export-D119531761
Open

Clip child content to non-uniform border radii#58490
robert68-code wants to merge 1 commit into
react:mainfrom
robert68-code:export-D119531761

Conversation

@robert68-code

@robert68-code robert68-code commented Sep 11, 2026

Copy link
Copy Markdown

Summary:
Fixes #53877.
The Issue

Uniform Constraint: Previously, the clipping logic relied on UIKit's layer.cornerRadius property whenever the padding-box feature flag was off. This property only supports applying a single, uniform radius to all four corners of a view.

Incorrect Rendering: If a layout called for mixed radii (e.g., borderRadius: 36 36 36 0), UIKit would force all four corners to round to 36, causing intended square corners to render as rounded.

Content Spillage: Because layer.cornerRadius cannot inset a clip by an uneven border, child backgrounds would spill out of the padding box and paint directly over the parent's borders. This behavior is documented in Issue #53877.

== The change
Geometry-Based Masking: The renderer now dynamically selects the clipping mechanism based on the layout geometry. If the border radii are non-uniform, the view uses a layer.mask with a custom shape layer built from the exact per-corner radii and per-side border widths.

Optimized Uniform Routing: If the view utilizes standard uniform radii, it continues to take the cheaper, existing cornerRadius path.

Direct Image Masking: Since a UIImageView on iOS does not naturally inherit its parent's corner rounding, the new shape mask is applied directly to the image layer so it respects the same non-uniform clipping path.

Recycling Hygiene: Because direct image masks persist, new teardown logic was introduced. When a masked view is returned to the recycle pool, the custom clipping masks are cleared. This prevents recycled views from carrying leftover clipping artifacts into their next mount lifecycle.

Differential Revision: D119531761

Summary:
Fixes react#53877.
The Issue

Uniform Constraint: Previously, the clipping logic relied on UIKit's layer.cornerRadius property whenever the padding-box feature flag was off. This property only supports applying a single, uniform radius to all four corners of a view.

Incorrect Rendering: If a layout called for mixed radii (e.g., borderRadius: 36 36 36 0), UIKit would force all four corners to round to 36, causing intended square corners to render as rounded.

Content Spillage: Because layer.cornerRadius cannot inset a clip by an uneven border, child backgrounds would spill out of the padding box and paint directly over the parent's borders. This behavior is documented in Issue react#53877.

== The change
Geometry-Based Masking: The renderer now dynamically selects the clipping mechanism based on the layout geometry. If the border radii are non-uniform, the view uses a layer.mask with a custom shape layer built from the exact per-corner radii and per-side border widths.

Optimized Uniform Routing: If the view utilizes standard uniform radii, it continues to take the cheaper, existing cornerRadius path.

Direct Image Masking: Since a UIImageView on iOS does not naturally inherit its parent's corner rounding, the new shape mask is applied directly to the image layer so it respects the same non-uniform clipping path.

Recycling Hygiene: Because direct image masks persist, new teardown logic was introduced. When a masked view is returned to the recycle pool, the custom clipping masks are cleared. This prevents recycled views from carrying leftover clipping artifacts into their next mount lifecycle.

Differential Revision: D119531761
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 11, 2026
@meta-codesync

meta-codesync Bot commented Sep 11, 2026

Copy link
Copy Markdown

@robert68-code has exported this pull request. If you are a Meta employee, you can view the originating Diff in D119531761.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Overflow Hidden + Custom Border Radii does not work on iOS

1 participant