Commit Graph

2471 Commits

Author SHA1 Message Date
Eric Rozell
50ecd98141 Add test fixture to reproduce bug in aspect-ratio (#1421)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1421

Adds repro of inconsistent implementation of aspect-ratio behavior across Web and React Native.

Reviewed By: NickGerleman

Differential Revision: D50225804

fbshipit-source-id: 0494e0373dcdebc789715b2ec19c002a47d69ce0
2023-10-12 15:02:00 -07:00
Eric Rozell
a876372357 Add option to use aspect-ratio in test fixtures
Summary: Wires up codegen for aspect-ratio styles in JS, Java and CPP gentest fixtures.

Reviewed By: NickGerleman

Differential Revision: D50225805

fbshipit-source-id: 660a3999eab24611b7c2d2e073b1d55180a5d4f0
2023-10-12 15:02:00 -07:00
Eric Rozell
fad4d50b8e Add option to use overflow: scroll in text fixtures
Summary: Wires up the option to use overflow: scroll in JS, Java, and CPP gentest fixtures.

Reviewed By: NickGerleman

Differential Revision: D50225803

fbshipit-source-id: f71c000b7143ad9e0e34d99e2d5ba2c6186266d1
2023-10-12 15:02:00 -07:00
Joe Vilches
bac658b4f5 Add row reverse tests for position
Summary: after looking into the issue described in https://github.com/facebook/yoga/issues/1208 it seems to apply to position too, so adding tests to confirm

Reviewed By: NickGerleman

Differential Revision: D50154056

fbshipit-source-id: 64dd04ce3ad765526a547fe60b699b664f251c06
2023-10-11 14:02:39 -07:00
Joe Vilches
799624b9a5 Add row reverse tests for border
Summary: after looking into the issue described in https://github.com/facebook/yoga/issues/1208 it seems to apply to border too, so adding tests to confirm

Reviewed By: NickGerleman

Differential Revision: D50153472

fbshipit-source-id: a50f3e040153086b6a573924b513919dbb94f3c0
2023-10-11 14:02:39 -07:00
Joe Vilches
9d9b1f0874 Add row reverse tests for padding
Summary: after looking into the issue described in https://github.com/facebook/yoga/issues/1208 it seems to apply to padding too, so adding tests to confirm

Reviewed By: NickGerleman

Differential Revision: D50153085

fbshipit-source-id: bad0ef50389a71a45ec3a58d87c1dea0c2b26024
2023-10-11 14:02:39 -07:00
Chiara Mooney
81de77af8d Fix Type Casting Warnings in ReactCommon
Summary:
Casting warnings are treated as errors in React Native Windows. Adjusting casting to fix warnings.

## Changelog:
[GENERAL] [FIXED] - Fixes type casting warnings that are treated as errors downstream in React Native Windows.

X-link: https://github.com/facebook/react-native/pull/39818

Reviewed By: rshest

Differential Revision: D49940422

Pulled By: NickGerleman

fbshipit-source-id: e4d44326806a2b1974c7e50770e61807a007e39f
2023-10-09 11:07:46 -07:00
Nick Gerleman
7fe6e345a7 FloatOptional GCC build fix and more constexpr (#1411)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1411

X-link: https://github.com/facebook/react-native/pull/39796

Pull Request resolved: https://github.com/facebook/yoga/pull/1414

GCC flags that `isUndefined()` is not declared `constexpr` but that `unwrapOrDefault()` is. `std::isnan` is not constexpr until C++ 23 (because we cannot have nice things), so I made `yoga::isUndefined()` constexpr, using the same code `std::isnan()` boils down to. I then made `FloatOptional` depend on `Comparison.h` (instead of the other way around), so we can use it.

Note that the use of the `std::floating_point` concept here requires the libc++ bump in the previous diff in the stack.

Reviewed By: yungsters

Differential Revision: D49896837

fbshipit-source-id: 61e2bbbfedecffd007a12d42d998e43d3cf5119c
2023-10-06 13:04:39 -07:00
Nick Gerleman
f700e1335c C++ style enums 17/N: Gutter (#1407)
Summary:
X-link: https://github.com/facebook/react-native/pull/39599

Pull Request resolved: https://github.com/facebook/yoga/pull/1407

Replaces internal usages of YGGutter with Gutter.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49532100

fbshipit-source-id: 53c1d23e23a9db7294c66b6dc0eaff4e62ff278c
2023-10-04 20:34:42 -07:00
Nick Gerleman
98d2172e05 Use modern Android libc++ in Yoga and React Native OSS (#1412)
Summary:
X-link: https://github.com/facebook/react-native/pull/39795
Pull Request resolved: https://github.com/facebook/yoga/pull/1412

Android NDK 25 uses a version of libc++ that is more than three years old, missing a lot of basic features of C++ 20. This is rectified in NDK 26 (latest LTS NDK), which brings us up to date with latest Clang (17, released this year), and adds a new policy where future NDK versions will bump libc++ as part of bumping LLVM/Clang.

This requires an a beta AGP version (and corresponding Android Studio Preview). Based on how far we are historically, it wouldn't be a surprise if we see the stable release this month (well before the RN 0.74/Yoga 3.0 cut, even in the worse case).

Changelog:
[Android][Changed] - Use NDK 26

Reviewed By: yungsters

Differential Revision: D49895949

fbshipit-source-id: 37bb4d1fdf81137be7f14f6675b4e079c6f861e4
2023-10-04 19:57:14 -07:00
Nick Gerleman
2734784ddb Fix style resolution functions returning FloatOptional (#1404)
Summary:
X-link: https://github.com/facebook/react-native/pull/39595

Pull Request resolved: https://github.com/facebook/yoga/pull/1404

These functions all ensure their returns are defined, but return FloatOptional anyway, making their callers have to deal with that possibility. Return `float` instead of `FloatOptional`, and do some additional cleanup.

Reviewed By: rshest

Differential Revision: D49531421

fbshipit-source-id: 95b21cade74e501dd54c7b6ca667c8c3859c5dae
2023-10-03 15:36:01 -07:00
Joe Vilches
ce8fe99bf9 Fix typo on aspect ratio page
Summary: Was reading https://yogalayout.com/docs/aspect-ratio and noticed a typo. "Flexbox does has" -> "Flexbox does have"

Reviewed By: NickGerleman

Differential Revision: D49885138

fbshipit-source-id: 847b40eda257bd0726c3992a7285ac6fa267d418
2023-10-03 14:44:00 -07:00
Joe Vilches
e099449c37 Adding optional QOL flags to gentest
Summary:
This diff adds the ability to add 2 flags to gentest.rb that can help with debugging that I found myself wanting to use:

* The ability to suspend the script. Meaning the chrome browser will pause after running each fixture so the user can inspect elements to see if their html is as expected. Normally, the browser just redirects to the next fixture
* The ability to run a specific fixture instead of all fixtures. I found myself wanting to do this as I was changing one in the previous diff. If the user input is incorrect it just ignores it.

Hopefully this will help make debugging this script a bit easier for noobs like me :P

Reviewed By: NickGerleman

Differential Revision: D49775228

fbshipit-source-id: 29933029119ee5afc0195213df70d4d2cf881a9e
2023-10-03 11:31:34 -07:00
Joe Vilches
e60ae290ea Add fixtures to test proper margins with reverse flex directions
Summary:
Yoga has a known bug where marginStart and marginEnd will swap with row-reverse flex direction. This is not the intended behavior. On Paper this is also an issue with marginLeft and marginRight (at least we think Paper is the culprit, not exactly clear yet).

margin-start (and end) is not actually valid css. The gentest.rb script will just turn this into margin-left, but the cpp generated will properly test marginStart. This seems a bit weird to be since marginStart != marginLeft AFAIK. Things like RTL and LTR modes might make this test not exactly right. But given how many other tests depend on this quirk I think it is fine to add as is - the end result is the same after all. If not, a followup would be to add support for mapping margin-inline-start (valid css) to marginStart.

Anyway, this diff is to add test coverage for this scenario. Next stop is to actually try to fix this problem, which may be a bit harder :P

See https://github.com/facebook/yoga/issues/1208 for more info.

Reviewed By: NickGerleman

Differential Revision: D49744271

fbshipit-source-id: 75b8dd0cc5c53b2f338476fb70b60006aaa89054
2023-10-03 11:31:34 -07:00
Nick Gerleman
4ef28bce24 Remove usage of Gutters arrays and YGGutter as index (#1406)
Summary:
X-link: https://github.com/facebook/react-native/pull/39597

Pull Request resolved: https://github.com/facebook/yoga/pull/1406

Similar in vain to D49362819, we want to stop exposing pre-resolved CompactValue, and allow enum class usage without becoming annoying.

This also simplifies gap resolution a bit. I moved this to Style, to make it clear we aren't relying on any node state. I plan to do some similar cleanup for other resolution later.

Reviewed By: rshest

Differential Revision: D49530923

fbshipit-source-id: 47b06a7301fb283acc493dba159f496159d59580
2023-10-03 10:08:10 -07:00
jlmip
07cabca526 Fixed issue with first line element gap handling. (#1408)
Summary:
If the first element of a line is not contributing (e.g. position absolute), an additional gap will be added to the line, because the first gap element of the line is never identified (wrong start index).
Fix: raise the index of the first line element until we find an element that is contributing to the line.

Pull Request resolved: https://github.com/facebook/yoga/pull/1408

Reviewed By: yungsters

Differential Revision: D49722065

Pulled By: NickGerleman

fbshipit-source-id: 1068cb0b11ae4b04ec8d063e70540cce06181d5a
2023-10-03 06:24:48 -07:00
Nick Gerleman
b03a821884 Fix handling of negative flex gap (#1405)
Summary:
X-link: https://github.com/facebook/react-native/pull/39596

Pull Request resolved: https://github.com/facebook/yoga/pull/1405

I noticed that we weren't clamping negative flex gap values to zero. This fixes that bug.

Reviewed By: rshest

Differential Revision: D49530494

fbshipit-source-id: 069db7312f72a085c5c4b01ead7bc66a353a07e5
2023-09-30 21:09:13 -07:00
Nick Gerleman
a8566a0150 C++ style enums 16/N: Dimension (#1403)
Summary:
X-link: https://github.com/facebook/react-native/pull/39598

Pull Request resolved: https://github.com/facebook/yoga/pull/1403

Replaces all usages of YGDimension with Dimension.

Adds `yoga::to_underlying` to act like `std::to_underlying`, added in C++ 23.

This enum is oddly only used internally, and is never an input to the public API, but it handled as any other public generated enum. Potentially some more cleanup to do there.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49475409

fbshipit-source-id: 7d4c31e8a84485baea0dab50b5cf16b86769fa07
2023-09-29 00:06:34 -07:00
Nick Gerleman
8d24fcd90f Remove FloatOptional related TODOs
Summary:
These were added quite a while ago, and the proprosed change doesn't really make sense to pursue, since FloatOptional is a C++ wrapper around a Float, and the public API is entirely C.

bypass-github-export-checks

Reviewed By: rshest

Differential Revision: D49476343

fbshipit-source-id: f83cc99adda75fc0dba96e063cca92510c3d2ef0
2023-09-21 18:14:46 -07:00
Nick Gerleman
83705c2942 Remove usage of Dimension arrays and YGDimension as index (#1402)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1402

X-link: https://github.com/facebook/react-native/pull/39567

This change hides away most usages of YGDimension as an index. We do this for a couple reasons:

1. Right now the style interface may return a full array of resolved edge or dimension values, as a CompactValue. As we abstract away from CompactValue, and move towards ValuePool, this will no longer be the internal interface, and cheap to return. We instead change the interface to return a single value at once, which lets us resolve values lazily.

2. As we move internal usage to scoped enums, enums are not implicitly convertible to intergers (broadly a good thing). Hiding the enum as index prevents the need for callers to cast or convert to underlying.

Instead of making a new version of `IdxRef` for this, I converted to a more traditional setter. I will be making similar changes later for other styles, when I hide CompactValue from the public interface.

To review I would recommend filtering to changes in `xplat`, or viewing this in a single one of the OSS PRs exported. Everything apart from the below 20 files is a mirror.

{F1096792573}

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D49362819

fbshipit-source-id: 30d730d78e62f36597d43f477120f65694e51ea3
2023-09-20 16:19:59 -07:00
hetan thakkar
81754d8cb2 Fixed minor syntax error (#1363)
Summary:
I've corrected the operator syntax error. This error disrupts the execution of command: 'npx react-native run-ios.'

<img width="1440" alt="Screenshot 2023-09-08 at 8 04 49 PM" src="https://github.com/facebook/yoga/assets/38756320/b6a51270-8ae3-4d3f-be22-1fd938af42f8">

bypass-github-export-checks

Pull Request resolved: https://github.com/facebook/yoga/pull/1363

Reviewed By: yungsters

Differential Revision: D49118992

Pulled By: NickGerleman

fbshipit-source-id: 55c3ec7890a9682887d2d88e66400eb7f6613792
2023-09-20 08:34:18 -07:00
Nick Gerleman
6bc896e549 C++ style enums 15/N: Display (#1397)
Summary:
X-link: https://github.com/facebook/react-native/pull/39541

Pull Request resolved: https://github.com/facebook/yoga/pull/1397

Moves internal usages of YGDisplay to Display

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: sammy-SC

Differential Revision: D49361952

fbshipit-source-id: a961efaa35a3fed01659d23783bf90e0b47656f0
2023-09-19 16:30:02 -07:00
Nick Gerleman
75bbfb0b71 C++ style enums 14/N: Overflow (#1398)
Summary:
X-link: https://github.com/facebook/react-native/pull/39537

Pull Request resolved: https://github.com/facebook/yoga/pull/1398

Moves internal usages of YGOverflow to Overflow

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49361843

fbshipit-source-id: 42161aa8a26f64f052587b861120cdad0290ae46
2023-09-19 16:30:02 -07:00
Nick Gerleman
03d0523996 C++ style enums 13/N: Wrap (#1400)
Summary:
X-link: https://github.com/facebook/react-native/pull/39539

Pull Request resolved: https://github.com/facebook/yoga/pull/1400

Moves internal usages of YGPositionType to PositionType

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49361746

fbshipit-source-id: ccc77b4c77753b5f41e11f1849d4c02153c190b7
2023-09-19 16:30:02 -07:00
Nick Gerleman
4ea6b4c4f9 C++ Style enums 12/N: PositionType (#1399)
Summary:
X-link: https://github.com/facebook/react-native/pull/39538

Pull Request resolved: https://github.com/facebook/yoga/pull/1399

Moves internal usages of YGPositionType to PositionType

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49361677

fbshipit-source-id: 526222d6cf9f3dc26eddfbfb8a04de4ba28e14a9
2023-09-19 16:30:02 -07:00
Nick Gerleman
5bf81b1ef8 C++ style enums 11/N: Align (#1395)
Summary:
X-link: https://github.com/facebook/react-native/pull/39497

Pull Request resolved: https://github.com/facebook/yoga/pull/1395

Moves internal usages of YGAlign to Align

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49337511

fbshipit-source-id: bb9906fcd22780d2cfd8d1360ef69f66b9701bb6
2023-09-19 16:30:02 -07:00
Nick Gerleman
61763e7d0a C++ style enums 10/N: Justify (#1396)
Summary:
X-link: https://github.com/facebook/react-native/pull/39498

Pull Request resolved: https://github.com/facebook/yoga/pull/1396

Moves internal usages of YGJustify to Justify.

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49336538

fbshipit-source-id: 6deb2438e3cd2989c8212ee294fd0fe4819f40ab
2023-09-19 16:30:02 -07:00
Nick Gerleman
6ec790dd1b C++ style enums 9/N: FlexDirection (#1394)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1394

X-link: https://github.com/facebook/react-native/pull/39484

Moves internal usages of YGDirection to Direction.

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49336066

fbshipit-source-id: b49e1ffcd79a427e36ea8d2c26debaa98ef3e4c9
2023-09-19 16:30:02 -07:00
Nick Gerleman
9b99e4fc22 C++ style enums 8/N: Direction (#1392)
Summary:
X-link: https://github.com/facebook/react-native/pull/39483

Pull Request resolved: https://github.com/facebook/yoga/pull/1392

Moves internal usages of YGDirection to Direction.

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D49335231

fbshipit-source-id: 459fe820c91be88734cebaa8655cd3f0afda83bf
2023-09-19 16:30:02 -07:00
Nick Gerleman
ea3869fe9f Simplify bitfields (#1393)
Summary:
X-link: https://github.com/facebook/react-native/pull/39485

Pull Request resolved: https://github.com/facebook/yoga/pull/1393

These were previously packed into structs to allow zero initializing all the flags at once without needing a ctor. C++ 20 has in-class member initializer support for bitfields, which makes these look more like normal member variables.

Setting enum values is a bit jank right now, due to relying on C enums which are effectively int32_t, along with GCC `-Wconversion` being a bit aggressive in needing to explicitly mask. I have some ideas to fix this later (e.g. using scoped enums internally).

bypass-github-export-checks

Changelog:
[General][Breaking] - Require C++ 20 when including renderer headers

Reviewed By: sammy-SC

Differential Revision: D49265967

fbshipit-source-id: 6ab935a866196df06e742c821f3af88eb4d18e1a
2023-09-19 01:28:35 -07:00
Nick Gerleman
557d2a76fe Breaking: Use C++ 20 (#1382)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1382

X-link: https://github.com/facebook/react-native/pull/39437

Have been running into places where C++ 20 makes life easier for use like `std::bit_cast` (that one is easy to polyfill), in-class member initializer support for bitfields, designated initializers, defaulted comparison operator, concepts instead of SFINAE, and probably more.

Our other infra is in the process of making this jump, or already has. This tests it out everywhere, across the various reference builds, to see if we have any issues.

This is a bit more aggressive than I had previously communicated, but n - 1 is going to be a better long term place than n - 2.

If we wanted to use `std::bit_cast` we would need one of:
1. GCC 11+ (~2.5 years old)
1. Clang 14 (~2.5 years old)
1. VS 16.11 (~2 years old)

For mobile this means:
1. NDK 26 (still in Beta 😭)
1. XCode 14.3.0 (~6 months old)

https://en.cppreference.com/w/cpp/compiler_support/20

That isn't quite doable yet, but we can start taking advantage of language features in the meantime. More of these will be supported in older toolchains.

Anyone needing support for older C++ versions can lag behind on more recent changes. E.g. Yoga 2.0 supports C++ 14.

bypass-github-export-checks

Changelog: [Internal]

Reviewed By: cortinico

Differential Revision: D49261607

fbshipit-source-id: ceb06eac20dfe93352d7b796d6847a7314069cf3
2023-09-19 01:28:35 -07:00
Nick Gerleman
ed406f0b55 C++ style enums 7/N: MeasureMode (#1389)
Summary:
X-link: https://github.com/facebook/react-native/pull/39452

Pull Request resolved: https://github.com/facebook/yoga/pull/1389

This converts usages of YGMeasureMode to MeasureMode

Reviewed By: rozele

Differential Revision: D49271165

fbshipit-source-id: 273c9ed0a61c3965e469548d29d37e4566c974dc
2023-09-14 23:06:34 -07:00
Nick Gerleman
383b325d06 C++ style enums 6/N: PrintOptions (#1385)
Summary:
X-link: https://github.com/facebook/react-native/pull/39449

Pull Request resolved: https://github.com/facebook/yoga/pull/1385

This converts usages of YGPrintOptions to PrintOptions

Reviewed By: rozele

Differential Revision: D49270929

fbshipit-source-id: ad98dd25865138808d25b48eff22fbe81ccdd352
2023-09-14 23:06:34 -07:00
Nick Gerleman
70954bbda5 C++ style enums 5/N: LogLevel (#1387)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1387

X-link: https://github.com/facebook/react-native/pull/39447

This converts usages of YGLogLevel to LogLevel

Reviewed By: rozele

Differential Revision: D49270695

fbshipit-source-id: 2ba5b4f2b0af93fef89dbbb2ce54c2f486670aac
2023-09-14 23:06:34 -07:00
Nick Gerleman
6f5eaefc51 C++ style enums 4/N: Errata (#1388)
Summary:
X-link: https://github.com/facebook/react-native/pull/39451

Pull Request resolved: https://github.com/facebook/yoga/pull/1388

This converts usages of YGErrata to Errata

Reviewed By: rozele

Differential Revision: D49270354

fbshipit-source-id: 39c0d26a1609cca0a96da843796ab41c81e3af93
2023-09-14 23:06:34 -07:00
Nick Gerleman
42e1f2c737 C++ style enums 3/N: ExperimentalFeature (#1386)
Summary:
X-link: https://github.com/facebook/react-native/pull/39448

Pull Request resolved: https://github.com/facebook/yoga/pull/1386

This converts usages of YGExperimentalFeature to ExperimentalFeature

Reviewed By: rozele

Differential Revision: D49269440

fbshipit-source-id: 0fcb4f380e214a6aadcac457df5a989789bb05d2
2023-09-14 23:06:34 -07:00
Nick Gerleman
9129a0af87 C++ style enums 2/N: NodeType (#1383)
Summary:
X-link: https://github.com/facebook/react-native/pull/39450

Pull Request resolved: https://github.com/facebook/yoga/pull/1383

This converts usages of YGNodeType to NodeType

Reviewed By: rozele

Differential Revision: D49269117

fbshipit-source-id: 27318279fe555c28c605625a160d5be781b662b8
2023-09-14 23:06:34 -07:00
Nick Gerleman
4cd45ac5d5 C++ style enums 1/N: Generator (#1384)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1384

X-link: https://github.com/facebook/react-native/pull/39446

This adds logic to the enum generator to generate C++ style scoped enums.

This gives us a few nicities over C enums, even if both must exist:
1. We can add types and keep unsgined enums directly in bitfields
2. Style/readability
3. Avoiding implicit int conversion

Reviewed By: rozele

Differential Revision: D49267996

fbshipit-source-id: 1c41164c377b317c1fef97811c46cbc00b5a837e
2023-09-14 23:06:34 -07:00
Nick Gerleman
c60050d0cb Fixup hack for flex line size calculation (#1380)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1380

X-link: https://github.com/facebook/react-native/pull/39433

Back when rolling out flex gap, we encountered a bug where gap was added to the end of the main axis when a size was not specified.

During flex line justification/sizing, we calculate the amount of space that should be in between children. We erroneously add this, even after the last child element.

For `justify-content`, this space between children is derived from free space along the axis. The only time we have free space is if we had a dimension/dimension constraint already set on the parent. In this case, the extra space added to the end of the flex line is usually never noticed, because we bound `maxLineMainDim` to container dimension constraints at the end of layout, and the error doesn't effect how any children are positioned or sized.

There was at least one screenshot test where this issue showed up though, and I was able to add a slightly different repro where we may have free space without a definite dimension by enforcing a min dimension and not stretching.

{F1091401183}

The new reference is correct, and looking back at diffs, is what this seemed to originally look like when added three years ago. Seems like there may have been a potential regression, but I didn't spot anything suspicious when I looked around the code history.

`betweenMainDim` may still be set for `gap` even if we don't have a sized parent, which makes the extra space propagated to `maxLineMainDim` effect parent size.

Because we were in a code freeze, I opted to have us go with a solution just effecting flex gap, instead of the right one, in case there were any side effects. This cleans up the code to use the right calculation everywhere, and fixes a separate bug, where `endOfLineIndex` and `startOfLineIndex` may not be the last/first in the line if they are out of the layout flow (absolutely positioned, or display: none_

See the original conversation on https://github.com/facebook/yoga/pull/1188

Reviewed By: javache

Differential Revision: D49260049

fbshipit-source-id: 218552c5ff938668b9f257df7a1493e13ded4d0d
2023-09-14 20:26:31 -07:00
Nick Gerleman
f9c2c27d33 Use fbsource clang-format config
Summary:
This mirrors the clang-format config used by fbsource to Yoga.

They are pretty similar, except for an annoying habit where Yoga's previous forced small functions in headers to be a a single line, so you would get a combination of multiline and single line functions next to each other which are hard to read. That is what motivated this change.

It also enforces header ordering (yay). I don't think we have any side-effect causing headers, so this should be safe.

Reviewed By: yungsters

Differential Revision: D49248994

fbshipit-source-id: 66998395e7c0158ff9d9fb1bee44e8401bdd8f21
2023-09-13 20:12:55 -07:00
Nick Gerleman
9d21e3e300 Remove config drilling (#1378)
Summary:
X-link: https://github.com/facebook/react-native/pull/39404

Pull Request resolved: https://github.com/facebook/yoga/pull/1378

We thread a config through the root node, to every function, that we don't actually use (with the exception of `canUseCachedMeasurement` in the previous diff which was passing root `pointScaleFactor`).

Since the model is currently per-node config, this only creates redundancy/confusion.

I do think we might want to make some more global/layout-pass scoped configuration in the future, but likely not with this sort of drilling.

Reviewed By: yungsters

Differential Revision: D49180385

fbshipit-source-id: 91248042df7d3cea1fc316b47b8137fcb790b521
2023-09-13 20:12:55 -07:00
Nick Gerleman
66cc95f932 Breaking: per-node pointScaleFactor (#1379)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1379

X-link: https://github.com/facebook/react-native/pull/39403

Right now we have a `pointScaleFactor` per-node, but only ever read the one off the root node. In most cases where config is global, these will be the same, but it is possible for these to differ.

This... doesn't make much sense from an API perspective, and there are edge cases where we may want to allow laying out a subtree with a different DPI then the rest of the tree (though I think there might be other solutions to that).

We should rethink some of what is currently on config being allowed per-node (do we really need each node to be able to have a separate logger?), but this makes the model consistent in the meantime.

This change is breaking to any users relying on setting `pointScaleFactor` on the config of the root node, but not other nodes.

Reviewed By: yungsters

Differential Revision: D49181131

fbshipit-source-id: f1363ca242094f04b995fd50c1e56834d5003425
2023-09-13 14:11:25 -07:00
Nick Gerleman
0a90b16ac6 Remove layoutContext Drilling (#1376)
Summary:
X-link: https://github.com/facebook/react-native/pull/39401

Pull Request resolved: https://github.com/facebook/yoga/pull/1376

kill_with_fire_flamethrower

Reviewed By: rshest

Differential Revision: D49179244

fbshipit-source-id: 9a827e1bd29205254fee5725449191726d6bcf5a
2023-09-12 19:08:55 -07:00
Nick Gerleman
b1e0140aaa Remove JNI Binding usage of layoutContext (#1377)
Summary:
X-link: https://github.com/facebook/react-native/pull/39402

Pull Request resolved: https://github.com/facebook/yoga/pull/1377

To avoid keeping a per-node mapping on native Yoga nodes to Java nodes, a per-layout context was added, to be able to pass information from the start of the layout, to measure functions, log functions, etc.

The way this was done was super invasive, and added quite a few private APIs used only by the JNI functions.

This change removes the context-using functions from the JNI bindings in favor of it managing its own context. Next diff removes all the cruft.

Reviewed By: javache

Differential Revision: D49179243

fbshipit-source-id: 7e4944bead864e6b73fd2208a47c5725c18ff2b0
2023-09-12 19:08:55 -07:00
Nick Gerleman
700be8c8ad Extract isBaselineLayout() (#1375)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1375

X-link: https://github.com/facebook/react-native/pull/39400

Moves `isBaselineLayout` out of `CalculateLayout` into `Baseline.h`. This function is called by flex line justification code, which I have been looking at extracting.

Reviewed By: yungsters

Differential Revision: D49177937

fbshipit-source-id: 02c13aa0b02b26cb60ef197473b90e06d53d5f8d
2023-09-12 19:08:55 -07:00
Nick Gerleman
62ba8ebb3d Replace dim and pos arrays (#1373)
Summary:
X-link: https://github.com/facebook/react-native/pull/39397

Pull Request resolved: https://github.com/facebook/yoga/pull/1373

These are used to get the position origin edge from axis (same as leading edge), and dimension from axis.

Replace them with function usage, so that we can call into them from other files than `CalculateLayout.cpp`, and so that we can later use scoped enums not implicitly convertible to ints.

Reviewed By: rshest

Differential Revision: D49134566

fbshipit-source-id: cb806539ba0733a5773c594713720d465987e469
2023-09-11 19:51:40 -07:00
Nick Gerleman
a4f36bdb51 Separate FlexLine functionality (#1374)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1374

X-link: https://github.com/facebook/react-native/pull/39396

Yoga today has a struct `CollectFlexItemsRowValues`, and function `calculateFlexItemsRowValues()`. These names have evolved over time into something not making much sense.

The job of `calculateFlexItemsRowValues()` is a flex-wrap container into lines (i.e. line-breaking main-axis content, which may be row or column). It returns line-breaking results, but some other fields on `calculateFlexItemsRowValues()` are set much later in the process, and the struct is acting effectivelty as a holder for the line-specific values.

This change:
1. Does some renaming (mainly to FlexLine)
2. Reconciles the count `itemsOnLine` and list `relativeChildren` to list `itemsInFlow` (`relativeChildren` is a lie, as it can include elements with `YGPositionTypeStatic` and exclude relative elements which have `display: "none"`. It really just means children which are included in the layout flow for the line)
3. Makes non-changing algorithm outputs const for clarity of what is a running value, and what is a result of line-breaking values with flex basis.
4. Moves working layout values to a substructure `flexLine.layout`
5. Replaces some dishonest documentation about `endOfLineIndex`.
6. Extracts this logic out of `CalculateLayout()` to a separate file
7. Extracts `boundAxis` wholesale into a separate file, to be usable outside of `CalculateLayout.cpp`

Reviewed By: rshest

Differential Revision: D49133837

fbshipit-source-id: ec68c5a3d2f01e7c9bd8d26e28298331a3fe2475
2023-09-11 19:51:40 -07:00
Nick Gerleman
241c5e4baf Cleanup visibility macros (#1372)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1372

X-link: https://github.com/facebook/react-native/pull/39375

D18029030 added `-fvisibility-hidden`, and a corresponding `YOGA_EXPORT` macro for defining shared library visibility. This is used inline next to function and class definitions that should be exported out of the binary.

There was already a `WIN_EXPORT` macro doing the same thing when building a DLL, defined in the headers instead of CPP files, and it seems like sometimes folks forgot to add it to new public APIs after?

This reconciles the redundant macros into a single visibility macro, that we always place with declaration instead of definition. We also rename `YOGA_EXPORT` to `YG_EXPORT` to match the naming convention of other Yoga macros.

Reviewed By: rshest

Differential Revision: D49132643

fbshipit-source-id: cafa6de0c300788a72d9a446ce07c5ac89a20a8e
2023-09-11 19:51:40 -07:00
Nick Gerleman
0720e0b22a Breaking: YGConfigRef related const-correctness fixes (#1371)
Summary:
X-link: https://github.com/facebook/react-native/pull/39374

Pull Request resolved: https://github.com/facebook/yoga/pull/1371

Right now `YGConfigGetDefault` and `YGNodeGetConfig` both return mutable, freeable, configs, which is bad, since the former points to a global singleton config, and the latter usually does too. Mutating this is not thread safe, and it should never be freed.

This change makes these functions return `YGConfigConstRef` to prevent mutation, and also lets us allow `YGConfigNewWithConfig` to accept a const config. If a caller does want to mutate a config (such as to free it), it must be tracked manually.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D49132476

fbshipit-source-id: ac9ce61149e69c6c25cadb99711435b0a5b9f38a
2023-09-11 19:51:40 -07:00
Nick Gerleman
a003c09a4c Cleanup Android logger code (#1367)
Summary:
X-link: https://github.com/facebook/react-native/pull/39373

Pull Request resolved: https://github.com/facebook/yoga/pull/1367

Moves some messiness around conditionally using Android's logger to `Log.cpp`, isolated to within a single function.

Reviewed By: rshest

Differential Revision: D49131964

fbshipit-source-id: cdff8af1d4df6ae28f00eecfed1920c71eec24d0
2023-09-11 19:51:40 -07:00