Commit 2c208f8
Override getClipBounds to expose overflow clipping to the framework (#56606)
Summary:
Pull Request resolved: #56606
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
fbshipit-source-id: fe1d52e3c000ba1b5e2d21eac75928be24a866451 parent 497d9c1 commit 2c208f8
3 files changed
Lines changed: 65 additions & 0 deletions
File tree
- packages/react-native/ReactAndroid
- api
- src/main/java/com/facebook/react
- uimanager
- views/view
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6457 | 6457 | | |
6458 | 6458 | | |
6459 | 6459 | | |
| 6460 | + | |
| 6461 | + | |
6460 | 6462 | | |
6461 | 6463 | | |
6462 | 6464 | | |
| |||
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
465 | 465 | | |
466 | 466 | | |
467 | 467 | | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
468 | 497 | | |
469 | 498 | | |
470 | 499 | | |
| |||
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
| |||
820 | 821 | | |
821 | 822 | | |
822 | 823 | | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
823 | 857 | | |
824 | 858 | | |
825 | 859 | | |
| |||
0 commit comments