Repository navigation
Add Fabric implementation of flow-relative padding and margin - #35342
NickGerleman wants to merge 1 commit into
Conversation
|
This pull request was exported from Phabricator. Differential Revision: D41267765 |
1 similar comment
|
This pull request was exported from Phabricator. Differential Revision: D41267765 |
f2cdc75 to
3b02eb2
Compare
3b02eb2 to
7ae334c
Compare
|
This pull request was exported from Phabricator. Differential Revision: D41267765 |
There was a problem hiding this comment.
As we know, this type;
number | string | undefinedis a generic type for most of the style attributes.
Should we declare a generic type for this type as well? Ex. BoxDimensionValue or BoxDimensionType etc.
And use the same generic type in below code. This will allow us to DRY the code.
Similarly for ;
number | undefinedWhat do you think?
PS: It looks like decl file is modified manually.
There was a problem hiding this comment.
Contributions welcome to clean up the TS declarations 🙂.
7ae334c to
e8de242
Compare
|
This pull request was exported from Phabricator. Differential Revision: D41267765 |
Base commit: 5fda72f |
…35342) Summary: Pull Request resolved: react#35342 This is a native implementation of the JS shimmed layout-specific properties in react#35316. There is an experiment splitting the prop splitting codepath in Fabric, so this change effectively has two implementations depending on whether `enablePropIteratorSetter` is enabled. None of these changes make sense to propagate Yoga. `inlineEnd`, etc are already mapped to `YGEdgeStart` and `YGEdgeEnd`, but RN's mapping used a different name. Then `blockStart`, `blockEnd`, map directly to existing edges in all cases since we don't support a writing mode. On web, the last value in the style which computes the given dimension is given precedence. E.g. if "left" comes after "start" it will be chosen. Yoga stylesheets are unordered, and precedence for edges is given based on specificity (left > start > horizontal > all). We give precedence to new renamings (e.g. start to inlineStart), but to preserve consistent behavior, we give precedence to specific edges before overwriting them with flow relative ones (e.g. marginTop has precedence over marginBlockStar). Changelog: [General][Added] - Add Fabric implementation of flow-relative padding and margin Differential Revision: D41267765 fbshipit-source-id: 2d21c6acb710b04a8577e98bf5cc7d4bb2de1815
|
This pull request was exported from Phabricator. Differential Revision: D41267765 |
e8de242 to
d8c9b1d
Compare
Base commit: 5fda72f |
|
PR build artifact for d8c9b1d is ready. |
|
PR build artifact for d8c9b1d is ready. |
…al edges ## Summary: This proposes a change of behavior, not a bug fix: when a style sets both `paddingTop` and `paddingBlockStart` (or `paddingBottom` and `paddingBlockEnd`), the block-axis longhand wins instead of the physical edge. Today the two axes disagree. `applyAliasedProps` applies `paddingBlockStart` and `paddingBlockEnd` only when `paddingTop` and `paddingBottom` are undefined, while `paddingInlineStart` sets Yoga's `Start` edge, which Yoga resolves before `Left` (`Style::computeLeftEdge`), so it already wins over `paddingLeft`. The block-axis order comes from #35342, which gave "precedence to specific edges" and described Yoga's precedence as "left > start > horizontal > all". But for padding Yoga resolved `start` before `left` then (`YGNode::computeEdgeValueForRow` at `67b8e182fa`) and does today, as #41682 notes. This change makes the block axis match the inline one. Yoga has no block-start or block-end edge, so the longhands replace the physical edges in `applyAliasedProps`. ### Web parity On the web, `padding-top` and `padding-block-start` set the same side in a horizontal writing mode, and the later declaration wins. React Native flattens styles by key, so no declaration order reaches layout, and neither rule matches the web in every case: | Style | Web | `main` | This change | | --- | --- | --- | --- | | `paddingTop: 0` then `paddingBlockStart: 8` | 8 | 0 | 8 | | `paddingBlockStart: 8` then `paddingTop: 0` | 0 | 0 | 8 | So this does not improve web parity in general; it changes which order matches. It gives one rule for padding on both axes: the logical longhand wins over the physical edge. ### Motivation A component library compiled with StyleX for React Native carries `paddingTop: 0` from a reset beside a component's `paddingBlockStart: 8`. React Native applies the 0, and a button is laid out 22 points tall where its design is 38. ### Scope This changes padding only. `marginBlockStart`/`marginBlockEnd`, `insetBlockStart`/`insetBlockEnd` and `borderBlockStartWidth`/`borderBlockEndWidth` still give the physical edge precedence; #59996 gave the border widths that order, and Android's `BorderInsets.kt` follows it. If the direction is right, they should follow; this PR is limited to padding to settle the direction first. The shorthands keep their place: `paddingBlock` sets Yoga's `Vertical` edge, which `paddingTop` and `paddingBottom` still override, as `paddingLeft` overrides `paddingInline` (`Horizontal`). ## Changelog: [GENERAL] [CHANGED] - `paddingBlockStart` and `paddingBlockEnd` take precedence over `paddingTop` and `paddingBottom`, as `paddingInlineStart` and `paddingInlineEnd` do over `paddingLeft` and `paddingRight` ## Test Plan: ```sh yarn fantom packages/react-native/Libraries/Components/View/__tests__/View-paddingBlockLonghands-itest.js ``` The new `View-paddingBlockLonghands-itest.js` lays out a container around a 10×10 child: - `paddingTop: 0, paddingBlockStart: 8, paddingBottom: 0, paddingBlockEnd: 4` puts the child 8 points down in a container 22 tall. On `main` it fails: child at 0, container 10 tall. - `paddingLeft: 0, paddingInlineStart: 8` puts the child 8 points in (passes on `main`: the inline-axis order). - `paddingTop` and `paddingBottom` alone still apply, and `paddingTop: 2, paddingBlock: 8` still gives 2. These pass on this branch, as do `yarn fantom packages/react-native/Libraries/Components/View packages/react-native/Libraries/StyleSheet`, `flow full-check`, ESLint, Prettier and `scripts/clang-format.js --check`. Not run: iOS or Android builds; the change is in shared C++ layout code, which Fantom runs. Differential Revision: D135947739 Pull Request resolved: #60382
Summary:
This is a native implementation of the JS shimmed layout-specific properties in #35316.
There is an experiment splitting the prop setting codepath in Fabric, so this change effectively has two implementations depending on whether
enablePropIteratorSetteris enabled.None of these changes make sense to propagate Yoga.
inlineEnd, etc are already mapped toYGEdgeStartandYGEdgeEnd, but RN's mapping used a different name. ThenblockStart,blockEnd, map directly to existing edges in all cases since we don't support a writing mode.On web, the last value in the style which computes the given dimension is given precedence. E.g. if "left" comes after "start" it will be chosen. Yoga stylesheets are unordered, and precedence for edges is given based on specificity (left > start > horizontal > all). The JS change would always give precedence to flow-relative properties, and we emulate the same ordering independence for consistency with current rules for resolution.
Changelog:
[General][Added] - Add Fabric implementation of flow-relative padding and margin
Differential Revision: D41267765