Skip to content

Android: a backgroundSize with one auto axis is ignored, so '20px auto' draws a gradient over the whole view instead of a 20px tile #60346

Done

Description

@YevheniiKotyrlo

Description

On Android, a backgroundSize entry that gives one axis a length or a percentage and leaves the other auto is dropped whole: the tile keeps the positioning area's width and height. With backgroundImage: 'linear-gradient(#ff0000, #0000ff)', backgroundRepeat: 'no-repeat' and backgroundSize: '20px auto', a 200x100 View is filled with the gradient edge to edge, where '20px 100%' draws a 20 point strip at its left. CSS Backgrounds 3 sizes the given axis by its value and, for an image with no natural size such as a gradient, the auto axis as 100%, so both entries give the same 20x100 tile.

  • BackgroundSize.kt reads auto as a null axis (L65, L90).
  • BackgroundImageDrawable.calculateBackgroundImageSize starts from the positioning area's size and applies the entry only when both axes are non-null (L353-L370), so one auto axis keeps both at the area's size.
  • iOS applies each axis on its own (RCTBackgroundImageUtils.mm L163-L182).

Both came in with #52282, which brought backgroundSize to Android. #58247 (open) rewrites calculateBackgroundImageSize so that an auto axis keeps a url() image's ratio, and keeps an image with no ratio, a gradient, at its intrinsic size, so this case stays as it is there.

Steps to reproduce

The reproducer renders two white 200x100 Views with backgroundImage: 'linear-gradient(#ff0000, #0000ff)' and backgroundRepeat: 'no-repeat', the first with backgroundSize: '20px auto', the second with backgroundSize: '20px 100%'.

  1. Clone the reproducer and, with one Android device attached, run bash ./reproduce.sh. It builds and installs the release APK, takes a screenshot, and reads each View's colour 10 dp and 100 dp from its left edge, half way down. It exits 1 while the 20px auto View shows the gradient at both points and the 20px 100% View at 10 dp alone.
  2. Or by hand: cd ReproducerApp && yarn install && cd android && ./gradlew assembleRelease && adb install -r app/build/outputs/apk/release/app-release.apk and open the app. The second View shows a 20 point gradient strip on white; the first is filled with the gradient.

Expected: the 20px auto View draws the same 20x100 strip as the 20px 100% View.
Seen: the gradient over the whole 20px auto View.

React Native Version

0.90.0-nightly-20261127-7a2d1d257

Affected Platforms

Runtime - Android

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

info Fetching system and libraries information...
System:
  OS: Windows 11 10.0.26300
  CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor          "
  Memory: 140.33 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-20261127-7a2d1d257
    wanted: 0.90.0-nightly-20261127-7a2d1d257
  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 dbfa2b3, on a Galaxy S23:

[…]
device: SM-S911B, Android 14 (API 34), arm64-v8a
react-native 0.90.0-nightly-20261127-7a2d1d257
== ./gradlew :app:assembleRelease -PreactNativeArchitectures=arm64-v8a
screenshot: screenshot.png
backgroundSize: '20px auto': 600x300 px; at 10 dp: the gradient; at 100 dp: the gradient
backgroundSize: '20px 100%': 600x300 px; at 10 dp: the gradient; at 100 dp: white (no tile)
SUMMARY: '20px auto' fills the whole view with the gradient, where '20px 100%' draws a 20 dp tile; exit 1

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/rn-android-background-size-one-auto-axis

Screenshots and Videos

No response

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