Skip to content

[Android] TextInput: boxShadow disappears because the underlineColorAndroid color filter also tints it #60303

Backlog

Description

@LouisHaftmann

Description

On Android, a TextInput with boxShadow often renders without its shadow. A View with the same style always shows it, and iOS is not affected.

The cause is ReactTextInputManager.setUnderlineColor. It applies setColorFilter(underlineColor, PorterDuff.Mode.SRC_IN) to the whole view.background. Once the input has a boxShadow, view.background is the CompositeBackgroundDrawable from BackgroundStyleApplicator, and its layers include the OutsetBoxShadowDrawables. OutsetBoxShadowDrawable.setColorFilter sets the filter on its shadow paint, so the shadow takes the underline color. TextInput defaults underlineColorAndroid to 'transparent', so the shadow becomes fully transparent.

Whether the shadow is visible depends on the order the native props are applied:

  • setBoxShadow after setUnderlineColor: withNewShadows creates new shadow drawables without the filter, and the shadow shows.
  • setUnderlineColor after setBoxShadow: the shadow is filtered and disappears.

So the bug looks random in apps: it comes and goes with the set of style keys, styling libraries and later prop updates. The reproducer makes it deterministic by changing underlineColorAndroid after mount.

This is probably the cause of #47920 ("boxShadow on TextInput alternates visible/hidden with each key typed on Android"). It was closed for missing author feedback after it did not reproduce in RNTester, which fits the order dependency.

setUnderlineColor is unchanged on main.

Possible fix: when view.background is a CompositeBackgroundDrawable, apply the underline filter only to its originalBackground (the platform EditText underline drawable). The filter should also survive when BackgroundStyleApplicator builds a new composite.

Workaround: put the boxShadow on a View that wraps the TextInput, or on a sibling View behind it.

Steps to reproduce

  1. Clone the reproducer and run cd ReproducerApp && yarn install && yarn android.
  2. On launch, the TextInput shows its shadow like the View above it.
  3. Press Set underlineColorAndroid="rgba(255, 255, 255, 0)" (one fully transparent color to another). The shadow disappears.
  4. Press Set underlineColorAndroid="red". The shadow turns red.
  5. Press Set underlineColorAndroid="transparent". The shadow disappears again.

Expected: the TextInput shadow looks like the View shadow for every underlineColorAndroid value.

React Native Version

0.88.1

Affected Platforms

Runtime - Android

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

System:
  OS: Linux 7.3 CachyOS Linux
  CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor
  Memory: 39.41 GB / 62.69 GB
  Shell:
    version: 5.3.20
    path: /usr/bin/bash
Binaries:
  Node:
    version: 26.6.0
    path: /home/louis/n/bin/node
  Yarn: Not Found
  npm:
    version: 11.18.0
    path: /home/louis/n/bin/npm
  Watchman: Not Found
SDKs:
  Android SDK:
    API Levels:
      - "31"
      - "33"
      - "36"
      - "37"
      - "37"
    Build Tools:
      - 30.0.3
      - 34.0.0
      - 35.0.0
      - 36.0.0
      - 37.0.0
    System Images:
      - android-36 | Google Play Intel x86_64 Atom
      - android-37.0 | Google Play Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: AI-262.10968.63.2622.16840690
Languages:
  Java:
    version: javac 21
    path: /home/louis/.sdkman/candidates/java/current/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 20.2.0
    wanted: 20.2.0
  react:
    installed: 19.3.0
    wanted: 19.3.0
  react-native:
    installed: 0.88.1
    wanted: 0.88.1
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

None. This is a rendering bug without a crash or log output.

MANDATORY Reproducer

https://github.com/LouisHaftmann/rn-textinput-boxshadow-underline

Screenshots and Videos

OnePlus 7 Pro, Android 12. Left: on launch. Middle: after underlineColorAndroid="rgba(255, 255, 255, 0)". Right: after underlineColorAndroid="red".

overview

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions