Override getClipBounds to expose overflow clipping to the framework#56606
Closed
fabriziocucci wants to merge 2 commits intofacebook:mainfrom
Closed
Override getClipBounds to expose overflow clipping to the framework#56606fabriziocucci wants to merge 2 commits intofacebook:mainfrom
fabriziocucci wants to merge 2 commits intofacebook:mainfrom
Conversation
|
@fabriziocucci has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102353840. |
17be930 to
6db021e
Compare
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
6db021e to
78c6c70
Compare
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
78c6c70 to
7083a57
Compare
|
This pull request has been merged in 2c208f8. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Override
getClipBounds()on ReactViewGroup to return the padding box rect whenoverflowis hidden or scroll, gated behind thesyncAndroidClipBoundsWithOverflowfeature flag.
This exposes the view's clipping behavior to the Android framework via the standard
View.getClipBounds()API:getClipBounds(Rect): Booleanreturnstrueand populates the rect with thepadding box when overflow is hidden/scroll, or
falsewhen overflow is visiblegetClipBounds(): Rect?returns the padding box rect ornullrespectivelyThis allows framework-level systems to inspect a view and determine whether it clips
its children by checking
getClipBounds() != null, and to obtain the actual clippingregion for
getGlobalVisibleRect()calculations.Why not
setClipBounds()?An alternative approach would be to call
View.setClipBounds(Rect)which sets themClipBoundsfield directly. This has the advantage of being picked up by AOSP'sViewGroup.getChildVisibleRect()(which readsmClipBoundsvia direct field accessrather than calling
getClipBounds()). However,setClipBounds()also propagatesthe clip rect to the RenderNode via
mRenderNode.setClipRect(), which clips theview'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 systemsquery 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