Skip to content

Commit e40572b

Browse files
fix: keep BackgroundDrawable creation lazy, propagate bounds instead
Revert the eager ensureBackgroundDrawable call inside setBorderRadius so views with borderRadius but no backgroundColor don't carry an always-allocated drawable. Instead, fix the root timing issue at the actual site of the bug: when ensureBackgroundDrawable lazily constructs a new BackgroundDrawable + new composite, carry the existing composite's bounds over before assigning view.background. This primes the new drawable with the view's real dimensions so its first draw computes the border-radius path correctly, without imposing cost on views that never hit this path. Test Plan: same RNTester repro (UI > Border > "Border radius with transparent -> opaque background").
1 parent ef91012 commit e40572b

1 file changed

Lines changed: 13 additions & 9 deletions

File tree

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/BackgroundStyleApplicator.kt

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,9 @@ public object BackgroundStyleApplicator {
211211
compositeBackgroundDrawable.borderRadius ?: BorderRadiusStyle()
212212
compositeBackgroundDrawable.borderRadius?.set(corner, radius)
213213

214-
// Eagerly create the BackgroundDrawable so subsequent backgroundColor
215-
// changes can mutate the existing drawable in place instead of
216-
// replacing view.background with a freshly-constructed composite whose
217-
// inner BackgroundDrawable has 0x0 bounds on first draw. Without this,
218-
// a backgroundColor transition from transparent to opaque leaves the
219-
// view rendering as a rectangle even though borderRadius is set.
220-
// See https://github.com/facebook/react-native/issues/52415.
221-
ensureBackgroundDrawable(view)
214+
if (view is ImageView) {
215+
ensureBackgroundDrawable(view)
216+
}
222217
compositeBackgroundDrawable.background?.borderRadius = compositeBackgroundDrawable.borderRadius
223218
compositeBackgroundDrawable.backgroundImage?.borderRadius =
224219
compositeBackgroundDrawable.borderRadius
@@ -642,7 +637,16 @@ public object BackgroundStyleApplicator {
642637
compositeBackgroundDrawable.borderRadius,
643638
compositeBackgroundDrawable.borderInsets,
644639
)
645-
view.background = compositeBackgroundDrawable.withNewBackground(background)
640+
val newComposite = compositeBackgroundDrawable.withNewBackground(background)
641+
// Carry the existing composite's bounds over so the freshly
642+
// constructed BackgroundDrawable has the view's real dimensions when
643+
// it first draws. Without this, setBackgroundColor called after the
644+
// view has been laid out (e.g. a transparent -> opaque transition)
645+
// would leave the drawable with 0x0 bounds on its first draw and the
646+
// border-radius path would collapse to a rectangle.
647+
// See https://github.com/facebook/react-native/issues/52415.
648+
newComposite.bounds = compositeBackgroundDrawable.bounds
649+
view.background = newComposite
646650
background
647651
}
648652
}

0 commit comments

Comments
 (0)