Commit ef91012
committed
fix(android): preserve border-radius across transparent → opaque backgroundColor transition
Summary:
On Android, a View whose backgroundColor starts as transparent and
later transitions to an opaque color loses its border-radius clipping
and renders as a rectangle. Reported in facebook#52415; iOS is unaffected.
Root cause: `setBorderRadius` only eagerly creates an inner
`BackgroundDrawable` for `ImageView`. For a regular `View` with a
transparent backgroundColor, the composite background drawable ends
up with no inner `BackgroundDrawable` at first. When the color later
becomes opaque, `setBackgroundColor` -> `ensureBackgroundDrawable`
constructs a fresh `BackgroundDrawable` and swaps `view.background`
with a new `CompositeBackgroundDrawable` via `withNewBackground`.
The freshly constructed drawable starts with 0x0 bounds, and on the
first draw the computed path is a zero-radius rectangle.
Fix: always eagerly create the inner `BackgroundDrawable` inside
`setBorderRadius`, not only for `ImageView`. This way subsequent
`setBackgroundColor` calls mutate the existing drawable in place,
avoiding the `view.background` replacement path where bounds/path are
not yet primed.
Changelog:
[ANDROID] [FIXED] - View with borderRadius renders as rectangle after transparent → opaque backgroundColor transition
Test Plan:
Added an RNTester example under Border > "Border radius with transparent → opaque background" that starts with a transparent 50x50 box with borderRadius: 25 and toggles to red on tap. Without this change the opaque state renders as a square on Android; with the fix it renders as a circle. iOS rendering is unchanged.1 parent 24b51db commit ef91012
2 files changed
Lines changed: 48 additions & 3 deletions
File tree
- packages
- react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager
- rn-tester/js/examples/Border
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
215 | | - | |
216 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
217 | 222 | | |
218 | 223 | | |
219 | 224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
| 25 | + | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| |||
622 | 625 | | |
623 | 626 | | |
624 | 627 | | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
625 | 638 | | |
626 | 639 | | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
0 commit comments