Skip to content

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

Backlog

Description

@YevheniiKotyrlo

Description

On Android, a Text's textShadowRadius reaches Paint.setShadowLayer in pixels, while its textShadowOffset is converted from dp. On a 3x screen, textShadowRadius: 8 blurs by about as many pixels as at 160 dpi, a third of its reach in dp; iOS passes the radius to NSShadow.shadowBlurRadius in points.

textShadowRadius: 0 with a non-zero textShadowOffset draws no shadow on Android, since setShadowLayer removes the shadow layer at a radius of 0 ("If radius is 0, then the shadow layer is removed", Paint.setShadowLayer). iOS draws a sharp shadow there.

  • TextAttributeProps converts textShadowOffsetDx and textShadowOffsetDy with toPixelFromDIP and stores textShadowRadius as given (L315-L334, L455).
  • ShadowStyleSpan calls textPaint.setShadowLayer(radius, dx, dy, color) (L19-L21).
  • TextLayoutManager adds the span when either offset or the radius is non-zero (L437-L455), so a radius of 0 with an offset reaches setShadowLayer.
  • iOS: RCTAttributedTextUtils.mm L316-L326.

Steps to reproduce

The reproducer renders three black Texts with textShadowColor: '#ff0000' on white: textShadowOffset: {width: 0, height: 0} with textShadowRadius: 8, and textShadowOffset: {width: 4, height: 4} with textShadowRadius: 0 and with textShadowRadius: 1.

  1. Clone the reproducer and, with one Android device of at least 320 dpi attached, run bash ./reproduce.sh. It builds and installs the release APK, takes a screenshot at the device's density and one at 160 dpi, putting the density back on exit, and measures both. It exits 1 while either defect shows.
  2. Or by hand: cd ReproducerApp/android && ./gradlew assembleRelease && adb install -r app/build/outputs/apk/release/app-release.apk and open the app. The textShadowRadius: 0 text has no shadow; the textShadowRadius: 1 text has a sharp red one. Then adb shell wm density 160, open the app again, and adb shell wm density reset: at 160 dpi the text is a third of its size on a 3x screen, and its blur reaches about as many pixels past the glyphs.

Expected: textShadowRadius in dp, like textShadowOffset, so the blur grows with the density as the text does; textShadowRadius: 0 with an offset draws a sharp shadow, as on iOS. At 160 dpi, where a dp is a pixel, nothing changes.
Seen: from 160 to 480 dpi the text grows 3.03x and its blur 1.09x; textShadowRadius: 0 draws 0 red pixels at both densities.

React Native Version

0.90.0-nightly-20261124-ad969b283

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info

System:
  OS: Windows 11 10.0.26300
  CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor          "
  Memory: 148.88 GB / 255.67 GB
Binaries:
  Node:
    version: 26.12.1
    path: C:\Program Files\nodejs\node.EXE
  Yarn:
    version: 1.22.22
    path: C:\Users\<user>\AppData\Roaming\npm\yarn.CMD
  npm:
    version: 12.2.1
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    Versions:
      - 10.0.19041.0
      - 10.0.26100.0
IDEs:
  Android Studio: AI-262.9437.185.2621.16467767
  Visual Studio: Not Found
Languages:
  Java:
    version: 17.0.20.1
    path: C:\Program Files\Microsoft\jdk-17.0.20.101-hotspot\bin\javac.EXE
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 22.0.0-alpha.0
    wanted: 22.0.0-alpha.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.90.0-nightly-20261124-ad969b283
    wanted: 0.90.0-nightly-20261124-ad969b283
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

No error is logged. bash ./reproduce.sh at the reproducer's 0382af4, on a Galaxy S23:

device: SM-S911B, Android 14 (API 34), arm64-v8a, 1080x2340 at 480 dpi
react-native 0.90.0-nightly-20261124-ad969b283
== ./gradlew :app:assembleRelease -PreactNativeArchitectures=arm64-v8a
screenshots: screenshots/1-at-480-dpi.png, screenshots/2-at-160-dpi.png
at 480 dpi (3.00 px per dp): the text "Shadow" spans 336x73 px, and the red shadow of textShadowRadius: 8 reaches 9.3 px (3.1 dp) past it
at 480 dpi: with textShadowOffset {width: 4, height: 4}, textShadowRadius: 0 draws 0 red pixels and textShadowRadius: 1 draws 5453
at 160 dpi (1.00 px per dp): the text "Shadow" spans 111x24 px, and the red shadow of textShadowRadius: 8 reaches 8.5 px (8.5 dp) past it
at 160 dpi: with textShadowOffset {width: 4, height: 4}, textShadowRadius: 0 draws 0 red pixels and textShadowRadius: 1 draws 415
SUMMARY: from 160 to 480 dpi the text grows 3.03x and its textShadowRadius: 8 blur 1.09x, so the radius is taken in pixels; and textShadowRadius: 0 with an offset draws no shadow, where textShadowRadius: 1 draws one

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/rn-android-text-shadow-radius

Screenshots and Videos

The textShadowRadius: 8 text on the Galaxy S23: at 480 dpi on the left, and at 160 dpi enlarged 3x on the right, so both show the same dp at the same size.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions