Repository navigation
Support cover and contain in backgroundSize - #60218
jkasprzyk17 wants to merge 1 commit into
Conversation
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.
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
cipolleschi
left a comment
There was a problem hiding this comment.
Thanks for fixing this! Could we also handle layers with more than two tokens?
For example:
processBackgroundSize('40px 40px, cover 10px auto, contain')
// Returns [{x: 40, y: 40}, 'contain']The invalid middle layer gets skipped, which can shift sizes onto different background layers. Would it make sense to reject the whole declaration with [] here?
Could we add a check for parts.length > 2 and a regression test with valid layers surrounding the invalid one?
|
Good catch, thanks! A layer with more than two tokens falls through both branches and gets skipped. I'll add a |
Summary:
processBackgroundSizereturned[]for anybackgroundSizestring holdingcoverorcontain, sobackgroundSize: '10px auto, cover'dropped every layer,10px autoincluded. CSS<bg-size>accepts both keywords, and the C++ prop conversion already reads them.cover/containlayer 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.BackgroundSizeValuegets'cover' | 'contain'back (removed in fix(style)(backgroundSize) - Passing unsupported backgroundSize on android causes crash #55904), and the API snapshot is regenerated.BackgroundSize.parseread only the object form, so a keyword was dropped and the remaining sizes shifted to other layers. It now parsescoverandcontain. 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] -
backgroundSizestrings holdingcoverorcontainno longer drop every layerTest 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 failuresyarn flow-check: Found 0 errorsyarn eslint --max-warnings 0andyarn prettier --checkon the changed JS files: cleanyarn format-check-kotlin: cleanyarn build-types: onlyBackgroundSizeValuechanged inReactNativeApi.d.ts(plus hashes)yarn test-generated-typescript: passedRNTester 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 theexperimental_backgroundSizeshown next to each box:Before, every string holding a keyword was dropped, so all layers filled the box. After,
40px 40px, coverdraws a 40×40 red tile over a blue layer that fills the box, and40px 40px, contain, 20px 20pxdraws a 40×40 red tile over a green layer that fills the box.