Skip to content

Support cover and contain in backgroundSize - #60218

Open
jkasprzyk17 wants to merge 1 commit into
react:mainfrom
jkasprzyk17:fix/background-size-cover-contain-string
Open

jkasprzyk17 wants to merge 1 commit into
react:mainfrom
jkasprzyk17:fix/background-size-cover-contain-string

Conversation

@jkasprzyk17

@jkasprzyk17 jkasprzyk17 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

processBackgroundSize returned [] for any backgroundSize string holding cover or contain, so backgroundSize: '10px auto, cover' dropped every layer, 10px auto included. CSS <bg-size> accepts both keywords, and the C++ prop conversion already reads them.

  • JS: a lone cover/contain layer now parses to the keyword string, the same output as the array form, and every other layer keeps its size. A keyword combined with another value in one layer (cover 10px, cover contain) stays invalid and returns [], like other invalid values. BackgroundSizeValue gets 'cover' | 'contain' back (removed in fix(style)(backgroundSize) - Passing unsupported backgroundSize on android causes crash #55904), and the API snapshot is regenerated.
  • Android: BackgroundSize.parse read only the object form, so a keyword was dropped and the remaining sizes shifted to other layers. It now parses cover and contain. A gradient has no natural size or aspect ratio, so both size it to the background positioning area (CSS Images 3), the same as iOS does today.

The crash fixed in #55904 can't come back: an empty size list is still mapped to null.

Fixes #60214

Changelog:

[General] [Fixed] - backgroundSize strings holding cover or contain no longer drop every layer

Test Plan:

  • yarn fantom packages/react-native/Libraries/StyleSheet/__tests__/processBackgroundSize-itest.js: 50 passed, 50 total
  • ./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests 'com.facebook.react.uimanager.style.BackgroundSizeTest' -PreactNativeArchitectures=arm64-v8a: 4 tests, 0 failures
  • yarn flow-check: Found 0 errors
  • yarn eslint --max-warnings 0 and yarn prettier --check on the changed JS files: clean
  • yarn format-check-kotlin: clean
  • yarn build-types: only BackgroundSizeValue changed in ReactNativeApi.d.ts (plus hashes)
  • yarn test-generated-typescript: passed

RNTester on Android (API 35 emulator), Playground with gradient layers (linear-gradient(red, red), then green, then blue; the first layer is on top), experimental_backgroundRepeat: 'no-repeat' and the experimental_backgroundSize shown next to each box:

Before After
Android before Android after

Before, every string holding a keyword was dropped, so all layers filled the box. After, 40px 40px, cover draws a 40×40 red tile over a blue layer that fills the box, and 40px 40px, contain, 20px 20px draws a 40×40 red tile over a green layer that fills the box.

A backgroundSize string holding cover or contain returned [], dropping
every layer. Parse a lone cover or contain layer to the keyword string,
as the array form passes it, and keep the other layers. A keyword next
to another value in one layer stays invalid, per <bg-size>.

Android's BackgroundSize.parse dropped keyword strings, so the sizes of
the other layers shifted. Parse cover and contain there too. A gradient
has no natural size, so both size it to the positioning area.
@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 22, 2026
@github-actions

Copy link
Copy Markdown

Warning

JavaScript API change detected

This PR commits an update to ReactNativeApi.d.ts, indicating a change to React Native's public JavaScript API.

  • Please include a clear changelog message.
  • This change will be subject to additional review.

This change was flagged as: POTENTIALLY_BREAKING

@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 22, 2026

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.

backgroundSize strings holding cover or contain lose every size, while the array form keeps the keyword

1 participant