fix(android): crash when setting a percentage borderRadius on Image - #57795
fix(android): crash when setting a percentage borderRadius on Image#57795sbaiahmed1 wants to merge 1 commit into
Conversation
|
Hi @sbaiahmed1! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Percentage border radii arrive from JS as strings ('50%'), but
ReactImageManager's borderRadius @ReactPropGroup setter still typed the
prop as Float, so the reflection-based property updater crashed with
"java.lang.String cannot be cast to java.lang.Double" under the new
architecture.
Accept a Dynamic and parse it with LengthPercentage.setFromDynamic,
mirroring the migration ReactViewManager received in 0.75. The Float
overload is kept as a deprecated pass-through for backward
compatibility. Rendering needs no changes since the manager already
delegates to BackgroundStyleApplicator, which resolves percentages.
Fixes react#53977
Changelog:
[ANDROID] [FIXED] - Fix crash when setting a percentage borderRadius on Image
17d1d2a to
dfca164
Compare
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
|
@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this in D114576433. |
Summary
Fixes #53977
Setting a percentage border radius on
<Image>(e.g.borderRadius: '50%') crashes Android withjava.lang.String cannot be cast to java.lang.Double. Percentage radii arrive from JS as strings, butReactImageManager'sborderRadius@ReactPropGroupsetter was still typed asFloat, so the reflection-based property updater (ViewManagersPropertyCache) failed on the cast. (The crash reproduces on any API level, not just API 35 as reported.)This applies the same migration
ReactViewManagerreceived in 0.75: the setter now accepts aDynamicand parses it withLengthPercentage.setFromDynamic, which handles both numbers and'NN%'strings (invalid values degrade to a warning + null instead of a crash). The oldFloatoverload is kept as a deprecated pass-through so existing subclasses stay source/binary compatible, mirroring theReactViewManagerprecedent, and the public API dump is updated accordingly.No rendering changes are needed: the manager already delegates to
BackgroundStyleApplicator, which resolvesPERCENTlength values against the view bounds.Note: the same
Float-typed setter still exists inReactTextViewManager,PreparedLayoutTextViewManager,ReactTextInputManager,ReactScrollViewManager, andReactHorizontalScrollViewManager, so<Text>,<TextInput>, and<ScrollView>crash the same way. I kept this PR scoped to the reported Image crash and I'm happy to follow up with the same fix for the others.Changelog:
[ANDROID] [FIXED] - Fix crash when setting a percentage borderRadius on Image
Test Plan
testBorderRadiustoReactImagePropertyTest, driving the real crash path (ViewManager.updateProperties→ reflection prop updater) with'50%', a plain number, a per-corner percentage, and null, asserting the resolvedLengthPercentageon the view. Without the fix it fails with the exact exception from the issue; with the fix the suite passes (9/9):./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests "com.facebook.react.views.image.ReactImagePropertyTest"borderRadius: '50%'image to rn-tester's Image → Border Radius example. Verified on a Pixel 9 Pro emulator (API 36) with rn-tester built from source: the screen that previously redboxed on mount now renders, with the percentage image drawn as a circle and the existing numeric-radius images unchanged (screenshot below).Screenshot