Repository navigation
Commit bd9348a
Keep percentages in translateX/translateY string transforms (#59366)
Summary:
`processTransform` drops the `%` unit when it parses `translateX(...)` or `translateY(...)` from a CSS transform string:
```js
processTransform('translateX(10%)'); // [{translateX: 10}], expected [{translateX: '10%'}]
```
Native reads a bare number as points, so a view styled with `transform: 'translateX(10%)'` moves 10 points instead of 10% of its width. `translate(10%, 20px)` and the array form `[{translateX: '10%'}]` already keep the percentage, and so does the native CSS parser (`enableNativeCSSParsing`). Only the `translateX`/`translateY` branch of the JS string parser discards it.
The same parser also required a digit before the decimal point, so `translateX(.5px)` and `matrix(.5, …)` parsed `.5` as `5`. The array form and the native CSS parser both accept these. #57487 fixed the same problem in `processTransformOrigin`.
## Changelog:
[GENERAL] [FIXED] - Keep percentages in `translateX`/`translateY` string transforms and parse numbers without a leading zero
Pull Request resolved: #59366
Test Plan:
New tests fail without the fix and pass with it:
- `yarn fantom packages/react-native/Libraries/StyleSheet/__tests__/processTransform-itest.js`: 19 passed. Without the fix, 2 fail: `translateX(10%)` gives `{translateX: 10}`, and `translateX(.5px)` gives `{translateX: 5}`.
- `yarn fantom packages/react-native/Libraries/Components/View/__tests__/View-itest.js`: 228 passed. The new test renders a 200×50 `<View>` with `transform: 'translateX(10%) translateY(20%)'` and checks `getBoundingClientRect()`. Without the fix, the 2 `enableNativeCSSParsing` 🛑 variants fail with `Expected 20 but received 10`. The 2 ✅ variants already passed because the native parser handles it.
- `CSSTransformTest.cpp`: added `matrix_leading_dot`, `translate_x_leading_dot` and `translate_y_leading_dot` to show the native parser already handles these inputs. I couldn't find an OSS runner for these tests, so I compiled the file against googletest 1.15.2 and the in-repo headers: 95 tests passed. Changing an expected value to `5.0f` makes `translate_x_leading_dot` fail with `Which is: 0.5`, so the assertion is checking the parsed value.
- `yarn flow-check`: 0 errors. ESLint `--max-warnings 0` and Prettier on the changed JS files are clean, and `node scripts/clang-format.js --check` on the changed C++ file is clean.
Not run: RNTester on a device. The change is JS-only and covered by the Fantom layout test above.
Reviewed By: rubennorte
Differential Revision: D127122803
Pulled By: javache
fbshipit-source-id: a7f8873c12bc845c074405e6d79da00b723d223c1 parent 4fac9c8 commit bd9348a
4 files changed
Lines changed: 104 additions & 5 deletions
File tree
- packages/react-native
- Libraries
- Components/View/__tests__
- StyleSheet
- __tests__
- ReactCommon/react/renderer/css/tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
200 | 225 | | |
201 | 226 | | |
202 | 227 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
151 | 182 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | 67 | | |
66 | 68 | | |
67 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
| |||
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
76 | | - | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| |||
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
128 | | - | |
| 133 | + | |
129 | 134 | | |
130 | 135 | | |
131 | 136 | | |
| |||
135 | 140 | | |
136 | 141 | | |
137 | 142 | | |
138 | | - | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
139 | 153 | | |
140 | 154 | | |
141 | 155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
| |||
181 | 191 | | |
182 | 192 | | |
183 | 193 | | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
184 | 204 | | |
185 | 205 | | |
186 | 206 | | |
| |||
224 | 244 | | |
225 | 245 | | |
226 | 246 | | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
227 | 256 | | |
228 | 257 | | |
229 | 258 | | |
| |||
0 commit comments