-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for gap, column-gap, and row-gap #1116
Conversation
Great work 👏 I have been trying a similar approach but got stuck with setting child's cross-axis offset. Glad to see this solution. I've added a PR for a fix. I'll be testing it more as I get time. |
Flex gap fixes
This looks good! Can you create a PR on this branch with yoga changes, I'll update the React native bindings to match with this version. It'll make it easier to test stuff and get feedback on this PR. AFAIKS React native has Yoga here. Would be cool to figure out if there's an automated way to get a specific Yoga version in React native. |
I’m away from my laptop until the new year now. If you want I can give you write access to my fork if that makes things easier! |
Cool. no worries. I'll figure it out. Happy holidays! 🥳 |
You too! Feel free to ping me if you need me to sanity check anything or are stuck with anything! |
collectedFlexItemsValues.itemsOnLine; | ||
leadingMainDim = betweenMainDim / 2; | ||
betweenMainDim += leadingMainDim * 2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could be a nit pick - this can also be represented as below
case YGJustifySpaceAround: {
const float betweenMainDimWithoutGap = collectedFlexItemsValues.remainingFreeSpace /
collectedFlexItemsValues.itemsOnLine;
// Space on the edges is half of the space between elements
leadingMainDim = betweenMainDimWithoutGap / 2;
betweenMainDim += betweenMainDimWithoutGap;
break;
}
need to check if cost of multiplication > cost of defining a scope and a variable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deja vu! I actually did it like this originally - then I thought this path is used a lot less than the flex start, and the extra variable could affect the entire function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what you think anyway. I’m not adverse to changing it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a thought, we could do,
leadingMainDim = collectedFlexItemsValues.remainingFreeSpace /
collectedFlexItemsValues.itemsOnLine;
betweenMainDim += leadingMainDim;
leadingMainDim *= 0.5;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, this might be good as it prevents additional multiplication, but we can wait for someone with c++ performance experience to review it 😅
We need this 🙏🏻 |
Any update on this? |
Any update on this? |
+1! |
Someone approve it please. |
any update? |
For real though, I get notified for every comment. I don't have any updates. |
Common Facebook devs, its been more than 6 months and you guys just can't review & click that approve button |
Still waiting for approvement |
Hey folks! I want to apologize for the lack of engagement on this issue. Yoga has been without a full-time maintainer. PRs like this show that the community is still finding important issues. I'm going to import this PR, and try to find a reviewer. There is a spiritual successor to Yoga, that has been successfully adopted by other teams at Meta. We have been looking at whether it can help provide a path to enable new capabilities and support for layout in react-native. |
@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Thanks @NickGerleman
Cool! would be awesome to learn more about this and If there are any plans to open source the implementation :D |
@NickGerleman Thanks so much for taking this on! If you have any questions, me and @intergalacticspacehighway will be here to help |
I left a comment in react-native-community/discussions-and-proposals, that we've decided not to go forward with flexlayout yet in react-native. This reopens the possibility to add new capabilities to Yoga, without the same concern of giving something to the community to then take it back. The core functionality in this PR looks to be well tested from the fixtures added. I am not an expert in the internals of Yoga, but I am seeing everything that I would expect to. The space for the gap is accounted for in line-breaking, and the accumulated gaps limit the available line-length, before sizing flexible children, so items are sized correctly as to accommodate the gap. Then the gap is used for spacing during main axis and cross-axis justification. There are a couple of more superficial issues. E.g. formatting, missing methods on the node to set/get gap in Java/C# (where the generated tests use that), or calling a function |
Summary: facebook/yoga#1116 adds a new enum. The enum generator is out of date with copyright header, and some codemods, but it also looks like there were manual changes, types added, etc since generation. I fixed up the script to incorporate generating the changes folks made manually, and also added an enum that was previously only added manually to the C ABI. Changelog: [General][Fixed] - Fixup Yoga Enum Generator Reviewed By: yungsters Differential Revision: D39922252 fbshipit-source-id: b678fa9a43a896873d8c434745bdaf3f16fd991f
Summary: This adds the YGGutter enum, used to choose between row/column gap variants (row-gap, column-gap, gap). This used later in changes from facebook/yoga#1116, in the APIs which deal with setting gap on style on yoga node. Note the original PR called this `YGGap`, but this ending up leading to a couple public method signatures that could appear ambiguous: 1. `SetGap(YGGap gap, float gapLength)`: Enums like `YGAlign` are the vaues for an `align` prop. `YGGap` controls the variant of the gap (like `YGEdge` does for left/right/top/bottom variants). So the enum reads as if it is the `gapValue`, and it looks like we have two of the same parameter. 2. `SetGap(YGGap gapDirection, float gap)`: This is misleading, because the direction gaps flow is the cross-axis of flex-direction. 3. `GetGap(YGGap gap)`: `gap` is the variant, but looks like an out param. The [CSS Box Alignment](https://www.w3.org/TR/css-align-3/#column-row-gap) spec refers to these gaps as "Gutters", which removes the ambiguity. Changelog: [General][Added] - Add YGGutter Enum Reviewed By: yungsters Differential Revision: D39922412 fbshipit-source-id: 4b0baf800fecb3d03560a4267c7fb4c4330fd39e
Summary: #1116 added a change to the test generator "gentests.rb" to support a newer version of chromedriver, along with a change to the enum generator (not touched in this diff) to produce code consistent with the current tests, which seem to have been manually edited since last generation. I had trouble running the test generator locally, because it relies on unversioned third-party dependencies, whose APIs change. Looking at source history, it seems like each time someone wants to run the script, they end up updating its syntax to match whatever versions they pull in. This change adds a Gemfile and lock so that that the version of "watir" is locked, and so that we will also automatically pull in a consistent "chomedriver" version via the "webdrivers" gem. It includes the updates from the PR to be consistent with already output tests, and I have also updated the copyright header generation to no longer create lint warnings on newly generated tests (some of the previous ones were fixed manually it looks like). The test generator would still produce bodies which would fail clang-format, and were manually edited (causing generation to emit new lint warnings), so I updated the generator to suppress clang-format in the body of the generated files. Three tests, around the interaction of minimum dimensions and flexible children produce different results in Chrome now compared to when the tests were added, so running `gentests.rb` creates tests which break UTs. This doesn't seem like any sort of rounding, or device specific difference, so I have disabled these tests for now. While digging around, it does look like Chrome periodically will fix bugs in its own layout implementation which cause differences, like https://bugs.chromium.org/p/chromium/issues/detail?id=927066 Reviewed By: rozele, Andrey-Mishanin Differential Revision: D39907416 fbshipit-source-id: f88714ff038b42f935901783452df25eabb6ebb1
Summary: #1116 adds a new enum. The enum generator is out of date with copyright header, and some codemods, but it also looks like there were manual changes, types added, etc since generation. I fixed up the script to incorporate generating the changes folks made manually, and also added an enum that was previously only added manually to the C ABI. Changelog: [General][Fixed] - Fixup Yoga Enum Generator Reviewed By: yungsters Differential Revision: D39922252 fbshipit-source-id: b678fa9a43a896873d8c434745bdaf3f16fd991f
Summary: This adds the YGGutter enum, used to choose between row/column gap variants (row-gap, column-gap, gap). This used later in changes from #1116, in the APIs which deal with setting gap on style on yoga node. Note the original PR called this `YGGap`, but this ending up leading to a couple public method signatures that could appear ambiguous: 1. `SetGap(YGGap gap, float gapLength)`: Enums like `YGAlign` are the vaues for an `align` prop. `YGGap` controls the variant of the gap (like `YGEdge` does for left/right/top/bottom variants). So the enum reads as if it is the `gapValue`, and it looks like we have two of the same parameter. 2. `SetGap(YGGap gapDirection, float gap)`: This is misleading, because the direction gaps flow is the cross-axis of flex-direction. 3. `GetGap(YGGap gap)`: `gap` is the variant, but looks like an out param. The [CSS Box Alignment](https://www.w3.org/TR/css-align-3/#column-row-gap) spec refers to these gaps as "Gutters", which removes the ambiguity. Changelog: [General][Added] - Add YGGutter Enum Reviewed By: yungsters Differential Revision: D39922412 fbshipit-source-id: 4b0baf800fecb3d03560a4267c7fb4c4330fd39e
Summary: facebook/yoga#1116 adds a new enum. The enum generator is out of date with copyright header, and some codemods, but it also looks like there were manual changes, types added, etc since generation. I fixed up the script to incorporate generating the changes folks made manually, and also added an enum that was previously only added manually to the C ABI. Changelog: [General][Fixed] - Fixup Yoga Enum Generator Reviewed By: yungsters Differential Revision: D39922252 fbshipit-source-id: b678fa9a43a896873d8c434745bdaf3f16fd991f
Summary: This adds the YGGutter enum, used to choose between row/column gap variants (row-gap, column-gap, gap). This used later in changes from facebook/yoga#1116, in the APIs which deal with setting gap on style on yoga node. Note the original PR called this `YGGap`, but this ending up leading to a couple public method signatures that could appear ambiguous: 1. `SetGap(YGGap gap, float gapLength)`: Enums like `YGAlign` are the vaues for an `align` prop. `YGGap` controls the variant of the gap (like `YGEdge` does for left/right/top/bottom variants). So the enum reads as if it is the `gapValue`, and it looks like we have two of the same parameter. 2. `SetGap(YGGap gapDirection, float gap)`: This is misleading, because the direction gaps flow is the cross-axis of flex-direction. 3. `GetGap(YGGap gap)`: `gap` is the variant, but looks like an out param. The [CSS Box Alignment](https://www.w3.org/TR/css-align-3/#column-row-gap) spec refers to these gaps as "Gutters", which removes the ambiguity. Changelog: [General][Added] - Add YGGutter Enum Reviewed By: yungsters Differential Revision: D39922412 fbshipit-source-id: 4b0baf800fecb3d03560a4267c7fb4c4330fd39e
Summary: This extracts the core changes from #1116, to support gap/row-gap/column-gap, mostly identical, apart from the rename of gaps -> gutters. The core functionality in this PR looks to be well tested from the fixtures added. I am not an expert in the internals of Yoga, but I am seeing everything that I would expect to. The space for the gap is accounted for in line-breaking, and the accumulated gaps limit the available line-length, before sizing flexible children, so items are sized correctly as to accommodate the gap. Then the gap is used for spacing during main axis and cross-axis justification. Changelog: [Genral][Added] - Implement gap/row-gap/column-gap (within the yoga C ABI) Reviewed By: javache Differential Revision: D39922410 fbshipit-source-id: 5850f22032169028bd8383b49dd240b335c11d3d
Summary: This adds the fixtures from #1116 and generates tests. This adds a good amount of coverage, but I plan to follow up with a diff adding a bit more, e.g. for interactions with flex direction of column when we should no-op, etc. I also discovered the current fixtures do not allow testing shorthand props like "gap" without changes. This also updates the `webdrivers` gem to respond to a break with chromedriver on m1 macs from 4 days ago titusfortner/webdrivers#239. Reviewed By: yungsters Differential Revision: D39922413 fbshipit-source-id: dfc7bda894be8dfcb24e25c19a4df0b09a72ce7e
Summary: This extracts the core changes from facebook/yoga#1116, to support gap/row-gap/column-gap, mostly identical, apart from the rename of gaps -> gutters. The core functionality in this PR looks to be well tested from the fixtures added. I am not an expert in the internals of Yoga, but I am seeing everything that I would expect to. The space for the gap is accounted for in line-breaking, and the accumulated gaps limit the available line-length, before sizing flexible children, so items are sized correctly as to accommodate the gap. Then the gap is used for spacing during main axis and cross-axis justification. Changelog: [Genral][Added] - Implement gap/row-gap/column-gap (within the yoga C ABI) Reviewed By: javache Differential Revision: D39922410 fbshipit-source-id: 5850f22032169028bd8383b49dd240b335c11d3d
Summary: This extracts the core changes from facebook/yoga#1116, to support gap/row-gap/column-gap, mostly identical, apart from the rename of gaps -> gutters. The core functionality in this PR looks to be well tested from the fixtures added. I am not an expert in the internals of Yoga, but I am seeing everything that I would expect to. The space for the gap is accounted for in line-breaking, and the accumulated gaps limit the available line-length, before sizing flexible children, so items are sized correctly as to accommodate the gap. Then the gap is used for spacing during main axis and cross-axis justification. Changelog: [Genral][Added] - Implement gap/row-gap/column-gap (within the yoga C ABI) Reviewed By: javache Differential Revision: D39922410 fbshipit-source-id: 5850f22032169028bd8383b49dd240b335c11d3d
Good news! All of the changes from this PR should now be merged. The change should be synced to React Native already, and facebook/react-native#34360 tracks the PR exposing the capability. I am planning to release this change along with the other recently merged commits in a new version of Yoga. This will be published to Maven Central and Cocoapods. The latter needs a little bit of infra work before this happens. There was a delay here that I don't this is acceptable. I think we should be better positioned now to accept Yoga changes going forward. |
Summary: This extracts the core changes from facebook/yoga#1116, to support gap/row-gap/column-gap, mostly identical, apart from the rename of gaps -> gutters. The core functionality in this PR looks to be well tested from the fixtures added. I am not an expert in the internals of Yoga, but I am seeing everything that I would expect to. The space for the gap is accounted for in line-breaking, and the accumulated gaps limit the available line-length, before sizing flexible children, so items are sized correctly as to accommodate the gap. Then the gap is used for spacing during main axis and cross-axis justification. Changelog: [Genral][Added] - Implement gap/row-gap/column-gap (within the yoga C ABI) Reviewed By: javache Differential Revision: D39922410 fbshipit-source-id: 5850f22032169028bd8383b49dd240b335c11d3d
Summary: This PR adds React native binding for facebook/yoga#1116 ## Changelog [General] [Added] - Flex gap yoga bindings <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> Pull Request resolved: #34974 Test Plan: Run rn tester app and go to view example. You'll find a flex gap example. Example location - `packages/rn-tester/js/examples/View/ViewExample.js` ### Tested on - [x] iOS Fabric - [x] iOS non-fabric - [x] Android Fabric - [x] Android non-fabric To test on non-fabric Android, I just switched these booleans. Let me know if there's anything else I might have missed. <img width="674" alt="Screenshot 2022-10-14 at 3 30 48 AM" src="https://user-images.githubusercontent.com/23293248/195718971-7aee4e7e-dbf0-4452-9d47-7925919c61dc.png"> Reviewed By: mdvacca Differential Revision: D40527474 Pulled By: NickGerleman fbshipit-source-id: 81c2c97c76f58fad3bb40fb378aaf8b6ebd30d63
Summary: facebook/yoga#1116 adds a new enum. The enum generator is out of date with copyright header, and some codemods, but it also looks like there were manual changes, types added, etc since generation. I fixed up the script to incorporate generating the changes folks made manually, and also added an enum that was previously only added manually to the C ABI. Changelog: [General][Fixed] - Fixup Yoga Enum Generator Reviewed By: yungsters Differential Revision: D39922252 fbshipit-source-id: b678fa9a43a896873d8c434745bdaf3f16fd991f
Summary: This adds the YGGutter enum, used to choose between row/column gap variants (row-gap, column-gap, gap). This used later in changes from facebook/yoga#1116, in the APIs which deal with setting gap on style on yoga node. Note the original PR called this `YGGap`, but this ending up leading to a couple public method signatures that could appear ambiguous: 1. `SetGap(YGGap gap, float gapLength)`: Enums like `YGAlign` are the vaues for an `align` prop. `YGGap` controls the variant of the gap (like `YGEdge` does for left/right/top/bottom variants). So the enum reads as if it is the `gapValue`, and it looks like we have two of the same parameter. 2. `SetGap(YGGap gapDirection, float gap)`: This is misleading, because the direction gaps flow is the cross-axis of flex-direction. 3. `GetGap(YGGap gap)`: `gap` is the variant, but looks like an out param. The [CSS Box Alignment](https://www.w3.org/TR/css-align-3/#column-row-gap) spec refers to these gaps as "Gutters", which removes the ambiguity. Changelog: [General][Added] - Add YGGutter Enum Reviewed By: yungsters Differential Revision: D39922412 fbshipit-source-id: 4b0baf800fecb3d03560a4267c7fb4c4330fd39e
Summary: This extracts the core changes from facebook/yoga#1116, to support gap/row-gap/column-gap, mostly identical, apart from the rename of gaps -> gutters. The core functionality in this PR looks to be well tested from the fixtures added. I am not an expert in the internals of Yoga, but I am seeing everything that I would expect to. The space for the gap is accounted for in line-breaking, and the accumulated gaps limit the available line-length, before sizing flexible children, so items are sized correctly as to accommodate the gap. Then the gap is used for spacing during main axis and cross-axis justification. Changelog: [Genral][Added] - Implement gap/row-gap/column-gap (within the yoga C ABI) Reviewed By: javache Differential Revision: D39922410 fbshipit-source-id: 5850f22032169028bd8383b49dd240b335c11d3d
Summary: This PR adds React native binding for facebook/yoga#1116 ## Changelog [General] [Added] - Flex gap yoga bindings <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> Pull Request resolved: facebook#34974 Test Plan: Run rn tester app and go to view example. You'll find a flex gap example. Example location - `packages/rn-tester/js/examples/View/ViewExample.js` ### Tested on - [x] iOS Fabric - [x] iOS non-fabric - [x] Android Fabric - [x] Android non-fabric To test on non-fabric Android, I just switched these booleans. Let me know if there's anything else I might have missed. <img width="674" alt="Screenshot 2022-10-14 at 3 30 48 AM" src="https://user-images.githubusercontent.com/23293248/195718971-7aee4e7e-dbf0-4452-9d47-7925919c61dc.png"> Reviewed By: mdvacca Differential Revision: D40527474 Pulled By: NickGerleman fbshipit-source-id: 81c2c97c76f58fad3bb40fb378aaf8b6ebd30d63
Only supports point values - percents don't work, and shouldn't be exposed as part of the API (similar to the current situation with borders).
I've added tests, and they all work.
I'm not 100% sure I've handled the bindings all correctly. I did run
enums.py
- but this created white a lot of extra changes too.Let me know if there's anything I've missed.
Fixes #812