Compare commits

..

19 Commits

Author SHA1 Message Date
Mateo Guzmán
16c82cac8b Update enums.py to generate Kotlin files 2025-08-09 12:05:19 +02:00
Mateo Guzmán
8bf7a34d02 Initial Kotlin setup and migrate YogaConstants (#1829)
Summary:
X-link: https://github.com/facebook/react-native/pull/53133

# Changelog:
[Internal] -

As part of the ongoing effort to migrate the React Native codebase to Kotlin, this PR introduces the initial setup required for Kotlin support in Yoga.

- Added initial basic Kotlin configuration to the project.
- Migrated `YogaConstants` as an initial file to try out the first migration steps.

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

Test Plan:
- Tested the migrated class directly against facebook/react-native, see the PR [here](https://github.com/facebook/react-native/pull/52998).
- Run: `./gradlew :yoga:assembleDebug` & `./gradlew :yoga:compileDebugSources`

I am not able to run the Java tests in this repo (even before the initial Kotlin setup) – not sure if I am missing something there but any pointers are welcome – it seems like there is some missing configuration. Currently trying with `./gradlew :yoga:test`

Reviewed By: cortinico

Differential Revision: D79545992

Pulled By: rshest

fbshipit-source-id: 8257ff53e6b6f2436980be98b6c94e1ac526b207
2025-08-07 08:17:56 -07:00
Dmitry Polukhin
82671c0132 Disable modernize-avoid-c-arrays in xplat/yoga/tests
Reviewed By: JuanBesa, rshest

Differential Revision: D79247609

fbshipit-source-id: 529ba950ab200c46493152b81dece6bd76f6fdbd
2025-07-30 03:39:00 -07:00
Alexey Medvedev
9f2a9476e5 Make yoga/Yoga.h an umbrell header (#1828)
Summary:
X-link: https://github.com/facebook/react-native/pull/52817

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

X-link: https://github.com/facebook/litho/pull/1070

This diff makes the Yoga/Yoga.h header an umbrella header, which means that it includes all of Yoga's public headers. The code changes in each file include adding the IWYU pragma export to each header file, which is a way to tell the compiler to export the header file's symbols to other files that include it. This is necessary for the header file to be used as an umbrella header.

Changelog:
[General][Added] - Code quality fixes

Reviewed By: corporateshark

Differential Revision: D78692457

fbshipit-source-id: 7fcd53d2a6f268fa4377dbd5bd6ba6eebc94b5f8
2025-07-24 16:51:13 -07:00
Jakub Piasecki
c7c85621fc Fix display: contents nodes not being cloned with the wrong owner (#1826)
Summary:
X-link: https://github.com/facebook/react-native/pull/52530

This PR fixes two issues with `display: contents` implementation:
1. When a node with `display: contents` set is a leaf, it won't be cloned after the initial tree is built. The added test case covers this scenario.
2. It was possible for the subtree of `display: contents` nodes not to be cloned during layout. I don't have a minimal reproduction for this one, unfortunately. It was discovered in the Expensify app: https://github.com/Expensify/App/issues/65268, along with a consistent reproduction. In that specific case, it seems to be heavily tied to `react-native-onyx`, which is a state management library.

Changelog: [GENERAL][FIXED] - Fixed nodes with `display: contents` set being cloned with the wrong owner

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

Reviewed By: adityasharat, NickGerleman

Differential Revision: D78084270

Pulled By: j-piasecki

fbshipit-source-id: eb81f6d7dcd1665974d07261ba693e2abea239bb
2025-07-11 02:16:35 -07:00
Nolan O'Brien
73980a3cf8 Fix exhaustive switches
Summary:
X-link: https://github.com/facebook/react-native/pull/52379

Changelog: [General][Fixed] - Add `default:` case to avoid warnings/errors for targets that compile with `-Wswitch-enum` and `-Wswitch-default` enabled

Reviewed By: aary, yungsters, astreet

Differential Revision: D77051152

fbshipit-source-id: 100b10f97cb3a5d73f1e3dcaf1b284baf6a43982
2025-07-02 14:21:18 -07:00
Nick Gerleman
4b5ca50117 Reland Fix possible invalid measurements when width or height is zero pixels (#1823)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1823

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

Fixes https://github.com/facebook/yoga/issues/1819

Yoga has a fast path when measuring a node, if it thinks it knows its dimensions ahead of time.

This path has some eroneous logic, to set both axis to owner size, if *either* will evaluate to zero, while having an `YGMeasureModeAtMost`/`FitContent` constraint. This means that if a node is given a zero width, and Yoga later measures with with `FitContent`, its height will become the maximum allowable height, even if it shouldn't be that large.

We can fix this, by only allowing if both axis are this fixed case, instead of just one.

This bug has existed for about a decade (going back to at least D3312496).

Changelog:
[General][Fixed] - Fix possible invalid measurements with width or height is zero pixels

Reviewed By: yungsters

Differential Revision: D76851589

fbshipit-source-id: 6f5a0e6beccc51f591726c9e83e9b90f3350ed0f
2025-06-30 20:46:39 -07:00
FBLite Revert Bot
30291398f3 Revert D76793705: Fix possible invalid measurements when width or height is zero pixels
Differential Revision:
D76793705

Original commit changeset: ea4c00e68891

Original Phabricator Diff: D76793705

fbshipit-source-id: 95d6b66ab08e073da9fb07fd4094a7e30e2f453b
2025-06-17 14:33:32 -07:00
Nick Gerleman
27d632c697 Fix possible invalid measurements when width or height is zero pixels (#1820)
Summary:
X-link: https://github.com/facebook/react-native/pull/52073

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

Fixes https://github.com/facebook/yoga/issues/1819

Yoga has a fast path when measuring a node, if it thinks it knows its dimensions ahead of time.

This path has some eroneous logic, to set both axis to owner size, if *either* will evaluate to zero, while having an `YGMeasureModeAtMost`/`FitContent` constraint. This means that if a node is given a zero width, and Yoga later measures with with `FitContent`, its height will become the maximum allowable height, even if it shouldn't be that large.

We can fix this, by only allowing if both axis are this fixed case, instead of just one.

This bug has existed for about a decade (going back to at least D3312496).

Changelog:
[General][Fixed] - Fix possible invalid measurements with width or height is zero pixels

Reviewed By: yungsters

Differential Revision: D76793705

fbshipit-source-id: ea4c00e688912a58c08801e4a14ddf1b293a5d86
2025-06-17 12:15:55 -07:00
Nicola Corti
117fa494f7 Migrate from OSSRH to Central Portal (#1816)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1816

This migrates Yoga to publish to Central Portal rather than OSSRC

Reviewed By: NickGerleman

Differential Revision: D76436235

fbshipit-source-id: ddaaa95472054aa2b09399b5cc8d821dae51234f
2025-06-11 16:12:06 -07:00
Nicola Corti
073c136117 Remove unnecessary gradle-enterprise.gradle.kts from Yoga (#1817)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1817

This file is not really necessary. As we don't have a Gradle Enterprise instance anymore, let's just remove it and inline it.

Reviewed By: mdvacca

Differential Revision: D76436236

fbshipit-source-id: 27fcc48574905415b147f67dd4a8f57dffbeda3e
2025-06-11 11:46:34 -07:00
Nick Gerleman
1232761571 YGPersistentNodeCloningTest (#1813)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1813

This adds a unit test to Yoga, which emulates the model of "persistent Yoga nodes" and cloning used by React Fabric, including the private (but relied on) Yoga APIs.

It models the over-invalidation exposed in D75287261, which reproduces (due to Yoga incorrectly measuring flex-basis under fit-content, and that constraint changing when sibling changes) but this test for now sets a definite height on A, to show that we only clone what is neccesary, when measure constraints do not have to change.

Having a minimal version of Fabric's model in Yoga unit tests should make some of these interesting interactions a bit easier to debug.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D75572762

fbshipit-source-id: cda8b3fdd6e538a55dd100494518688c864bd233
2025-06-02 19:32:45 -07:00
Nick Gerleman
c935fd5e10 Resubmit: Expose Unsnapped Dimensions (#1811)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1811

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

## Resubmit

This was backed out due to being up the stack from another change that was backed out, but should be safe by itself.

## Original

We want to know if an artifact created during measurement can fully be reused after final layout, but the final layout is allowed to be slightly larger due to pixel grid rounding (while still allowing reuse). It's hard to tell after the fact, whether it is larger because of this rounding (though the measure is used), or if it may be a pixel larger for valid reasons.

We can expose the unsnapped dimensions of a node to give us this information, and to correlate measurement artifacts.

This is most of the time the same as the layout's measured dimension, though I don't think it's safe to use this, since anything else measuring the node after could clobber this (I think `YGNodeLayoutGetOverflow` may also be prone to this as a bug).

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D74673119

fbshipit-source-id: 06d2eb21e28b76458ec88f4dfcaec809707d0390
2025-05-13 18:21:04 -07:00
Yannick Loriot
624325302c Revert D74292949: Expose Unsnapped Dimensions
Differential Revision:
D74292949

Original commit changeset: 05011c66a9a9

Original Phabricator Diff: D74292949

fbshipit-source-id: c6ca51c7b882950d54b6a43e206973774db40429
2025-05-09 01:45:16 -07:00
Nick Gerleman
37a94a86de Expose Unsnapped Dimensions (#1809)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1809

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

We want to know if an artifact created during measurement can fully be reused after final layout, but the final layout is allowed to be slightly larger due to pixel grid rounding (while still allowing reuse). It's hard to tell after the fact, whether it is larger because of this rounding (though the measure is used), or if it may be a pixel larger for valid reasons.

We can expose the unsnapped dimensions of a node to give us this information, and to correlate measurement artifacts.

This is most of the time the same as the layout's measured dimension, though I don't think it's safe to use this, since anything else measuring the node after could clobber this (I think `YGNodeLayoutGetOverflow` may also be prone to this as a bug).

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D74292949

fbshipit-source-id: 05011c66a9a9480544313eb1dfe2c46bf7742bac
2025-05-08 17:45:16 -07:00
Santhosh Kumar
4abc1a7d5f Fix documentation of 'alignContent' property configured with spaces (#1808)
Summary:
The documentation shall be corrected to specify in which axis the spaces are distributed when flex container is configured 'alignContent' property.

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

Reviewed By: joevilches

Differential Revision: D74347272

Pulled By: philIip

fbshipit-source-id: 1b05840028bca774c9d4a68562bcf537d5a72500
2025-05-07 14:40:02 -07:00
Yurii Nakonechnyi
51e6095005 LayoutData - added explicit default fields values initialization (#1802)
Summary:
X-link: https://github.com/facebook/react-native/pull/50227

Explicit defaults add 'strictness' and take the guesswork out of what's going on in places like this:

6455a848a7/yoga/algorithm/CalculateLayout.cpp (L2345)

Changelog: [Internal]

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

Reviewed By: javache

Differential Revision: D71687310

Pulled By: NickGerleman

fbshipit-source-id: f11d18aa68ce7ccd17fb1d5af0e729e8c0711cf9
2025-03-24 12:23:46 -07:00
Yurii Nakonechnyi
79cef614ce fatalWithMessage() - added warning suppression: unused 'message' argument (#1803)
Summary:
X-link: https://github.com/facebook/react-native/pull/50148

## Changelog:

[Internal] - suppression: unused 'message' argument

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

Reviewed By: NickGerleman

Differential Revision: D71492528

Pulled By: lunaleaps

fbshipit-source-id: 6fc7a665066351d15e09f0b6c82ed1fe3f688a94
2025-03-19 19:06:50 -07:00
Rob Hogan
6455a848a7 Update GHA actions/upload-artifact to v4, unbreak CI (#1799)
Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1799

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

`actions/upload-artifact@v3` is deprecated and will no longer execute, causing CI to fail - eg:

https://github.com/facebook/yoga/actions/runs/13789185831/job/38564343959

See https://github.blog/changelog/2024-04-16-deprecation-notice-v3-of-the-artifact-actions/ for context

Reviewed By: NickGerleman

Differential Revision: D70986391

fbshipit-source-id: 66cec50bb485e89c0948c752ba7dc2a4f42617d6
2025-03-11 13:40:51 -07:00
29 changed files with 725 additions and 131 deletions

3
.gitignore vendored
View File

@@ -73,3 +73,6 @@ local.properties
# Docusarus build # Docusarus build
.docusaurus .docusaurus
# Android Studio
.idea

View File

@@ -9,6 +9,7 @@ plugins {
id("com.android.library") version "8.7.1" apply false id("com.android.library") version "8.7.1" apply false
id("com.android.application") version "8.7.1" apply false id("com.android.application") version "8.7.1" apply false
id("io.github.gradle-nexus.publish-plugin") version "1.3.0" id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id 'org.jetbrains.kotlin.android' version '2.1.20' apply false
} }
allprojects { allprojects {
@@ -34,6 +35,8 @@ nexusPublishing {
sonatype { sonatype {
username.set(sonatypeUsername) username.set(sonatypeUsername)
password.set(sonatypePassword) password.set(sonatypePassword)
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
} }
} }
} }

View File

@@ -84,6 +84,12 @@ ENUMS = {
], ],
} }
# Temporary filter enums to not upgrade all enums at once
KOTLIN_ENUM_NAMES = {"Direction"}
ENUMS_KOTLIN = {name: ENUMS[name] for name in KOTLIN_ENUM_NAMES}
ENUMS_JAVA = {name: values for name, values in ENUMS.items() if name not in KOTLIN_ENUM_NAMES}
DO_NOT_STRIP = ["LogLevel"] DO_NOT_STRIP = ["LogLevel"]
BITSET_ENUMS = ["Errata"] BITSET_ENUMS = ["Errata"]
@@ -120,6 +126,9 @@ def to_java_upper(symbol):
return _format_name(symbol, "_", "upper") return _format_name(symbol, "_", "upper")
def to_kotlin_upper(symbol):
return _format_name(symbol, "_", "upper")
def to_hyphenated_lower(symbol): def to_hyphenated_lower(symbol):
return _format_name(symbol, "-", "lower") return _format_name(symbol, "-", "lower")
@@ -215,7 +224,7 @@ with open(root + "/yoga/YGEnums.cpp", "w") as f:
f.write("\n") f.write("\n")
# write out java files # write out java files
for name, values in sorted(ENUMS.items()): for name, values in sorted(ENUMS_JAVA.items()):
with open(root + "/java/com/facebook/yoga/Yoga%s.java" % name, "w") as f: with open(root + "/java/com/facebook/yoga/Yoga%s.java" % name, "w") as f:
f.write(get_license("java")) f.write(get_license("java"))
f.write("package com.facebook.yoga;\n\n") f.write("package com.facebook.yoga;\n\n")
@@ -267,6 +276,48 @@ for name, values in sorted(ENUMS.items()):
f.write(" }\n") f.write(" }\n")
f.write("}\n") f.write("}\n")
# write out Kotlin files
for name, values in sorted(ENUMS_KOTLIN.items()):
with open(root + "/java/com/facebook/yoga/Yoga%s.kt" % name, "w") as f:
f.write(get_license("kotlin"))
f.write("package com.facebook.yoga\n\n")
f.write("public enum class Yoga%s(public val intValue: Int) {\n" % name)
if len(values) > 0:
for value in values:
if isinstance(value, tuple):
f.write(" %s(%d)" % (to_kotlin_upper(value[0]), value[1]))
else:
f.write(" %s(%d)" % (to_kotlin_upper(value), values.index(value)))
if values.index(value) is len(values) - 1:
f.write(";\n")
else:
f.write(",\n")
else:
f.write("__EMPTY(-1);")
f.write("\n")
f.write(" public fun intValue(): Int = intValue\n")
f.write("\n")
f.write(" public companion object {\n")
f.write(" @JvmStatic\n")
f.write(" public fun fromInt(value: Int): Yoga%s =\n" % name)
f.write(" when (value) {\n")
for value in values:
if isinstance(value, tuple):
f.write(
" %d -> %s\n" % (value[1], to_kotlin_upper(value[0]))
)
else:
f.write(
" %d -> %s\n"
% (values.index(value), to_kotlin_upper(value))
)
f.write(
' else -> throw IllegalArgumentException("Unknown enum value: $value")\n'
)
f.write(" }\n")
f.write(" }\n")
f.write("}\n")
# write out TypeScript file # write out TypeScript file
with open(root + "/javascript/src/generated/YGEnums.ts", "w") as f: with open(root + "/javascript/src/generated/YGEnums.ts", "w") as f:
f.write(get_license("js")) f.write(get_license("js"))

View File

@@ -240,3 +240,14 @@
<div style="position:relative; width:50px; height:50px;"> <div style="position:relative; width:50px; height:50px;">
</div> </div>
</div> </div>
<div id="align_items_non_stretch_s526008"
style="flex-direction: column; width: 400px; height: 400px;">
<div style="flex-direction: row;">
<div style="flex-direction: column; align-items: flex-start;">
<div>
<div style="width: 0; height: 10px;"></div>
</div>
</div>
</div>
</div>

View File

@@ -1,17 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// You can use this script to configure the gradleEnterprise{} block in your build.
// You need to rename this file to ./gradle/gradle-enterprise.gradle.kts in order for
// this to be processed.
extensions.getByName("gradleEnterprise").withGroovyBuilder {
setProperty("server", "https://your-gradle-enterprise-instance.example.com")
getProperty("buildScan").withGroovyBuilder {
"publishAlways"()
"tag"(if(System.getenv("CI") != null) "CI" else "Local")
}
}

View File

@@ -9,6 +9,7 @@ plugins {
id("com.android.library") id("com.android.library")
id("maven-publish") id("maven-publish")
id("signing") id("signing")
id("org.jetbrains.kotlin.android")
} }
group = "com.facebook.yoga" group = "com.facebook.yoga"
@@ -48,6 +49,8 @@ android {
} }
} }
kotlinOptions { jvmTarget = "1.8" }
publishing { publishing {
multipleVariants { multipleVariants {
withSourcesJar() withSourcesJar()
@@ -60,6 +63,7 @@ android {
dependencies { dependencies {
implementation("com.google.code.findbugs:jsr305:3.0.2") implementation("com.google.code.findbugs:jsr305:3.0.2")
implementation("com.facebook.soloader:soloader:0.10.5") implementation("com.facebook.soloader:soloader:0.10.5")
implementation("androidx.core:core-ktx:1.16.0")
testImplementation("junit:junit:4.12") testImplementation("junit:junit:4.12")
} }

View File

@@ -1,25 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.yoga;
public class YogaConstants {
public static final float UNDEFINED = Float.NaN;
public static boolean isUndefined(float value) {
return Float.compare(value, UNDEFINED) == 0;
}
public static boolean isUndefined(YogaValue value) {
return value.unit == YogaUnit.UNDEFINED;
}
public static float getUndefined() {
return UNDEFINED;
}
}

View File

@@ -0,0 +1,18 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.yoga
public object YogaConstants {
@JvmField public val UNDEFINED: Float = Float.NaN
@JvmStatic public fun isUndefined(value: Float): Boolean = value.compareTo(UNDEFINED) == 0
@JvmStatic public fun isUndefined(value: YogaValue): Boolean = value.unit == YogaUnit.UNDEFINED
@JvmStatic public fun getUndefined(): Float = UNDEFINED
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @generated by enums.py
package com.facebook.yoga;
public enum YogaDirection {
INHERIT(0),
LTR(1),
RTL(2);
private final int mIntValue;
YogaDirection(int intValue) {
mIntValue = intValue;
}
public int intValue() {
return mIntValue;
}
public static YogaDirection fromInt(int value) {
switch (value) {
case 0: return INHERIT;
case 1: return LTR;
case 2: return RTL;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
}

View File

@@ -0,0 +1,29 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// @generated by enums.py
package com.facebook.yoga
public enum class YogaDirection(public val intValue: Int) {
INHERIT(0),
LTR(1),
RTL(2);
public fun intValue(): Int = intValue
public companion object {
@JvmStatic
public fun fromInt(value: Int): YogaDirection =
when (value) {
0 -> INHERIT
1 -> LTR
2 -> RTL
else -> throw IllegalArgumentException("Unknown enum value: $value")
}
}
}

View File

@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @generated SignedSource<<e8d11c0e97041bb2f1487f0d87363fdc>> * @generated SignedSource<<84597dd8b2c4f3aac1f21abe68f25308>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignItemsTest.html * generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignItemsTest.html
*/ */
@@ -2293,6 +2293,86 @@ public class YGAlignItemsTest {
assertEquals(50f, root_child1.getLayoutHeight(), 0.0f); assertEquals(50f, root_child1.getLayoutHeight(), 0.0f);
} }
@Test
public void test_align_items_non_stretch_s526008() {
YogaConfig config = YogaConfigFactory.create();
final YogaNode root = createNode(config);
root.setPositionType(YogaPositionType.ABSOLUTE);
root.setWidth(400f);
root.setHeight(400f);
final YogaNode root_child0 = createNode(config);
root_child0.setFlexDirection(YogaFlexDirection.ROW);
root.addChildAt(root_child0, 0);
final YogaNode root_child0_child0 = createNode(config);
root_child0_child0.setAlignItems(YogaAlign.FLEX_START);
root_child0.addChildAt(root_child0_child0, 0);
final YogaNode root_child0_child0_child0 = createNode(config);
root_child0_child0.addChildAt(root_child0_child0_child0, 0);
final YogaNode root_child0_child0_child0_child0 = createNode(config);
root_child0_child0_child0_child0.setHeight(10f);
root_child0_child0_child0.addChildAt(root_child0_child0_child0_child0, 0);
root.setDirection(YogaDirection.LTR);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(400f, root.getLayoutWidth(), 0.0f);
assertEquals(400f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(400f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0_child0_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0_child0_child0_child0.getLayoutHeight(), 0.0f);
root.setDirection(YogaDirection.RTL);
root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(0f, root.getLayoutX(), 0.0f);
assertEquals(0f, root.getLayoutY(), 0.0f);
assertEquals(400f, root.getLayoutWidth(), 0.0f);
assertEquals(400f, root.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0.getLayoutY(), 0.0f);
assertEquals(400f, root_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0.getLayoutHeight(), 0.0f);
assertEquals(400f, root_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0_child0_child0.getLayoutHeight(), 0.0f);
assertEquals(0f, root_child0_child0_child0_child0.getLayoutX(), 0.0f);
assertEquals(0f, root_child0_child0_child0_child0.getLayoutY(), 0.0f);
assertEquals(0f, root_child0_child0_child0_child0.getLayoutWidth(), 0.0f);
assertEquals(10f, root_child0_child0_child0_child0.getLayoutHeight(), 0.0f);
}
private YogaNode createNode(YogaConfig config) { private YogaNode createNode(YogaConfig config) {
return mNodeFactory.create(config); return mNodeFactory.create(config);
} }

View File

@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the * This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* @generated SignedSource<<075a0b67003e5c4a1f51bd99da71c700>> * @generated SignedSource<<fd80af208d8635435f86ffa8f3810b39>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignItemsTest.html * generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignItemsTest.html
*/ */
@@ -2442,3 +2442,88 @@ test('align_stretch_with_row_reverse', () => {
config.free(); config.free();
} }
}); });
test('align_items_non_stretch_s526008', () => {
const config = Yoga.Config.create();
let root;
try {
root = Yoga.Node.create(config);
root.setPositionType(PositionType.Absolute);
root.setWidth(400);
root.setHeight(400);
const root_child0 = Yoga.Node.create(config);
root_child0.setFlexDirection(FlexDirection.Row);
root.insertChild(root_child0, 0);
const root_child0_child0 = Yoga.Node.create(config);
root_child0_child0.setAlignItems(Align.FlexStart);
root_child0.insertChild(root_child0_child0, 0);
const root_child0_child0_child0 = Yoga.Node.create(config);
root_child0_child0.insertChild(root_child0_child0_child0, 0);
const root_child0_child0_child0_child0 = Yoga.Node.create(config);
root_child0_child0_child0_child0.setHeight(10);
root_child0_child0_child0.insertChild(root_child0_child0_child0_child0, 0);
root.calculateLayout(undefined, undefined, Direction.LTR);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(400);
expect(root.getComputedHeight()).toBe(400);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(400);
expect(root_child0.getComputedHeight()).toBe(10);
expect(root_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0.getComputedWidth()).toBe(0);
expect(root_child0_child0.getComputedHeight()).toBe(10);
expect(root_child0_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0_child0.getComputedWidth()).toBe(0);
expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
expect(root_child0_child0_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0_child0_child0.getComputedWidth()).toBe(0);
expect(root_child0_child0_child0_child0.getComputedHeight()).toBe(10);
root.calculateLayout(undefined, undefined, Direction.RTL);
expect(root.getComputedLeft()).toBe(0);
expect(root.getComputedTop()).toBe(0);
expect(root.getComputedWidth()).toBe(400);
expect(root.getComputedHeight()).toBe(400);
expect(root_child0.getComputedLeft()).toBe(0);
expect(root_child0.getComputedTop()).toBe(0);
expect(root_child0.getComputedWidth()).toBe(400);
expect(root_child0.getComputedHeight()).toBe(10);
expect(root_child0_child0.getComputedLeft()).toBe(400);
expect(root_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0.getComputedWidth()).toBe(0);
expect(root_child0_child0.getComputedHeight()).toBe(10);
expect(root_child0_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0_child0.getComputedWidth()).toBe(0);
expect(root_child0_child0_child0.getComputedHeight()).toBe(10);
expect(root_child0_child0_child0_child0.getComputedLeft()).toBe(0);
expect(root_child0_child0_child0_child0.getComputedTop()).toBe(0);
expect(root_child0_child0_child0_child0.getComputedWidth()).toBe(0);
expect(root_child0_child0_child0_child0.getComputedHeight()).toBe(10);
} finally {
if (typeof root !== 'undefined') {
root.freeRecursive();
}
config.free();
}
});

View File

@@ -19,10 +19,11 @@ include(":yoga")
project(":yoga").projectDir = file("java") project(":yoga").projectDir = file("java")
rootProject.name = "yoga-github" gradleEnterprise {
buildScan {
// If you specify a file inside gradle/gradle-enterprise.gradle.kts termsOfServiceUrl = "https://gradle.com/terms-of-service"
// you can configure your custom Gradle Enterprise instance termsOfServiceAgree = "yes"
if (file("./gradle/gradle-enterprise.gradle.kts").exists()) { }
apply(from = "./gradle/gradle-enterprise.gradle.kts")
} }
rootProject.name = "yoga-github"

7
tests/.clang-tidy Normal file
View File

@@ -0,0 +1,7 @@
---
InheritParentConfig: true
Checks: '
-facebook-hte-CArray,
-modernize-avoid-c-arrays,
'
...

View File

@@ -0,0 +1,214 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <gtest/gtest.h>
#include <yoga/Yoga.h>
#include <yoga/config/Config.h>
#include <yoga/node/Node.h>
#include <functional>
#include <memory>
#include <vector>
namespace facebook::yoga {
struct YGPersistentNodeCloningTest : public ::testing::Test {
struct NodeWrapper {
explicit NodeWrapper(
YGConfigRef config,
std::vector<std::shared_ptr<NodeWrapper>> children = {})
: node{YGNodeNewWithConfig(config)}, children{std::move(children)} {
YGNodeSetContext(node, this);
auto privateNode = resolveRef(node);
for (const auto& child : this->children) {
auto privateChild = resolveRef(child->node);
// Claim first ownership of not yet owned nodes, to avoid immediately
// cloning them
if (YGNodeGetOwner(child->node) == nullptr) {
privateChild->setOwner(privateNode);
}
privateNode->insertChild(privateChild, privateNode->getChildCount());
}
}
// Clone, with current children, for mutation
NodeWrapper(const NodeWrapper& other)
: node{YGNodeClone(other.node)}, children{other.children} {
YGNodeSetContext(node, this);
auto privateNode = resolveRef(node);
privateNode->setOwner(nullptr);
}
// Clone, with new children
NodeWrapper(
const NodeWrapper& other,
std::vector<std::shared_ptr<NodeWrapper>> children)
: node{YGNodeClone(other.node)}, children{std::move(children)} {
YGNodeSetContext(node, this);
auto privateNode = resolveRef(node);
privateNode->setOwner(nullptr);
privateNode->setChildren({});
privateNode->setDirty(true);
for (const auto& child : this->children) {
auto privateChild = resolveRef(child->node);
// Claim first ownership of not yet owned nodes, to avoid immediately
// cloning them
if (YGNodeGetOwner(child->node) == nullptr) {
privateChild->setOwner(privateNode);
}
privateNode->insertChild(privateChild, privateNode->getChildCount());
}
}
NodeWrapper(NodeWrapper&&) = delete;
~NodeWrapper() {
YGNodeFree(node);
}
NodeWrapper& operator=(const NodeWrapper& other) = delete;
NodeWrapper& operator=(NodeWrapper&& other) = delete;
YGNodeRef node;
std::vector<std::shared_ptr<NodeWrapper>> children;
};
struct ConfigWrapper {
ConfigWrapper() {
YGConfigSetCloneNodeFunc(
config,
[](YGNodeConstRef oldNode, YGNodeConstRef owner, size_t childIndex) {
onClone(oldNode, owner, childIndex);
auto wrapper = static_cast<NodeWrapper*>(YGNodeGetContext(owner));
auto old = static_cast<NodeWrapper*>(YGNodeGetContext(oldNode));
wrapper->children[childIndex] = std::make_shared<NodeWrapper>(*old);
return wrapper->children[childIndex]->node;
});
}
ConfigWrapper(const ConfigWrapper&) = delete;
ConfigWrapper(ConfigWrapper&&) = delete;
~ConfigWrapper() {
YGConfigFree(config);
}
ConfigWrapper& operator=(const ConfigWrapper&) = delete;
ConfigWrapper& operator=(ConfigWrapper&&) = delete;
YGConfigRef config{YGConfigNew()};
};
ConfigWrapper configWrapper;
YGConfigRef config{configWrapper.config};
void SetUp() override {
onClone = [](...) {};
}
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
static inline std::function<void(YGNodeConstRef, YGNodeConstRef, size_t)>
onClone;
};
TEST_F(
YGPersistentNodeCloningTest,
changing_sibling_height_does_not_clone_neighbors) {
// <ScrollView>
// <View id="Sibling" style={{ height: 1 }} />
// <View id="A" style={{ height: 1 }}>
// <View id="B">
// <View id="C">
// <View id="D"/>
// </View>
// </View>
// </View>
// </ScrollView>
auto sibling = std::make_shared<NodeWrapper>(config);
YGNodeStyleSetHeight(sibling->node, 1);
auto d = std::make_shared<NodeWrapper>(config);
auto c = std::make_shared<NodeWrapper>(config, std::vector{d});
auto b = std::make_shared<NodeWrapper>(config, std::vector{c});
auto a = std::make_shared<NodeWrapper>(config, std::vector{b});
YGNodeStyleSetHeight(a->node, 1);
auto scrollContentView =
std::make_shared<NodeWrapper>(config, std::vector{sibling, a});
YGNodeStyleSetPositionType(scrollContentView->node, YGPositionTypeAbsolute);
auto scrollView =
std::make_shared<NodeWrapper>(config, std::vector{scrollContentView});
YGNodeStyleSetWidth(scrollView->node, 100);
YGNodeStyleSetHeight(scrollView->node, 100);
// We don't expect any cloning during the first layout
onClone = [](...) { FAIL(); };
YGNodeCalculateLayout(
scrollView->node, YGUndefined, YGUndefined, YGDirectionLTR);
auto siblingPrime = std::make_shared<NodeWrapper>(config);
YGNodeStyleSetHeight(siblingPrime->node, 2);
auto scrollContentViewPrime = std::make_shared<NodeWrapper>(
*scrollContentView, std::vector{siblingPrime, a});
auto scrollViewPrime = std::make_shared<NodeWrapper>(
*scrollView, std::vector{scrollContentViewPrime});
std::vector<NodeWrapper*> nodesCloned;
// We should only need to clone "A"
onClone = [&](YGNodeConstRef oldNode,
YGNodeConstRef /*owner*/,
size_t /*childIndex*/) {
nodesCloned.push_back(static_cast<NodeWrapper*>(YGNodeGetContext(oldNode)));
};
YGNodeCalculateLayout(
scrollViewPrime->node, YGUndefined, YGUndefined, YGDirectionLTR);
EXPECT_EQ(nodesCloned.size(), 1);
EXPECT_EQ(nodesCloned[0], a.get());
}
TEST_F(YGPersistentNodeCloningTest, clone_leaf_display_contents_node) {
// <View id="A">
// <View id="B" style={{ display: 'contents' }} />
// </View>
auto b = std::make_shared<NodeWrapper>(config);
auto a = std::make_shared<NodeWrapper>(config, std::vector{b});
YGNodeStyleSetDisplay(b->node, YGDisplayContents);
// We don't expect any cloning during the first layout
onClone = [](...) { FAIL(); };
YGNodeCalculateLayout(a->node, YGUndefined, YGUndefined, YGDirectionLTR);
auto aPrime = std::make_shared<NodeWrapper>(config, std::vector{b});
std::vector<NodeWrapper*> nodesCloned;
// We should clone "C"
onClone = [&](YGNodeConstRef oldNode,
YGNodeConstRef /*owner*/,
size_t /*childIndex*/) {
nodesCloned.push_back(static_cast<NodeWrapper*>(YGNodeGetContext(oldNode)));
};
YGNodeCalculateLayout(aPrime->node, 100, 100, YGDirectionLTR);
EXPECT_EQ(nodesCloned.size(), 1);
EXPECT_EQ(nodesCloned[0], b.get());
}
} // namespace facebook::yoga

View File

@@ -161,3 +161,23 @@ TEST(YogaTest, per_node_point_scale_factor) {
YGConfigFree(config2); YGConfigFree(config2);
YGConfigFree(config3); YGConfigFree(config3);
} }
TEST(YogaTest, raw_layout_dimensions) {
YGConfigRef config = YGConfigNew();
YGConfigSetPointScaleFactor(config, 0.5f);
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetWidth(root, 11.5f);
YGNodeStyleSetHeight(root, 9.5f);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_EQ(YGNodeLayoutGetWidth(root), 12.0f);
ASSERT_EQ(YGNodeLayoutGetHeight(root), 10.0f);
ASSERT_EQ(YGNodeLayoutGetRawWidth(root), 11.5f);
ASSERT_EQ(YGNodeLayoutGetRawHeight(root), 9.5f);
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

View File

@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree. * LICENSE file in the root directory of this source tree.
* *
* clang-format off * clang-format off
* @generated SignedSource<<71295a398c89ea424490884a05e2c77c>> * @generated SignedSource<<1db57b05babb408c08efcec7dbdf16fb>>
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignItemsTest.html * generated by gentest/gentest-driver.ts from gentest/fixtures/YGAlignItemsTest.html
*/ */
@@ -2310,3 +2310,84 @@ TEST(YogaTest, align_stretch_with_row_reverse) {
YGConfigFree(config); YGConfigFree(config);
} }
TEST(YogaTest, align_items_non_stretch_s526008) {
YGConfigRef config = YGConfigNew();
YGNodeRef root = YGNodeNewWithConfig(config);
YGNodeStyleSetPositionType(root, YGPositionTypeAbsolute);
YGNodeStyleSetWidth(root, 400);
YGNodeStyleSetHeight(root, 400);
YGNodeRef root_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetFlexDirection(root_child0, YGFlexDirectionRow);
YGNodeInsertChild(root, root_child0, 0);
YGNodeRef root_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetAlignItems(root_child0_child0, YGAlignFlexStart);
YGNodeInsertChild(root_child0, root_child0_child0, 0);
YGNodeRef root_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeInsertChild(root_child0_child0, root_child0_child0_child0, 0);
YGNodeRef root_child0_child0_child0_child0 = YGNodeNewWithConfig(config);
YGNodeStyleSetHeight(root_child0_child0_child0_child0, 10);
YGNodeInsertChild(root_child0_child0_child0, root_child0_child0_child0_child0, 0);
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0_child0));
YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL);
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetHeight(root));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetWidth(root_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0));
ASSERT_FLOAT_EQ(400, YGNodeLayoutGetLeft(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0_child0_child0_child0));
ASSERT_FLOAT_EQ(10, YGNodeLayoutGetHeight(root_child0_child0_child0_child0));
YGNodeFreeRecursive(root);
YGConfigFree(config);
}

View File

@@ -17,15 +17,15 @@ has effect when items are wrapped to multiple lines using [flex wrap](/docs/styl
**Center**: Align wrapped lines in the center of the container's cross axis. **Center**: Align wrapped lines in the center of the container's cross axis.
**Space between**: Evenly space wrapped lines across the container's main axis, distributing **Space between**: Evenly space wrapped lines across the container's cross axis, distributing
remaining space between the lines. remaining space between the lines.
**Space around**: Evenly space wrapped lines across the container's main axis, distributing **Space around**: Evenly space wrapped lines across the container's cross axis, distributing
remaining space around the lines. Compared to space between using remaining space around the lines. Compared to space between using
space around will result in space being distributed to the beginning of space around will result in space being distributed to the beginning of
the first lines and end of the last line. the first lines and end of the last line.
**Space evenly**: Evenly space wrapped lines across the container's main axis, distributing **Space evenly**: Evenly space wrapped lines across the container's cross axis, distributing
remaining space around the lines. Compared to space around, space evenly will not remaining space around the lines. Compared to space around, space evenly will not
double the gaps between children. The size of gaps between children and between double the gaps between children. The size of gaps between children and between
the parent's edges and the first/last child will all be equal. the parent's edges and the first/last child will all be equal.

View File

@@ -90,3 +90,11 @@ float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge) {
return getResolvedLayoutProperty<&LayoutResults::padding>( return getResolvedLayoutProperty<&LayoutResults::padding>(
node, scopedEnum(edge)); node, scopedEnum(edge));
} }
float YGNodeLayoutGetRawHeight(YGNodeConstRef node) {
return resolveRef(node)->getLayout().rawDimension(Dimension::Height);
}
float YGNodeLayoutGetRawWidth(YGNodeConstRef node) {
return resolveRef(node)->getLayout().rawDimension(Dimension::Width);
}

View File

@@ -32,4 +32,14 @@ YG_EXPORT float YGNodeLayoutGetMargin(YGNodeConstRef node, YGEdge edge);
YG_EXPORT float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge); YG_EXPORT float YGNodeLayoutGetBorder(YGNodeConstRef node, YGEdge edge);
YG_EXPORT float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge); YG_EXPORT float YGNodeLayoutGetPadding(YGNodeConstRef node, YGEdge edge);
/**
* Return the measured height of the node, before layout rounding
*/
YG_EXPORT float YGNodeLayoutGetRawHeight(YGNodeConstRef node);
/**
* Return the measured width of the node, before layout rounding
*/
YG_EXPORT float YGNodeLayoutGetRawWidth(YGNodeConstRef node);
YG_EXTERN_C_END YG_EXTERN_C_END

View File

@@ -72,9 +72,9 @@ inline bool operator==(const YGValue& lhs, const YGValue& rhs) {
case YGUnitPoint: case YGUnitPoint:
case YGUnitPercent: case YGUnitPercent:
return lhs.value == rhs.value; return lhs.value == rhs.value;
default:
return false;
} }
return false;
} }
inline bool operator!=(const YGValue& lhs, const YGValue& rhs) { inline bool operator!=(const YGValue& lhs, const YGValue& rhs) {

View File

@@ -11,11 +11,11 @@
* `#include <yoga/Yoga.h>` includes all of Yoga's public headers. * `#include <yoga/Yoga.h>` includes all of Yoga's public headers.
*/ */
#include <yoga/YGConfig.h> #include <yoga/YGConfig.h> // IWYU pragma: export
#include <yoga/YGEnums.h> #include <yoga/YGEnums.h> // IWYU pragma: export
#include <yoga/YGMacros.h> #include <yoga/YGMacros.h> // IWYU pragma: export
#include <yoga/YGNode.h> #include <yoga/YGNode.h> // IWYU pragma: export
#include <yoga/YGNodeLayout.h> #include <yoga/YGNodeLayout.h> // IWYU pragma: export
#include <yoga/YGNodeStyle.h> #include <yoga/YGNodeStyle.h> // IWYU pragma: export
#include <yoga/YGPixelGrid.h> #include <yoga/YGPixelGrid.h> // IWYU pragma: export
#include <yoga/YGValue.h> #include <yoga/YGValue.h> // IWYU pragma: export

View File

@@ -415,6 +415,12 @@ static void measureNodeWithoutChildren(
Dimension::Height); Dimension::Height);
} }
inline bool isFixedSize(float dim, SizingMode sizingMode) {
return sizingMode == SizingMode::StretchFit ||
(yoga::isDefined(dim) && sizingMode == SizingMode::FitContent &&
dim <= 0.0);
}
static bool measureNodeWithFixedSize( static bool measureNodeWithFixedSize(
yoga::Node* const node, yoga::Node* const node,
const Direction direction, const Direction direction,
@@ -424,12 +430,8 @@ static bool measureNodeWithFixedSize(
const SizingMode heightSizingMode, const SizingMode heightSizingMode,
const float ownerWidth, const float ownerWidth,
const float ownerHeight) { const float ownerHeight) {
if ((yoga::isDefined(availableWidth) && if (isFixedSize(availableWidth, widthSizingMode) &&
widthSizingMode == SizingMode::FitContent && availableWidth <= 0.0f) || isFixedSize(availableHeight, heightSizingMode)) {
(yoga::isDefined(availableHeight) &&
heightSizingMode == SizingMode::FitContent && availableHeight <= 0.0f) ||
(widthSizingMode == SizingMode::StretchFit &&
heightSizingMode == SizingMode::StretchFit)) {
node->setLayoutMeasuredDimension( node->setLayoutMeasuredDimension(
boundAxis( boundAxis(
node, node,
@@ -476,16 +478,19 @@ static void zeroOutLayoutRecursively(yoga::Node* const node) {
} }
static void cleanupContentsNodesRecursively(yoga::Node* const node) { static void cleanupContentsNodesRecursively(yoga::Node* const node) {
for (auto child : node->getChildren()) { if (node->hasContentsChildren()) [[unlikely]] {
if (child->style().display() == Display::Contents) { node->cloneContentsChildrenIfNeeded();
child->getLayout() = {}; for (auto child : node->getChildren()) {
child->setLayoutDimension(0, Dimension::Width); if (child->style().display() == Display::Contents) {
child->setLayoutDimension(0, Dimension::Height); child->getLayout() = {};
child->setHasNewLayout(true); child->setLayoutDimension(0, Dimension::Width);
child->setDirty(false); child->setLayoutDimension(0, Dimension::Height);
child->cloneChildrenIfNeeded(); child->setHasNewLayout(true);
child->setDirty(false);
child->cloneChildrenIfNeeded();
cleanupContentsNodesRecursively(child); cleanupContentsNodesRecursively(child);
}
} }
} }
} }

View File

@@ -106,25 +106,25 @@ void roundLayoutResultsToPixelGrid(
const bool hasFractionalHeight = const bool hasFractionalHeight =
!yoga::inexactEquals(round(scaledNodeHeight), scaledNodeHeight); !yoga::inexactEquals(round(scaledNodeHeight), scaledNodeHeight);
node->setLayoutDimension( node->getLayout().setDimension(
Dimension::Width,
roundValueToPixelGrid( roundValueToPixelGrid(
absoluteNodeRight, absoluteNodeRight,
pointScaleFactor, pointScaleFactor,
(textRounding && hasFractionalWidth), (textRounding && hasFractionalWidth),
(textRounding && !hasFractionalWidth)) - (textRounding && !hasFractionalWidth)) -
roundValueToPixelGrid( roundValueToPixelGrid(
absoluteNodeLeft, pointScaleFactor, false, textRounding), absoluteNodeLeft, pointScaleFactor, false, textRounding));
Dimension::Width);
node->setLayoutDimension( node->getLayout().setDimension(
Dimension::Height,
roundValueToPixelGrid( roundValueToPixelGrid(
absoluteNodeBottom, absoluteNodeBottom,
pointScaleFactor, pointScaleFactor,
(textRounding && hasFractionalHeight), (textRounding && hasFractionalHeight),
(textRounding && !hasFractionalHeight)) - (textRounding && !hasFractionalHeight)) -
roundValueToPixelGrid( roundValueToPixelGrid(
absoluteNodeTop, pointScaleFactor, false, textRounding), absoluteNodeTop, pointScaleFactor, false, textRounding));
Dimension::Height);
} }
for (yoga::Node* child : node->getChildren()) { for (yoga::Node* child : node->getChildren()) {

View File

@@ -19,6 +19,7 @@ namespace facebook::yoga {
#if defined(__cpp_exceptions) #if defined(__cpp_exceptions)
throw std::logic_error(message); throw std::logic_error(message);
#else #else
static_cast<void>(message); // Unused
std::terminate(); std::terminate();
#endif #endif
} }

View File

@@ -36,12 +36,12 @@ enum struct LayoutPassReason : int {
}; };
struct LayoutData { struct LayoutData {
int layouts; int layouts = 0;
int measures; int measures = 0;
uint32_t maxMeasureCache; uint32_t maxMeasureCache = 0;
int cachedLayouts; int cachedLayouts = 0;
int cachedMeasures; int cachedMeasures = 0;
int measureCallbacks; int measureCallbacks = 0;
std::array<int, static_cast<uint8_t>(LayoutPassReason::COUNT)> std::array<int, static_cast<uint8_t>(LayoutPassReason::COUNT)>
measureCallbackReasonsCount; measureCallbackReasonsCount;
}; };

View File

@@ -66,10 +66,18 @@ struct LayoutResults {
return measuredDimensions_[yoga::to_underlying(axis)]; return measuredDimensions_[yoga::to_underlying(axis)];
} }
float rawDimension(Dimension axis) const {
return rawDimensions_[yoga::to_underlying(axis)];
}
void setMeasuredDimension(Dimension axis, float dimension) { void setMeasuredDimension(Dimension axis, float dimension) {
measuredDimensions_[yoga::to_underlying(axis)] = dimension; measuredDimensions_[yoga::to_underlying(axis)] = dimension;
} }
void setRawDimension(Dimension axis, float dimension) {
rawDimensions_[yoga::to_underlying(axis)] = dimension;
}
float position(PhysicalEdge physicalEdge) const { float position(PhysicalEdge physicalEdge) const {
return position_[yoga::to_underlying(physicalEdge)]; return position_[yoga::to_underlying(physicalEdge)];
} }
@@ -113,6 +121,7 @@ struct LayoutResults {
std::array<float, 2> dimensions_ = {{YGUndefined, YGUndefined}}; std::array<float, 2> dimensions_ = {{YGUndefined, YGUndefined}};
std::array<float, 2> measuredDimensions_ = {{YGUndefined, YGUndefined}}; std::array<float, 2> measuredDimensions_ = {{YGUndefined, YGUndefined}};
std::array<float, 2> rawDimensions_ = {{YGUndefined, YGUndefined}};
std::array<float, 4> position_ = {}; std::array<float, 4> position_ = {};
std::array<float, 4> margin_ = {}; std::array<float, 4> margin_ = {};
std::array<float, 4> border_ = {}; std::array<float, 4> border_ = {};

View File

@@ -181,6 +181,17 @@ void Node::setDirty(bool isDirty) {
} }
} }
void Node::setChildren(const std::vector<Node*>& children) {
children_ = children;
contentsChildrenCount_ = 0;
for (const auto& child : children) {
if (child->style().display() == Display::Contents) {
contentsChildrenCount_++;
}
}
}
bool Node::removeChild(Node* child) { bool Node::removeChild(Node* child) {
auto p = std::find(children_.begin(), children_.end(), child); auto p = std::find(children_.begin(), children_.end(), child);
if (p != children_.end()) { if (p != children_.end()) {
@@ -247,6 +258,7 @@ void Node::setLayoutHadOverflow(bool hadOverflow) {
void Node::setLayoutDimension(float lengthValue, Dimension dimension) { void Node::setLayoutDimension(float lengthValue, Dimension dimension) {
layout_.setDimension(dimension, lengthValue); layout_.setDimension(dimension, lengthValue);
layout_.setRawDimension(dimension, lengthValue);
} }
// If both left and right are defined, then use left. Otherwise return +left or // If both left and right are defined, then use left. Otherwise return +left or
@@ -379,6 +391,23 @@ void Node::cloneChildrenIfNeeded() {
if (child->getOwner() != this) { if (child->getOwner() != this) {
child = resolveRef(config_->cloneNode(child, this, i)); child = resolveRef(config_->cloneNode(child, this, i));
child->setOwner(this); child->setOwner(this);
if (child->hasContentsChildren()) [[unlikely]] {
child->cloneContentsChildrenIfNeeded();
}
}
i += 1;
}
}
void Node::cloneContentsChildrenIfNeeded() {
size_t i = 0;
for (Node*& child : children_) {
if (child->style().display() == Display::Contents &&
child->getOwner() != this) {
child = resolveRef(config_->cloneNode(child, this, i));
child->setOwner(this);
child->cloneChildrenIfNeeded();
} }
i += 1; i += 1;
} }

View File

@@ -96,6 +96,10 @@ class YG_EXPORT Node : public ::YGNode {
return config_->hasErrata(errata); return config_->hasErrata(errata);
} }
bool hasContentsChildren() const {
return contentsChildrenCount_ != 0;
}
YGDirtiedFunc getDirtiedFunc() const { YGDirtiedFunc getDirtiedFunc() const {
return dirtiedFunc_; return dirtiedFunc_;
} }
@@ -244,15 +248,12 @@ class YG_EXPORT Node : public ::YGNode {
owner_ = owner; owner_ = owner;
} }
void setChildren(const std::vector<Node*>& children) {
children_ = children;
}
// TODO: rvalue override for setChildren // TODO: rvalue override for setChildren
void setConfig(Config* config); void setConfig(Config* config);
void setDirty(bool isDirty); void setDirty(bool isDirty);
void setChildren(const std::vector<Node*>& children);
void setLayoutLastOwnerDirection(Direction direction); void setLayoutLastOwnerDirection(Direction direction);
void setLayoutComputedFlexBasis(FloatOptional computedFlexBasis); void setLayoutComputedFlexBasis(FloatOptional computedFlexBasis);
void setLayoutComputedFlexBasisGeneration( void setLayoutComputedFlexBasisGeneration(
@@ -286,6 +287,7 @@ class YG_EXPORT Node : public ::YGNode {
void removeChild(size_t index); void removeChild(size_t index);
void cloneChildrenIfNeeded(); void cloneChildrenIfNeeded();
void cloneContentsChildrenIfNeeded();
void markDirtyAndPropagate(); void markDirtyAndPropagate();
float resolveFlexGrow() const; float resolveFlexGrow() const;
float resolveFlexShrink() const; float resolveFlexShrink() const;