Skip to content
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

Closed
wants to merge 4 commits into from

Conversation

jacobp100
Copy link

@jacobp100 jacobp100 commented Dec 20, 2021

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

@intergalacticspacehighway
Copy link
Contributor

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.

@intergalacticspacehighway
Copy link
Contributor

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.

@jacobp100
Copy link
Author

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!

@intergalacticspacehighway
Copy link
Contributor

Cool. no worries. I'll figure it out. Happy holidays! 🥳

@jacobp100
Copy link
Author

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;
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Author

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

Copy link
Author

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;

Copy link
Contributor

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 😅

@jaraujocds
Copy link

We need this 🙏🏻

@davbrito
Copy link

Any update on this?

@erisvaldojunior
Copy link

Any update on this?

@kvbalib
Copy link

kvbalib commented Apr 21, 2022

+1!

@gmantovani97
Copy link

Someone approve it please.

@wood1986
Copy link

wood1986 commented Jun 9, 2022

any update?

@jacobp100
Copy link
Author

mnG4w

@jacobp100
Copy link
Author

For real though, I get notified for every comment. I don't have any updates.

@ShivamJoker
Copy link

Common Facebook devs, its been more than 6 months and you guys just can't review & click that approve button

@etasdemir
Copy link

Still waiting for approvement

@NickGerleman
Copy link
Contributor

NickGerleman commented Aug 1, 2022

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.

@facebook-github-bot
Copy link
Contributor

@NickGerleman has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@intergalacticspacehighway
Copy link
Contributor

Thanks @NickGerleman

There is a spiritual successor to Yoga, that has been successfully adopted by other teams at Meta.

Cool! would be awesome to learn more about this and If there are any plans to open source the implementation :D

@jacobp100
Copy link
Author

@NickGerleman Thanks so much for taking this on! If you have any questions, me and @intergalacticspacehighway will be here to help

@NickGerleman
Copy link
Contributor

NickGerleman commented Sep 27, 2022

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 YGFlexDirectionToString instead of YGGapToString. I'm working to fix those up at the moment, but we should be able to merge this soon 🙂.

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Sep 30, 2022
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
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Sep 30, 2022
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
facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2022
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
facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2022
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
facebook-github-bot pushed a commit that referenced this pull request Sep 30, 2022
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
facebook-github-bot pushed a commit to facebook/litho that referenced this pull request Sep 30, 2022
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
facebook-github-bot pushed a commit to facebook/litho that referenced this pull request Sep 30, 2022
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
facebook-github-bot pushed a commit that referenced this pull request Oct 13, 2022
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
facebook-github-bot pushed a commit that referenced this pull request Oct 13, 2022
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
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Oct 13, 2022
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
facebook-github-bot pushed a commit to facebook/litho that referenced this pull request Oct 13, 2022
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
@NickGerleman
Copy link
Contributor

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.

mohitcharkha pushed a commit to mohitcharkha/react-native that referenced this pull request Oct 17, 2022
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
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Oct 20, 2022
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
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
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
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
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
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
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
OlimpiaZurek pushed a commit to OlimpiaZurek/react-native that referenced this pull request May 22, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gap/row-gap/column/gap properties