Skip to content

fix(android): crash when setting a percentage borderRadius on Image - #57795

Open
sbaiahmed1 wants to merge 1 commit into
react:mainfrom
sbaiahmed1:fix/image-percentage-border-radius
Open

fix(android): crash when setting a percentage borderRadius on Image#57795
sbaiahmed1 wants to merge 1 commit into
react:mainfrom
sbaiahmed1:fix/image-percentage-border-radius

Conversation

@sbaiahmed1

@sbaiahmed1 sbaiahmed1 commented Aug 3, 2026

Copy link
Copy Markdown

Summary

Fixes #53977

Setting a percentage border radius on <Image> (e.g. borderRadius: '50%') crashes Android with java.lang.String cannot be cast to java.lang.Double. Percentage radii arrive from JS as strings, but ReactImageManager's borderRadius @ReactPropGroup setter was still typed as Float, 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 ReactViewManager received in 0.75: the setter now accepts a Dynamic and parses it with LengthPercentage.setFromDynamic, which handles both numbers and 'NN%' strings (invalid values degrade to a warning + null instead of a crash). The old Float overload is kept as a deprecated pass-through so existing subclasses stay source/binary compatible, mirroring the ReactViewManager precedent, and the public API dump is updated accordingly.

No rendering changes are needed: the manager already delegates to BackgroundStyleApplicator, which resolves PERCENT length values against the view bounds.

Note: the same Float-typed setter still exists in ReactTextViewManager, PreparedLayoutTextViewManager, ReactTextInputManager, ReactScrollViewManager, and ReactHorizontalScrollViewManager, 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

  • Added testBorderRadius to ReactImagePropertyTest, driving the real crash path (ViewManager.updateProperties → reflection prop updater) with '50%', a plain number, a per-corner percentage, and null, asserting the resolved LengthPercentage on 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"
  • Added a 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

image

@meta-cla

meta-cla Bot commented Aug 3, 2026

Copy link
Copy Markdown

Hi @sbaiahmed1!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

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
@sbaiahmed1
sbaiahmed1 force-pushed the fix/image-percentage-border-radius branch from 17d1d2a to dfca164 Compare August 3, 2026 01:20
@meta-cla

meta-cla Bot commented Aug 3, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 3, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 3, 2026
@meta-codesync

meta-codesync Bot commented Aug 3, 2026

Copy link
Copy Markdown

@fabriziocucci has imported this pull request. If you are a Meta employee, you can view this in D114576433.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Percentage borderRadius applied on the Image component crashes the application on Android API 35

1 participant