Skip to content

Take Android textShadowRadius in dp and draw a sharp shadow at 0 - #60284

Open
jkasprzyk17 wants to merge 1 commit into
react:mainfrom
jkasprzyk17:fix/android-text-shadow-radius-dp
Open

jkasprzyk17 wants to merge 1 commit into
react:mainfrom
jkasprzyk17:fix/android-text-shadow-radius-dp

Conversation

@jkasprzyk17

@jkasprzyk17 jkasprzyk17 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Fixes #60280.

On Android, a Text's textShadowRadius reached Paint.setShadowLayer in pixels, while textShadowOffset is converted from dp. The blur therefore did not grow with the screen density: on a 3x screen, textShadowRadius: 8 blurred by about a third of its reach in dp. iOS passes the radius to NSShadow.shadowBlurRadius in points.

Also, textShadowRadius: 0 with a non-zero textShadowOffset drew no shadow at all, because setShadowLayer removes the shadow layer when the radius is 0. iOS draws a sharp shadow there.

This change:

  • converts textShadowRadius from dp in TextAttributeProps, like textShadowOffset. This covers Text and TextInput, which share the span-building path.
  • passes the smallest positive radius to setShadowLayer in ShadowStyleSpan when the radius is 0, so the offset shadow is drawn sharp instead of being removed. ShadowStyleSpan is only added when the offset or the radius is non-zero, so text without a shadow is unaffected.

At 160 dpi, where a dp is a pixel, the radius is unchanged. On higher densities, existing blurs get wider, so this changes how existing text shadows look on Android. They now match iOS and the dp values used everywhere else.

Changelog:

[ANDROID] [CHANGED] - textShadowRadius is now in dp, like textShadowOffset, and textShadowRadius: 0 with an offset draws a sharp shadow instead of none

Test Plan:

Unit tests (Robolectric):

./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.views.text.*' -PreactNativeArchitectures=arm64-v8a

133 tests, 0 failures. New tests:

  • TextAttributePropsTest.mapBufferConvertsTextShadowRadiusFromDIP: radius 8 at density 2 becomes 16 px, next to the offsets.
  • ShadowStyleSpanTest: radius 0 with an offset keeps a positive shadow layer radius on the paint, and a positive radius is passed through.

yarn format-check-kotlin passes.

Manual: RNTester on an Android 15 emulator (Pixel 8, 420 dpi), Playground with black 36 pt Texts and a TextInput, textShadowColor: '#ff0000':

  • textShadowOffset: {width: 0, height: 0}, textShadowRadius: 8
  • textShadowOffset: {width: 4, height: 4}, textShadowRadius: 0
  • textShadowOffset: {width: 4, height: 4}, textShadowRadius: 1
  • TextInput with textShadowOffset: {width: 0, height: 0}, textShadowRadius: 8
Before After
Before After

Before: the radius-0 text has no shadow, and the radius-8 blur is about 3 px wide. After: the radius-0 text has a sharp offset shadow, and the radius-8 blur scales with the density, in both Text and TextInput.

Not checked: a real device, and the 160 dpi case (where nothing should change).

textShadowRadius reached Paint.setShadowLayer in pixels while
textShadowOffset was converted from dp, so the blur did not scale with
the screen density. A radius of 0 with an offset removed the shadow
layer entirely, where iOS draws a sharp shadow.

Fixes react#60280
@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 Nov 25, 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 Nov 25, 2026
@github-actions

Copy link
Copy Markdown

Visual regression

6 visual difference(s) at 09063bafad08. Visual differences need maintainer approval. Review the report, then apply visual-change-approved.

ios: no capture

android text-input/text-styles/cycle-1: Changed, 10147 px (0.994%)

diff

Expected and Captured
Expected Captured
expected captured

android text-input/text-styles/cycle-2: Changed, 9213 px (0.903%)

diff

Expected and Captured
Expected Captured
expected captured

android text-input/text-styles/cycle-3: Changed, 9527 px (0.933%)

diff

Expected and Captured
Expected Captured
expected captured

android text-input/text-styles/cycle-4: Changed, 9326 px (0.914%)

diff

Expected and Captured
Expected Captured
expected captured

android text-input/text-styles/cycle-5: Changed, 9436 px (0.925%)

diff

Expected and Captured
Expected Captured
expected captured

android text-input/text-styles/cycle-6: Changed, 9478 px (0.929%)

diff

Expected and Captured
Expected Captured
expected captured

This branch has not been deployed

No deployments
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.

Android: textShadowRadius is taken in pixels rather than dp, and textShadowRadius: 0 with an offset draws no shadow

1 participant