Repository navigation
Support cover and contain in backgroundSize - #60218
jkasprzyk17 wants to merge 1 commit into
Conversation
|
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 |
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>. A layer with more than two values was skipped, so the sizes of the layers after it shifted. Reject the whole declaration instead, as for any other invalid layer. 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.
b88904a to
f747f34
Compare
|
@cipolleschi Done: a layer with more than two values now rejects the whole declaration with |
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.cover 10px auto,10px 20px 30px) was skipped, so the sizes of the layers after it shifted onto other layers. It now rejects the whole declaration with[].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: 51 passed, 51 total. The new more-than-two-values test fails without the parser change./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.