Skip to content

Override getClipBounds to expose overflow clipping to the framework#56606

Closed
fabriziocucci wants to merge 2 commits intofacebook:mainfrom
fabriziocucci:export-D102353840
Closed

Override getClipBounds to expose overflow clipping to the framework#56606
fabriziocucci wants to merge 2 commits intofacebook:mainfrom
fabriziocucci:export-D102353840

Conversation

@fabriziocucci
Copy link
Copy Markdown
Contributor

@fabriziocucci fabriziocucci commented Apr 24, 2026

Summary:
Override getClipBounds() on ReactViewGroup to return the padding box rect when
overflow is hidden or scroll, gated behind the syncAndroidClipBoundsWithOverflow
feature flag.

This exposes the view's clipping behavior to the Android framework via the standard
View.getClipBounds() API:

  • getClipBounds(Rect): Boolean returns true and populates the rect with the
    padding box when overflow is hidden/scroll, or false when overflow is visible
  • getClipBounds(): Rect? returns the padding box rect or null respectively

This allows framework-level systems to inspect a view and determine whether it clips
its children by checking getClipBounds() != null, and to obtain the actual clipping
region for getGlobalVisibleRect() calculations.

Why not setClipBounds()?

An alternative approach would be to call View.setClipBounds(Rect) which sets the
mClipBounds field directly. This has the advantage of being picked up by AOSP's
ViewGroup.getChildVisibleRect() (which reads mClipBounds via direct field access
rather than calling getClipBounds()). However, setClipBounds() also propagates
the clip rect to the RenderNode via mRenderNode.setClipRect(), which clips the
view's own rendering — including its borders. It also requires maintaining a Rect
that must be kept in sync across size changes, border width changes, and overflow
changes.

For now, the getClipBounds() override is sufficient because harvesting systems
query the method rather than the field. If we find that AOSP's field-based path is
also needed, we can switch to setClipBounds() in the future.

Adds BackgroundStyleApplicator.getPaddingBoxRect() (internal via buck friend_paths)
which computes the padding box (view bounds minus border insets) reusing the same
border inset resolution logic as clipToPaddingBox().

Changelog: [Internal]

Reviewed By: twasilczyk, javache

Differential Revision: D102353840

@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Apr 24, 2026

@fabriziocucci has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102353840.

@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 Apr 24, 2026
fabriziocucci added a commit to fabriziocucci/react-native that referenced this pull request Apr 24, 2026
…acebook#56606)

Summary:
Pull Request resolved: facebook#56606

Override `getClipBounds()` on ReactViewGroup to return the padding box rect when
`overflow` is hidden or scroll, gated behind the `syncAndroidClipBoundsWithOverflow`
feature flag. This allows systems that query `View.getClipBounds()` to determine
that a view clips its children, without the heavyweight side effects of
`setClipBounds()`.

Unlike `setClipBounds()`, this approach:
- Does not clip the view's own rendering at the RenderNode level (no border clipping)
- Does not require maintaining a Rect across size/border/overflow changes
- Computes the padding box rect lazily, only when queried

Adds `BackgroundStyleApplicator.getPaddingBoxRect()` (internal) which computes the
padding box (view bounds minus border insets) reusing the same border inset
resolution logic as `clipToPaddingBox()`.

Changelog: [Internal]

Differential Revision: D102353840
@meta-codesync meta-codesync Bot changed the title Override getClipBounds to expose overflow clipping to the framework Override getClipBounds to expose overflow clipping to the framework (#56606) Apr 24, 2026
Summary:
Add a new feature flag to gate overriding getClipBounds on Android views to return
the padding box when overflow is hidden. This communicates the view's clipping
region to the Android framework for correct getGlobalVisibleRect calculations
(T253147322, T263753590).

Changelog: [Internal]

Reviewed By: twasilczyk

Differential Revision: D102353841
Summary:
Override `getClipBounds()` on ReactViewGroup to return the padding box rect when
`overflow` is hidden or scroll, gated behind the `syncAndroidClipBoundsWithOverflow`
feature flag.

This exposes the view's clipping behavior to the Android framework via the standard
`View.getClipBounds()` API:
- `getClipBounds(Rect): Boolean` returns `true` and populates the rect with the
  padding box when overflow is hidden/scroll, or `false` when overflow is visible
- `getClipBounds(): Rect?` returns the padding box rect or `null` respectively

This allows framework-level systems to inspect a view and determine whether it clips
its children by checking `getClipBounds() != null`, and to obtain the actual clipping
region for `getGlobalVisibleRect()` calculations.

## Why not `setClipBounds()`?

An alternative approach would be to call `View.setClipBounds(Rect)` which sets the
`mClipBounds` field directly. This has the advantage of being picked up by AOSP's
`ViewGroup.getChildVisibleRect()` (which reads `mClipBounds` via direct field access
rather than calling `getClipBounds()`). However, `setClipBounds()` also propagates
the clip rect to the RenderNode via `mRenderNode.setClipRect()`, which clips the
view's own rendering — including its borders. It also requires maintaining a Rect
that must be kept in sync across size changes, border width changes, and overflow
changes.

For now, the `getClipBounds()` override is sufficient because harvesting systems
query the method rather than the field. If we find that AOSP's field-based path is
also needed, we can switch to `setClipBounds()` in the future.

Adds `BackgroundStyleApplicator.getPaddingBoxRect()` (internal via buck friend_paths)
which computes the padding box (view bounds minus border insets) reusing the same
border inset resolution logic as `clipToPaddingBox()`.

Changelog: [Internal]

Reviewed By: twasilczyk, javache

Differential Revision: D102353840
@meta-codesync meta-codesync Bot changed the title Override getClipBounds to expose overflow clipping to the framework (#56606) Override getClipBounds to expose overflow clipping to the framework Apr 27, 2026
@meta-codesync meta-codesync Bot closed this in 2c208f8 Apr 27, 2026
@facebook-github-tools facebook-github-tools Bot added the Merged This PR has been merged. label Apr 27, 2026
@meta-codesync
Copy link
Copy Markdown

meta-codesync Bot commented Apr 27, 2026

This pull request has been merged in 2c208f8.

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. fb-exported Merged This PR has been merged. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant