From 633cdc908857a580e73bc209864cc227e25f78b4 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Mon, 8 Jun 2020 08:07:37 -0700 Subject: [PATCH 01/33] use fmod and YGDoubleEquals for double operations instead of float Summary: Changelog: [Internal][Yoga] Use double operations during rounding Reviewed By: mdvacca Differential Revision: D21840018 fbshipit-source-id: c5d17fcb8984b1da9832a15ccd4d628e8d742c6a --- yoga/Utils.cpp | 7 +++++++ yoga/Utils.h | 2 ++ yoga/Yoga.cpp | 16 ++++++++-------- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index f6e55d0d..c4281b60 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -52,6 +52,13 @@ bool YGFloatsEqual(const float a, const float b) { return yoga::isUndefined(a) && yoga::isUndefined(b); } +bool YGDoubleEqual(const double a, const double b) { + if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { + return fabs(a - b) < 0.0001f; + } + return yoga::isUndefined(a) && yoga::isUndefined(b); +} + float YGFloatSanitize(const float val) { return yoga::isUndefined(val) ? 0 : val; } diff --git a/yoga/Utils.h b/yoga/Utils.h index e9edf2f9..57e1d45d 100644 --- a/yoga/Utils.h +++ b/yoga/Utils.h @@ -64,6 +64,8 @@ inline bool YGValueEqual( // difference between two floats is less than 0.0001f or both are undefined. bool YGFloatsEqual(const float a, const float b); +bool YGDoubleEqual(const double a, const double b); + float YGFloatMax(const float a, const float b); YGFloatOptional YGFloatOptionalMax( diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 91e09c15..cb06c10e 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3668,7 +3668,7 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( double scaledValue = ((double) value) * pointScaleFactor; // We want to calculate `fractial` such that `floor(scaledValue) = scaledValue // - fractial`. - float fractial = fmodf(scaledValue, 1.0f); + double fractial = fmod(scaledValue, 1.0f); if (fractial < 0) { // This branch is for handling negative numbers for `value`. // @@ -3687,10 +3687,10 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( // - Finding the `floor`: -2.2 - fractial2 = -2.2 - 0.8 = -3 ++fractial; } - if (YGFloatsEqual(fractial, 0)) { + if (YGDoubleEqual(fractial, 0)) { // First we check if the value is already rounded scaledValue = scaledValue - fractial; - } else if (YGFloatsEqual(fractial, 1.0f)) { + } else if (YGDoubleEqual(fractial, 1.0f)) { scaledValue = scaledValue - fractial + 1.0f; } else if (forceCeil) { // Next we check if we need to use forced rounding @@ -3701,7 +3701,7 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( // Finally we just round the value scaledValue = scaledValue - fractial + (!YGFloatIsUndefined(fractial) && - (fractial > 0.5f || YGFloatsEqual(fractial, 0.5f)) + (fractial > 0.5f || YGDoubleEqual(fractial, 0.5f)) ? 1.0f : 0.0f); } @@ -4113,11 +4113,11 @@ static void YGRoundToPixelGrid( // whole number, we don't have any fraction To verify if the result is close // to whole number we want to check both floor and ceil numbers const bool hasFractionalWidth = - !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 0) && - !YGFloatsEqual(fmodf(nodeWidth * pointScaleFactor, 1.0), 1.0); + !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 0) && + !YGDoubleEqual(fmod(nodeWidth * pointScaleFactor, 1.0), 1.0); const bool hasFractionalHeight = - !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 0) && - !YGFloatsEqual(fmodf(nodeHeight * pointScaleFactor, 1.0), 1.0); + !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 0) && + !YGDoubleEqual(fmod(nodeHeight * pointScaleFactor, 1.0), 1.0); node->setLayoutDimension( YGRoundValueToPixelGrid( From d74a1069a03c5e184209a43e883b406786d8bbd0 Mon Sep 17 00:00:00 2001 From: Stiopa Koltsov Date: Wed, 24 Jun 2020 12:15:15 -0700 Subject: [PATCH 02/33] xplat: Disable Starlark in several files Summary: Disable Starlark in several files which are not trivial to fix. Reviewed By: scottrice Differential Revision: D22202463 fbshipit-source-id: a3ff717f0f4b9cd7f492b8fcebdb91f232207222 --- java/BUCK | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java/BUCK b/java/BUCK index d08cb37b..a658d7e9 100644 --- a/java/BUCK +++ b/java/BUCK @@ -1,3 +1,5 @@ +# BUILD FILE SYNTAX: PYTHON_DSL + # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the From a93e5d63c9d26e378c07f3adfd86e16a4ca88143 Mon Sep 17 00:00:00 2001 From: Amir Shalem Date: Mon, 6 Jul 2020 03:41:19 -0700 Subject: [PATCH 03/33] Don't call config->setLogger(nullptr) directly to avoid having no logger at all Summary: Changelog: [Internal][Yoga] Don't call config->setLogger(nullptr) directly to avoid having no logger at all Broken in D14151037 (https://github.com/facebook/yoga/commit/05f36a835a3a66b1b8affcdb036ec47117a8d28f) when it started calling ``` config->setLogger(nullptr); ``` instead of going thru ``` YGConfigSetLogger(config, nullptr); ``` which does the right thing by setting the logger to its default value: https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/yoga/yoga/Yoga.cpp?commit=835911317e8b3cf7da1866e40e1c79cda0690136&lines=4320-4330 Also by default YogaConfig always have a logger: https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/xplat/yoga/yoga/Yoga.cpp?commit=835911317e8b3cf7da1866e40e1c79cda0690136&lines=335-343 Reviewed By: SidharthGuglani Differential Revision: D22387459 fbshipit-source-id: 4da91da87a696d38cc9d8db2acb5845d29398adb --- java/jni/YGJNIVanilla.cpp | 2 +- .../com/facebook/yoga/YogaLoggerTest.java | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/java/jni/YGJNIVanilla.cpp b/java/jni/YGJNIVanilla.cpp index 698ab561..65343821 100644 --- a/java/jni/YGJNIVanilla.cpp +++ b/java/jni/YGJNIVanilla.cpp @@ -196,7 +196,7 @@ static void jni_YGConfigSetLoggerJNI( delete context; YGConfigSetContext(config, nullptr); } - config->setLogger(nullptr); + YGConfigSetLogger(config, nullptr); } } diff --git a/java/tests/com/facebook/yoga/YogaLoggerTest.java b/java/tests/com/facebook/yoga/YogaLoggerTest.java index 17316f6e..f88409d6 100644 --- a/java/tests/com/facebook/yoga/YogaLoggerTest.java +++ b/java/tests/com/facebook/yoga/YogaLoggerTest.java @@ -9,10 +9,62 @@ package com.facebook.yoga; import org.junit.Test; import java.lang.ref.WeakReference; +import java.util.List; +import java.util.ArrayList; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public class YogaLoggerTest { + + @Test + public void testRemovingLoggerFromConfig() throws Exception { + final List logs = new ArrayList<>(); + + final YogaConfig config = YogaConfigFactory.create(); + YogaLogger logger = new YogaLogger() { + @Override + public void log(YogaLogLevel level, String message) { + logs.add(message); + } + }; + config.setLogger(logger); + + final YogaNode root = YogaNodeFactory.create(config); + root.setFlexDirection(YogaFlexDirection.ROW); + root.setAlignItems(YogaAlign.BASELINE); + + final YogaNode child1 = YogaNodeFactory.create(config); + root.addChildAt(child1, 0); + + final YogaNode child2 = YogaNodeFactory.create(config); + child2.setBaselineFunction(new YogaBaselineFunction() { + public float baseline(YogaNode node, float width, float height) { + return Float.NaN; + } + }); + root.addChildAt(child2, 1); + + assertEquals(logs.size(), 0); + try { + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + fail("Expected calculateLayout to throw"); + } catch (IllegalStateException e) { + } + + assertEquals(logs.size(), 1); + + config.setLogger(null); + + try { + root.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); + fail("Expected calculateLayout to throw again"); + } catch (IllegalStateException e) { + } + + assertEquals(logs.size(), 1); + } + @Test public void testLoggerLeak() throws Exception { final YogaConfig config = YogaConfigFactory.create(); From 0767f4d10522677a0254613b8fe6466bc3b29534 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 14 Jul 2020 15:20:24 -0700 Subject: [PATCH 04/33] Using `YGPositionTypeAbsolute` value where we compare `absolute` vs `relative` Summary: Now Yoga.cpp does not use the `YGPositionTypeRelative` value/constant, it uses `YGPositionTypeAbsolute` instead. Now `YGPositionType` can only be `YGPositionTypeRelative` or `YGPositionTypeAbsolute`, so expressions `x == YGPositionTypeRelative` and `x != YGPositionTypeAbsolute` are equivalent. The reasoning behind the change is that in all cases we actually check a node to be (or not to be) `absolute`, not `relative`. This will make a difference in the coming diffs in the stack when we will introduce a new value for the type: `static`. We need to differentiate `static` and `relative` values t implement the `stacking context` feature in the W3C-compliant way (to fix bugs and avoid developer confusion). Read more here: https://developer.mozilla.org/en-US/docs/Web/CSS/position Changelog: [Internal] Internal change in Yoga. Reviewed By: SidharthGuglani Differential Revision: D22386733 fbshipit-source-id: 8e2c2b88b404660639f845783c8f93f0c62c0fbb --- yoga/YGNode.cpp | 5 ++++- yoga/Yoga.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 23d5c40b..1ee1bde6 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -307,6 +307,9 @@ void YGNode::setPosition( const YGFlexDirection crossAxis = YGFlexDirectionCross(mainAxis, directionRespectingRoot); + // Here we should check for `YGPositionTypeStatic` and in this case zero inset + // properties (left, right, top, bottom, begin, end). + // https://www.w3.org/TR/css-position-3/#valdef-position-static const YGFloatOptional relativePositionMain = relativePosition(mainAxis, mainSize); const YGFloatOptional relativePositionCross = @@ -440,7 +443,7 @@ float YGNode::resolveFlexShrink() const { bool YGNode::isNodeFlexible() { return ( - (style_.positionType() == YGPositionTypeRelative) && + (style_.positionType() != YGPositionTypeAbsolute) && (resolveFlexGrow() != 0 || resolveFlexShrink() != 0)); } diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index cb06c10e..97e64075 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1131,7 +1131,7 @@ static bool YGIsBaselineLayout(const YGNodeRef node) { const uint32_t childCount = YGNodeGetChildCount(node); for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType() == YGPositionTypeRelative && + if (child->getStyle().positionType() != YGPositionTypeAbsolute && child->getStyle().alignSelf() == YGAlignBaseline) { return true; } @@ -2505,7 +2505,7 @@ static void YGJustifyMainAxis( i < collectedFlexItemsValues.endOfLineIndex; i++) { const YGNodeRef child = node->getChild(i); - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { numberOfAutoMarginsOnCurrentLine++; } @@ -2589,7 +2589,7 @@ static void YGJustifyMainAxis( // Now that we placed the element, we need to update the variables. // We need to do that only for relative elements. Absolute elements do not // take part in that phase. - if (childStyle.positionType() == YGPositionTypeRelative) { + if (childStyle.positionType() != YGPositionTypeAbsolute) { if (child->marginLeadingValue(mainAxis).unit == YGUnitAuto) { collectedFlexItemsValues.mainDim += collectedFlexItemsValues.remainingFreeSpace / @@ -3311,7 +3311,7 @@ static void YGNodelayoutImpl( if (child->getStyle().display() == YGDisplayNone) { continue; } - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { if (child->getLineIndex() != i) { break; } @@ -3353,7 +3353,7 @@ static void YGNodelayoutImpl( if (child->getStyle().display() == YGDisplayNone) { continue; } - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { switch (YGNodeAlignItem(node, child)) { case YGAlignFlexStart: { child->setLayoutPosition( @@ -3544,7 +3544,7 @@ static void YGNodelayoutImpl( if (performLayout && node->getStyle().flexWrap() == YGWrapWrapReverse) { for (uint32_t i = 0; i < childCount; i++) { const YGNodeRef child = YGNodeGetChild(node, i); - if (child->getStyle().positionType() == YGPositionTypeRelative) { + if (child->getStyle().positionType() != YGPositionTypeAbsolute) { child->setLayoutPosition( node->getLayout().measuredDimensions[dim[crossAxis]] - child->getLayout().position[pos[crossAxis]] - From 16f676eccff0da229ba9ab97c96c4973b01b6750 Mon Sep 17 00:00:00 2001 From: Stanislau Hlebik Date: Fri, 17 Jul 2020 17:07:23 -0700 Subject: [PATCH 05/33] remediation of S205607 fbshipit-source-id: 5113fe0c527595e4227ff827253b7414abbdf7ac --- .../Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs | 1 + .../Android/Facebook.Yoga.Android/Resources/Resource.designer.cs | 1 + csharp/nuget/_._ | 1 + 3 files changed, 3 insertions(+) diff --git a/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs b/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs index e69de29b..56de9c5e 100644 --- a/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs +++ b/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs @@ -0,0 +1 @@ +S205607 diff --git a/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs b/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs index e69de29b..56de9c5e 100644 --- a/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs +++ b/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs @@ -0,0 +1 @@ +S205607 diff --git a/csharp/nuget/_._ b/csharp/nuget/_._ index e69de29b..56de9c5e 100644 --- a/csharp/nuget/_._ +++ b/csharp/nuget/_._ @@ -0,0 +1 @@ +S205607 From 5ac5624e3fc872bb9e3a899e42f77602539b8fae Mon Sep 17 00:00:00 2001 From: Stanislau Hlebik Date: Fri, 17 Jul 2020 17:07:23 -0700 Subject: [PATCH 06/33] remediation of S205607 fbshipit-source-id: 798decc90db4f13770e97cdce3c0df7d5421b2a3 --- .../Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs | 1 - .../Android/Facebook.Yoga.Android/Resources/Resource.designer.cs | 1 - csharp/nuget/_._ | 1 - 3 files changed, 3 deletions(-) diff --git a/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs b/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs index 56de9c5e..e69de29b 100644 --- a/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs +++ b/csharp/Android/Facebook.Yoga.Android.Tests/Resources/Resource.designer.cs @@ -1 +0,0 @@ -S205607 diff --git a/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs b/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs index 56de9c5e..e69de29b 100644 --- a/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs +++ b/csharp/Android/Facebook.Yoga.Android/Resources/Resource.designer.cs @@ -1 +0,0 @@ -S205607 diff --git a/csharp/nuget/_._ b/csharp/nuget/_._ index 56de9c5e..e69de29b 100644 --- a/csharp/nuget/_._ +++ b/csharp/nuget/_._ @@ -1 +0,0 @@ -S205607 From fc88b2f774f0ab9090d7ca15de6680f26d7285ad Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 20 Jul 2020 00:31:15 -0700 Subject: [PATCH 07/33] Introducing `YGPositionTypeStatic` Summary: Changelog: [Internal] Fabric-specific internal change. This diff introduces a new value for `YGPositionType`: `YGPositionTypeStatic`. No part of Yoga, RN, Litho or CK uses this value yet. `relative` and `static` values behave the same way for now. We also do not change any defaults. So, it should be fine. Reviewed By: SidharthGuglani Differential Revision: D22386732 fbshipit-source-id: 39cd9e818458ac2a91efb175f24a74c8c303ff08 --- gentest/gentest-cs.js | 3 ++- java/com/facebook/yoga/YogaPositionType.java | 10 ++++++---- tests/YGDefaultValuesTest.cpp | 2 +- tests/YGStyleAccessorsTest.cpp | 5 +++-- yoga/YGEnums.cpp | 2 ++ yoga/YGEnums.h | 6 +++++- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/gentest/gentest-cs.js b/gentest/gentest-cs.js index 2e276180..f0cbd7fb 100644 --- a/gentest/gentest-cs.js +++ b/gentest/gentest-cs.js @@ -120,8 +120,9 @@ CSEmitter.prototype = Object.create(Emitter.prototype, { YGOverflowHidden:{value:'YogaOverflow.Hidden'}, YGOverflowVisible:{value:'YogaOverflow.Visible'}, - YGPositionTypeAbsolute:{value:'YogaPositionType.Absolute'}, + YGPositionTypeAbsolute:{value:'YogaPositionType.Static'}, YGPositionTypeRelative:{value:'YogaPositionType.Relative'}, + YGPositionTypeAbsolute:{value:'YogaPositionType.Absolute'}, YGUndefined:{value:'YogaConstants.Undefined'}, diff --git a/java/com/facebook/yoga/YogaPositionType.java b/java/com/facebook/yoga/YogaPositionType.java index 00354f5c..d61c3244 100644 --- a/java/com/facebook/yoga/YogaPositionType.java +++ b/java/com/facebook/yoga/YogaPositionType.java @@ -8,8 +8,9 @@ package com.facebook.yoga; public enum YogaPositionType { - RELATIVE(0), - ABSOLUTE(1); + STATIC(0), + RELATIVE(1), + ABSOLUTE(2); private final int mIntValue; @@ -23,8 +24,9 @@ public enum YogaPositionType { public static YogaPositionType fromInt(int value) { switch (value) { - case 0: return RELATIVE; - case 1: return ABSOLUTE; + case 0: return STATIC; + case 1: return RELATIVE; + case 2: return ABSOLUTE; default: throw new IllegalArgumentException("Unknown enum value: " + value); } } diff --git a/tests/YGDefaultValuesTest.cpp b/tests/YGDefaultValuesTest.cpp index 249a7605..a622c1b3 100644 --- a/tests/YGDefaultValuesTest.cpp +++ b/tests/YGDefaultValuesTest.cpp @@ -20,7 +20,7 @@ TEST(YogaTest, assert_default_values) { ASSERT_EQ(YGAlignFlexStart, YGNodeStyleGetAlignContent(root)); ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignItems(root)); ASSERT_EQ(YGAlignAuto, YGNodeStyleGetAlignSelf(root)); - ASSERT_EQ(YGPositionTypeRelative, YGNodeStyleGetPositionType(root)); + ASSERT_EQ(YGPositionTypeStatic, YGNodeStyleGetPositionType(root)); ASSERT_EQ(YGWrapNoWrap, YGNodeStyleGetFlexWrap(root)); ASSERT_EQ(YGOverflowVisible, YGNodeStyleGetOverflow(root)); ASSERT_FLOAT_EQ(0, YGNodeStyleGetFlexGrow(root)); diff --git a/tests/YGStyleAccessorsTest.cpp b/tests/YGStyleAccessorsTest.cpp index 541f354f..d0bda431 100644 --- a/tests/YGStyleAccessorsTest.cpp +++ b/tests/YGStyleAccessorsTest.cpp @@ -132,9 +132,10 @@ ACCESSOR_TEST( ACCESSOR_TEST( positionType, - YGPositionTypeRelative, + YGPositionTypeStatic, YGPositionTypeAbsolute, - YGPositionTypeRelative) + YGPositionTypeRelative, + YGPositionTypeStatic) ACCESSOR_TEST( flexWrap, diff --git a/yoga/YGEnums.cpp b/yoga/YGEnums.cpp index 3c130129..c01d3d94 100644 --- a/yoga/YGEnums.cpp +++ b/yoga/YGEnums.cpp @@ -179,6 +179,8 @@ const char* YGOverflowToString(const YGOverflow value) { const char* YGPositionTypeToString(const YGPositionType value) { switch (value) { + case YGPositionTypeStatic: + return "static"; case YGPositionTypeRelative: return "relative"; case YGPositionTypeAbsolute: diff --git a/yoga/YGEnums.h b/yoga/YGEnums.h index 4241281d..3dc458dc 100644 --- a/yoga/YGEnums.h +++ b/yoga/YGEnums.h @@ -128,7 +128,11 @@ YG_ENUM_SEQ_DECL( YGOverflowHidden, YGOverflowScroll) -YG_ENUM_SEQ_DECL(YGPositionType, YGPositionTypeRelative, YGPositionTypeAbsolute) +YG_ENUM_SEQ_DECL( + YGPositionType, + YGPositionTypeStatic, + YGPositionTypeRelative, + YGPositionTypeAbsolute) YG_ENUM_DECL( YGPrintOptions, From 084d5935e6f6bf7306ad8041bdc2f097889b8e58 Mon Sep 17 00:00:00 2001 From: Thomas Nardone Date: Mon, 3 Aug 2020 09:26:28 -0700 Subject: [PATCH 08/33] Tweak stdlib imports in event, utils Summary: Changelog: [Internal][Fixed] - Tweaked stdlib imports Reviewed By: SidharthGuglani Differential Revision: D22860196 fbshipit-source-id: fc0fc1bf05ebbfae7e86bce5e960e58d5944ee5c --- yoga/Utils.cpp | 1 + yoga/event/event.cpp | 1 - yoga/event/event.h | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index c4281b60..edb198d2 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -6,6 +6,7 @@ */ #include "Utils.h" +#include using namespace facebook; diff --git a/yoga/event/event.cpp b/yoga/event/event.cpp index 2b07e381..3af3e83a 100644 --- a/yoga/event/event.cpp +++ b/yoga/event/event.cpp @@ -8,7 +8,6 @@ #include "event.h" #include #include -#include namespace facebook { namespace yoga { diff --git a/yoga/event/event.h b/yoga/event/event.h index 309dacb5..404ec376 100644 --- a/yoga/event/event.h +++ b/yoga/event/event.h @@ -11,6 +11,7 @@ #include #include #include +#include struct YGConfig; struct YGNode; From e1c9d8800e8d4f0edb11010da6270707a166e2ed Mon Sep 17 00:00:00 2001 From: Jiawei Lv Date: Tue, 11 Aug 2020 17:09:47 -0700 Subject: [PATCH 09/33] Assign test_ownership_2020 as owner for unowned java tests in fbandroid Summary: Changelog: [Internal] Reviewed By: IanChilds Differential Revision: D22980855 fbshipit-source-id: d5e394f16eaf0e50367b95b1eec98024b906d3d9 --- java/BUCK | 1 + 1 file changed, 1 insertion(+) diff --git a/java/BUCK b/java/BUCK index a658d7e9..fa0250a3 100644 --- a/java/BUCK +++ b/java/BUCK @@ -110,6 +110,7 @@ yoga_java_library( yoga_java_test( name = "tests", srcs = glob(["tests/**/*.java"]), + contacts = ["oncall+yoga@xmail.facebook.com"], cxx_library_whitelist = CXX_LIBRARY_WHITELIST_FOR_TESTS, use_cxx_libraries = True, visibility = ["PUBLIC"], From e0ae96368c966d1fb5f8ad3de852050c95621a79 Mon Sep 17 00:00:00 2001 From: Paco Estevez Garcia Date: Fri, 28 Aug 2020 06:30:53 -0700 Subject: [PATCH 10/33] Add DoNotStripAny Summary: This diff adds an annotation that also prevents stripping methods, fields and static blocks. This is necessary for D23373168 to be OSS'd Reviewed By: SidharthGuglani Differential Revision: D23395925 fbshipit-source-id: 8456234cb75b15ae87580835e76f8e251ba09a9b --- .../proguard/annotations/DoNotStripAny.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java diff --git a/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java b/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java new file mode 100644 index 00000000..48f71f2b --- /dev/null +++ b/java/proguard-annotations/src/main/java/com/facebook/proguard/annotations/DoNotStripAny.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) Facebook, Inc. and its 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.proguard.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.RetentionPolicy.CLASS; + +/** + * Add this annotation to a class to instruct Proguard to not strip it or any of its fields or + * methods out. + * + *

This is useful for methods called via reflection that could appear as unused to Proguard. + */ +@Target({ElementType.TYPE}) +@Retention(CLASS) +public @interface DoNotStripAny {} From f350c7a58e59aea8586f38b5d5e9654ae79da6c6 Mon Sep 17 00:00:00 2001 From: Panagiotis Vekris Date: Thu, 10 Sep 2020 16:00:22 -0700 Subject: [PATCH 11/33] explicitly set types_first=false in flowconfigs Summary: In Flow version 0.134, [types-first](https://flow.org/en/docs/lang/types-first/) will become the default mode for Flow. Given that this mode might introduce some errors due to missing annotations, we're pinning the previously default mode, to avoid introducing new errors. Note that in Jan 2021 we will be removing support for Flow classic mode. * Documentation for properly upgrading to types-first: https://flow.org/en/docs/cli/annotate-exports/ * Announcement post: https://medium.com/flow-type/types-first-a-scalable-new-architecture-for-flow-3d8c7ba1d4eb Reviewed By: mroch Differential Revision: D23606450 fbshipit-source-id: f849275269974e17c0ebe00885e387ccd9956b6d --- javascript/.flowconfig | 1 + website/.flowconfig | 1 + 2 files changed, 2 insertions(+) diff --git a/javascript/.flowconfig b/javascript/.flowconfig index 1fed4453..6a0c16ae 100644 --- a/javascript/.flowconfig +++ b/javascript/.flowconfig @@ -7,5 +7,6 @@ [lints] [options] +types_first=false [strict] diff --git a/website/.flowconfig b/website/.flowconfig index 1fed4453..6a0c16ae 100644 --- a/website/.flowconfig +++ b/website/.flowconfig @@ -7,5 +7,6 @@ [lints] [options] +types_first=false [strict] From 64e245942786227b2f97ccfa5c30ce5c4fd62d79 Mon Sep 17 00:00:00 2001 From: simek Date: Mon, 28 Sep 2020 21:24:45 -0700 Subject: [PATCH 12/33] remove most of tvOS remnants from the code (#29407) Summary: Refs: [0.62 release](https://reactnative.dev/blog/#moving-apple-tv-to-react-native-tvos), https://github.com/facebook/react-native/issues/28706, https://github.com/facebook/react-native/issues/28743, https://github.com/facebook/react-native/issues/29018 This PR removes most of the tvOS remnants in the code. Most of the changes are related to the tvOS platform removal from `.podspec` files, tvOS specific conditionals removal (Obj-C + JS) or tvOS CI/testing pipeline related code. In addition to the changes listed above I have removed the deprecated `Platform.isTVOS` method. I'm not sure how `Platform.isTV` method is correlated with Android TV devices support which is technically not deprecated in the core so I left this method untouched for now. ## Changelog * **[Internal] [Removed]** - remove most of tvOS remnants from the code: * `TVEventHandler`, `TVTouchable`, `RCTTVView`, `RCTTVRemoteHandler` and `RCTTVNavigationEventEmitter` * **[Internal] [Removed]** - remove `TARGET_TV_OS` flag and all the usages * **[iOS] [Removed]** - remove deprecated `Platform.isTVOS` method * **[iOS] [Removed]** - remove deprecated and TV related props from View: * `isTVSelectable`, `hasTVPreferredFocus` and `tvParallaxProperties` * **[iOS] [Removed]** - remove `BackHandler` utility implementation Pull Request resolved: https://github.com/facebook/react-native/pull/29407 Test Plan: Local tests (and iOS CI run) do not yield any errors, but I'm not sure how the CI pipeline would react to those changes. That is the reason why this PR is being posted as Draft. Some tweaks and code adjustment could be required. Reviewed By: PeteTheHeat Differential Revision: D22619441 Pulled By: shergin fbshipit-source-id: 9aaf3840c5e8bd469c2cfcfa7c5b441ef71b30b6 --- ReactYoga.xcodeproj/project.pbxproj | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/ReactYoga.xcodeproj/project.pbxproj b/ReactYoga.xcodeproj/project.pbxproj index 715c686a..090c6e09 100644 --- a/ReactYoga.xcodeproj/project.pbxproj +++ b/ReactYoga.xcodeproj/project.pbxproj @@ -191,7 +191,6 @@ 27595AD71E575C7800CCE2B1 /* SampleCxxModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D92B0D41E03699D0018521A /* SampleCxxModule.h */; }; 27595AD81E575C7800CCE2B1 /* SystraceSection.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D92B0D51E03699D0018521A /* SystraceSection.h */; }; 2D0EB9F32021067800CAF88A /* RCTUIUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = F1EFDA4E201F660F00EE6E4C /* RCTUIUtils.m */; }; - 2D16E68E1FA4FD3900B85C8A /* RCTTVNavigationEventEmitter.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */; }; 2D1D83CE1F74E2DA00615550 /* libdouble-conversion.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D383D621EBD27B9005632C8 /* libdouble-conversion.a */; }; 2D3B5E931D9B087300451313 /* RCTErrorInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */; }; 2D3B5E941D9B087900451313 /* RCTBundleURLProvider.m in Sources */ = {isa = PBXBuildFile; fileRef = 68EFE4ED1CF6EB3900A1DE13 /* RCTBundleURLProvider.m */; }; @@ -269,8 +268,6 @@ 3D0B842A1EC0B49400B2BD8E /* RCTTVRemoteHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0B84281EC0B49400B2BD8E /* RCTTVRemoteHandler.h */; }; 3D0B842B1EC0B49400B2BD8E /* RCTTVRemoteHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D0B84291EC0B49400B2BD8E /* RCTTVRemoteHandler.m */; }; 3D0B842C1EC0B4EA00B2BD8E /* RCTTVView.m in Sources */ = {isa = PBXBuildFile; fileRef = 130443D71E401AD800D93A67 /* RCTTVView.m */; }; - 3D0B842F1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */; }; - 3D0B84301EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m in Sources */ = {isa = PBXBuildFile; fileRef = 3D0B842E1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m */; }; 3D0E378A1F1CC40000DCAC9F /* RCTWebSocketModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */; }; 3D0E378E1F1CC59100DCAC9F /* RCTWebSocketModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */; }; 3D0E378F1F1CC5CF00DCAC9F /* RCTWebSocketModule.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */; }; @@ -1275,7 +1272,6 @@ 594F0A471FD233BD007FBE96 /* RCTSurfaceView.h in Copy Headers */, 594F0A481FD233BD007FBE96 /* RCTSurfaceHostingView.h in Copy Headers */, 594F0A491FD233BD007FBE96 /* RCTSurfaceSizeMeasureMode.h in Copy Headers */, - 2D16E68E1FA4FD3900B85C8A /* RCTTVNavigationEventEmitter.h in Copy Headers */, 59500D481F71C67600B122B7 /* RCTUIManagerUtils.h in Copy Headers */, 3D0E37901F1CC5E100DCAC9F /* RCTWebSocketModule.h in Copy Headers */, 5960C1BF1F0804F50066FD5B /* RCTLayoutAnimation.h in Copy Headers */, @@ -1876,8 +1872,6 @@ 39C50FFA2046EE3500CEE534 /* RCTVersion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTVersion.m; sourceTree = ""; }; 3D0B84281EC0B49400B2BD8E /* RCTTVRemoteHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVRemoteHandler.h; sourceTree = ""; }; 3D0B84291EC0B49400B2BD8E /* RCTTVRemoteHandler.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTVRemoteHandler.m; sourceTree = ""; }; - 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTTVNavigationEventEmitter.h; sourceTree = ""; }; - 3D0B842E1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTTVNavigationEventEmitter.m; sourceTree = ""; }; 3D0E37891F1CC40000DCAC9F /* RCTWebSocketModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RCTWebSocketModule.h; path = WebSocket/RCTWebSocketModule.h; sourceTree = ""; }; 3D1E68D81CABD13900DD7465 /* RCTDisplayLink.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDisplayLink.h; sourceTree = ""; }; 3D1E68D91CABD13900DD7465 /* RCTDisplayLink.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDisplayLink.m; sourceTree = ""; }; @@ -2346,8 +2340,6 @@ 0EEEA8DE2239002200A8C82D /* RCTSurfacePresenterStub.m */, 13B07FED1A69327A00A75B9A /* RCTTiming.h */, 13B07FEE1A69327A00A75B9A /* RCTTiming.m */, - 3D0B842D1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h */, - 3D0B842E1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m */, 13E067481A70F434002CDEE1 /* RCTUIManager.h */, 13E067491A70F434002CDEE1 /* RCTUIManager.m */, 59EB6DB91EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.h */, @@ -2945,7 +2937,6 @@ 3D302F311DF828F800D6DDAE /* RCTBundleURLProvider.h in Headers */, 3D302F321DF828F800D6DDAE /* RCTConvert.h in Headers */, 3D302F331DF828F800D6DDAE /* RCTDefines.h in Headers */, - 3D0B842F1EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.h in Headers */, 3D302F341DF828F800D6DDAE /* RCTDisplayLink.h in Headers */, 3D302F351DF828F800D6DDAE /* RCTErrorCustomizer.h in Headers */, 3D302F361DF828F800D6DDAE /* RCTErrorInfo.h in Headers */, @@ -3994,7 +3985,6 @@ 2D3B5EC81D9B095800451313 /* RCTActivityIndicatorViewManager.m in Sources */, 3DCD185D1DF978E7007FE5A1 /* RCTReloadCommand.m in Sources */, 130443DB1E401ADD00D93A67 /* RCTConvert+Transform.m in Sources */, - 3D0B84301EC0B51200B2BD8E /* RCTTVNavigationEventEmitter.m in Sources */, 2D3B5EC61D9B095000451313 /* RCTProfileTrampoline-x86_64.S in Sources */, 2D3B5EA61D9B08CA00451313 /* RCTTouchEvent.m in Sources */, 2D8C2E331DA40441000EE098 /* RCTMultipartStreamReader.m in Sources */, From 07eac0c6e21bf0ddbe5e87bd18a8940cff83a0b8 Mon Sep 17 00:00:00 2001 From: Pasquale Anatriello Date: Thu, 29 Oct 2020 09:23:02 -0700 Subject: [PATCH 13/33] Fix clone issue in YogaNodeJNIBase Summary: Changelog: Fix the cloneWithChildren implementation that was not copying the list of children on the java object. We were missing on copying the list of children when cloning. This is pretty bad as it means that the clone operation was mutating the old node as well as the new. When multiple threads were involved this could cause crashes. Reviewed By: SidharthGuglani Differential Revision: D24565307 fbshipit-source-id: 4e2e111db389e25c315ce7603b4018ac695bb0f1 --- java/com/facebook/yoga/YogaNodeJNIBase.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index 406e75e5..7ab391cc 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -116,6 +116,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { public YogaNodeJNIBase cloneWithChildren() { try { YogaNodeJNIBase clonedYogaNode = (YogaNodeJNIBase) super.clone(); + if (clonedYogaNode.mChildren != null) { + clonedYogaNode.mChildren = new ArrayList<>(clonedYogaNode.mChildren); + } long clonedNativePointer = YogaNative.jni_YGNodeCloneJNI(mNativePointer); clonedYogaNode.mOwner = null; clonedYogaNode.mNativePointer = clonedNativePointer; From e65b1ef6548d2ecfdf3d1cec230581be606a927e Mon Sep 17 00:00:00 2001 From: Kris Georges Date: Tue, 10 Nov 2020 08:21:19 -0800 Subject: [PATCH 14/33] Fix Yoga Playground website Litho codegen bugs Summary: Yoga Playground website changing direction results in no change to Litho code because of this typo Reviewed By: SidharthGuglani Differential Revision: D24818769 fbshipit-source-id: 1633513d4a25aead2008b59d52f669293214c598 --- website/src/components/Playground/src/CodeLitho.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/src/components/Playground/src/CodeLitho.js b/website/src/components/Playground/src/CodeLitho.js index 66e89a3e..cc96c840 100644 --- a/website/src/components/Playground/src/CodeLitho.js +++ b/website/src/components/Playground/src/CodeLitho.js @@ -24,7 +24,7 @@ function getEnum(yogaEnum: string, value: string | number): string { position: 'Position', flexWrap: 'Wrap', positionType: 'PositionType', - direction: 'Driection', + direction: 'Direction', }; if (!enumLookup[yogaEnum]) { From b043669972ee59bc3e7906e3707816ec3eccda1e Mon Sep 17 00:00:00 2001 From: Ron Edelstein Date: Thu, 17 Dec 2020 19:33:39 -0800 Subject: [PATCH 15/33] Explicitly set autoglob (long tail) Reviewed By: fbanurag, strulovich Differential Revision: D25620908 fbshipit-source-id: 1dd737d451ddfd07baa427902bdf1c96d7e67e64 --- android/sample/java/com/facebook/samples/yoga/BUCK | 1 + android/src/main/java/com/facebook/yoga/android/BUCK | 1 + 2 files changed, 2 insertions(+) diff --git a/android/sample/java/com/facebook/samples/yoga/BUCK b/android/sample/java/com/facebook/samples/yoga/BUCK index 31609016..502c19f3 100644 --- a/android/sample/java/com/facebook/samples/yoga/BUCK +++ b/android/sample/java/com/facebook/samples/yoga/BUCK @@ -8,6 +8,7 @@ load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID_JAVA_TARGET", "ANDROID_SAM yoga_android_library( name = "yoga", srcs = glob(["**/*.java"]), + autoglob = False, visibility = [ "PUBLIC", ], diff --git a/android/src/main/java/com/facebook/yoga/android/BUCK b/android/src/main/java/com/facebook/yoga/android/BUCK index c760ba0b..20408c78 100644 --- a/android/src/main/java/com/facebook/yoga/android/BUCK +++ b/android/src/main/java/com/facebook/yoga/android/BUCK @@ -8,6 +8,7 @@ load("//tools/build_defs/oss:yoga_defs.bzl", "ANDROID_RES_TARGET", "INFER_ANNOTA yoga_android_library( name = "android", srcs = glob(["**/*.java"]), + autoglob = False, visibility = [ "PUBLIC", ], From a38ec3d7a493c5497016d4d1b4e05b89cf5d6f65 Mon Sep 17 00:00:00 2001 From: Panagiotis Vekris Date: Mon, 4 Jan 2021 21:05:07 -0800 Subject: [PATCH 16/33] pin "classic" roots to v0.140 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: In Flow v0.143 types-first will become the only supported mode in Flow. As such the `types_first` configuration option will become invalid. To prevent breaking roots that have `types_first=false` set and are **unversioned**, this diff pins their version to v0.140, which is the last released version in fbsource. ## Repro First compute the list of all `.flowconfig`s: ``` zbgf '.flowconfig$' | grep -v '^fbsource/fbcode/flow' | grep -v 'Binary file' | awk -F':' '{ print $1 }' | sort -u > all-flowconfigs.txt ``` Compute `.flowconfig`s that don’t have a version: ``` zbgs -f '\.flowconfig' '[version]' | grep -v '^fbsource/fbcode/flow' | grep -v 'Binary file' | awk -F':' '{ print $1 }' | sort -u > versioned-flowconfigs.txt comm -23 all-flowconfigs.txt versioned-flowconfigs.txt > unversioned-flowconfigs.txt ``` Compute `.flowconfig`s that have `types_first=false`: ``` zbgr -f '\.flowconfig' '^types_first=false$' | grep -v '^fbsource/fbcode/flow' | grep -v 'Binary file' | awk -F':' '{ print $1 }' | sort -u > types_first-false-flowconfigs.txt ``` **and** no pinned version: ``` comm -12 unversioned-flowconfigs.txt types_first-false-flowconfigs.txt | grep 'fbsource' > pin-version-flowconfigs.txt ``` Update the `.flowconfig`s: ``` cat ~/scratch/flowconfigs/pin-version-flowconfigs-fbsource.txt | xargs -I{} bash -c 'printf "\n[version]\n^0.140.0\n" >> {}' ``` Reviewed By: mroch Differential Revision: D25771452 fbshipit-source-id: 876d6310e4e1aafb81d3ef3051f4e9e9e838a633 --- javascript/.flowconfig | 3 +++ website/.flowconfig | 3 +++ 2 files changed, 6 insertions(+) diff --git a/javascript/.flowconfig b/javascript/.flowconfig index 6a0c16ae..6bd402f8 100644 --- a/javascript/.flowconfig +++ b/javascript/.flowconfig @@ -10,3 +10,6 @@ types_first=false [strict] + +[version] +^0.140.0 diff --git a/website/.flowconfig b/website/.flowconfig index 6a0c16ae..6bd402f8 100644 --- a/website/.flowconfig +++ b/website/.flowconfig @@ -10,3 +10,6 @@ types_first=false [strict] + +[version] +^0.140.0 From 584dfe961e6220d684bfd847facb4e7b2717a712 Mon Sep 17 00:00:00 2001 From: Andres Suarez Date: Sun, 10 Jan 2021 10:03:53 -0800 Subject: [PATCH 17/33] Apply clang-format update fixes Reviewed By: igorsugak Differential Revision: D25861849 fbshipit-source-id: 840dc1061e557717c7f9ffcccbc09c24b96b78e0 --- .../YogaKitSample/ViewController.m | 18 +++++++------ javascript/sources/Node.cc | 4 +-- tests/EventsTest.cpp | 4 +-- tests/YGComputedMarginTest.cpp | 26 ++++++++++--------- tests/YGComputedPaddingTest.cpp | 26 ++++++++++--------- tests/YGTreeMutationTest.cpp | 21 ++++++++------- yoga/CompactValue.h | 4 +-- yoga/Yoga.cpp | 4 +-- 8 files changed, 57 insertions(+), 50 deletions(-) diff --git a/YogaKit/YogaKitSample/YogaKitSample/ViewController.m b/YogaKit/YogaKitSample/YogaKitSample/ViewController.m index 145fa47b..dedf03d2 100644 --- a/YogaKit/YogaKitSample/YogaKitSample/ViewController.m +++ b/YogaKit/YogaKitSample/YogaKitSample/ViewController.m @@ -28,17 +28,19 @@ UIView* child2 = [UIView new]; child2.backgroundColor = [UIColor greenColor]; - child2.frame = (CGRect){.size = { - .width = 200, - .height = 100, - }}; + child2.frame = (CGRect){ + .size = { + .width = 200, + .height = 100, + }}; UIView* child3 = [UIView new]; child3.backgroundColor = [UIColor yellowColor]; - child3.frame = (CGRect){.size = { - .width = 100, - .height = 100, - }}; + child3.frame = (CGRect){ + .size = { + .width = 100, + .height = 100, + }}; [child2 addSubview:child3]; [root addSubview:child1]; diff --git a/javascript/sources/Node.cc b/javascript/sources/Node.cc index 7e6833fe..421cfa71 100644 --- a/javascript/sources/Node.cc +++ b/javascript/sources/Node.cc @@ -23,8 +23,8 @@ static YGSize globalMeasureFunc( Node const& node = *reinterpret_cast(YGNodeGetContext(nodeRef)); Size size = node.callMeasureFunc(width, widthMode, height, heightMode); - YGSize ygSize = {static_cast(size.width), - static_cast(size.height)}; + YGSize ygSize = { + static_cast(size.width), static_cast(size.height)}; return ygSize; } diff --git a/tests/EventsTest.cpp b/tests/EventsTest.cpp index cf887b2d..e8300846 100644 --- a/tests/EventsTest.cpp +++ b/tests/EventsTest.cpp @@ -303,8 +303,8 @@ EventArgs createArgs( }; EventArgs args = createArgs(node, data); - args.eventTestDataPtr = {new EventTestData{eventTestData}, - deleteEventTestData}; + args.eventTestDataPtr = { + new EventTestData{eventTestData}, deleteEventTestData}; return args; } diff --git a/tests/YGComputedMarginTest.cpp b/tests/YGComputedMarginTest.cpp index b74e4174..fedfd561 100644 --- a/tests/YGComputedMarginTest.cpp +++ b/tests/YGComputedMarginTest.cpp @@ -29,12 +29,13 @@ TEST(YogaTest, computed_layout_margin) { } TEST(YogaTest, margin_side_overrides_horizontal_and_vertical) { - const std::array edges = {{YGEdgeTop, - YGEdgeBottom, - YGEdgeStart, - YGEdgeEnd, - YGEdgeLeft, - YGEdgeRight}}; + const std::array edges = { + {YGEdgeTop, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeLeft, + YGEdgeRight}}; for (float edgeValue = 0; edgeValue < 2; ++edgeValue) { for (const auto& edge : edges) { @@ -58,12 +59,13 @@ TEST(YogaTest, margin_side_overrides_horizontal_and_vertical) { } TEST(YogaTest, margin_side_overrides_all) { - const std::array edges = {{YGEdgeTop, - YGEdgeBottom, - YGEdgeStart, - YGEdgeEnd, - YGEdgeLeft, - YGEdgeRight}}; + const std::array edges = { + {YGEdgeTop, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeLeft, + YGEdgeRight}}; for (float edgeValue = 0; edgeValue < 2; ++edgeValue) { for (const auto& edge : edges) { diff --git a/tests/YGComputedPaddingTest.cpp b/tests/YGComputedPaddingTest.cpp index 677ed3a6..c3aabab7 100644 --- a/tests/YGComputedPaddingTest.cpp +++ b/tests/YGComputedPaddingTest.cpp @@ -29,12 +29,13 @@ TEST(YogaTest, computed_layout_padding) { } TEST(YogaTest, padding_side_overrides_horizontal_and_vertical) { - const std::array edges = {{YGEdgeTop, - YGEdgeBottom, - YGEdgeStart, - YGEdgeEnd, - YGEdgeLeft, - YGEdgeRight}}; + const std::array edges = { + {YGEdgeTop, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeLeft, + YGEdgeRight}}; for (float edgeValue = 0; edgeValue < 2; ++edgeValue) { for (const auto& edge : edges) { @@ -58,12 +59,13 @@ TEST(YogaTest, padding_side_overrides_horizontal_and_vertical) { } TEST(YogaTest, padding_side_overrides_all) { - const std::array edges = {{YGEdgeTop, - YGEdgeBottom, - YGEdgeStart, - YGEdgeEnd, - YGEdgeLeft, - YGEdgeRight}}; + const std::array edges = { + {YGEdgeTop, + YGEdgeBottom, + YGEdgeStart, + YGEdgeEnd, + YGEdgeLeft, + YGEdgeRight}}; for (float edgeValue = 0; edgeValue < 2; ++edgeValue) { for (const auto& edge : edges) { diff --git a/tests/YGTreeMutationTest.cpp b/tests/YGTreeMutationTest.cpp index bf07f39e..26f0b900 100644 --- a/tests/YGTreeMutationTest.cpp +++ b/tests/YGTreeMutationTest.cpp @@ -29,8 +29,8 @@ TEST(YogaTest, set_children_adds_children_to_parent) { const std::vector expectedChildren = {root_child0, root_child1}; ASSERT_EQ(children, expectedChildren); - const std::vector owners = {YGNodeGetOwner(root_child0), - YGNodeGetOwner(root_child1)}; + const std::vector owners = { + YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; const std::vector expectedOwners = {root, root}; ASSERT_EQ(owners, expectedOwners); @@ -49,8 +49,8 @@ TEST(YogaTest, set_children_to_empty_removes_old_children) { const std::vector expectedChildren = {}; ASSERT_EQ(children, expectedChildren); - const std::vector owners = {YGNodeGetOwner(root_child0), - YGNodeGetOwner(root_child1)}; + const std::vector owners = { + YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; const std::vector expectedOwners = {nullptr, nullptr}; ASSERT_EQ(owners, expectedOwners); @@ -73,8 +73,8 @@ TEST(YogaTest, set_children_replaces_non_common_children) { const std::vector expectedChildren = {root_child2, root_child3}; ASSERT_EQ(children, expectedChildren); - const std::vector owners = {YGNodeGetOwner(root_child0), - YGNodeGetOwner(root_child1)}; + const std::vector owners = { + YGNodeGetOwner(root_child0), YGNodeGetOwner(root_child1)}; const std::vector expectedOwners = {nullptr, nullptr}; ASSERT_EQ(owners, expectedOwners); @@ -100,10 +100,11 @@ TEST(YogaTest, set_children_keeps_and_reorders_common_children) { root_child2, root_child1, root_child3}; ASSERT_EQ(children, expectedChildren); - const std::vector owners = {YGNodeGetOwner(root_child0), - YGNodeGetOwner(root_child1), - YGNodeGetOwner(root_child2), - YGNodeGetOwner(root_child3)}; + const std::vector owners = { + YGNodeGetOwner(root_child0), + YGNodeGetOwner(root_child1), + YGNodeGetOwner(root_child2), + YGNodeGetOwner(root_child3)}; const std::vector expectedOwners = {nullptr, root, root, root}; ASSERT_EQ(owners, expectedOwners); diff --git a/yoga/CompactValue.h b/yoga/CompactValue.h index be933a16..f398668e 100644 --- a/yoga/CompactValue.h +++ b/yoga/CompactValue.h @@ -125,8 +125,8 @@ public: data.repr &= ~PERCENT_BIT; data.repr += BIAS; - return YGValue{data.value, - payload_.repr & 0x40000000 ? YGUnitPercent : YGUnitPoint}; + return YGValue{ + data.value, payload_.repr & 0x40000000 ? YGUnitPercent : YGUnitPoint}; } bool isUndefined() const noexcept { diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 97e64075..2db6be21 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3531,8 +3531,8 @@ static void YGNodelayoutImpl( YGNodeBoundAxisWithinMinAndMax( node, crossAxis, - YGFloatOptional{totalLineCrossDim + - paddingAndBorderAxisCross}, + YGFloatOptional{ + totalLineCrossDim + paddingAndBorderAxisCross}, crossAxisownerSize) .unwrap()), paddingAndBorderAxisCross), From 2cb46cf3e2c9d47662dafe370e8c67e5838cd5e5 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Fri, 5 Feb 2021 03:39:55 -0800 Subject: [PATCH 18/33] instance of checks for YogaNodeJniBase Summary: Changelog: [Internal][Yoga] - Added instance of checks in `YogaNodeJNIBase` class to prevent `ClassCastException`s. This was happening for some NT android tests - Mocked Yoga Node object was being passed in the `addChildAt` api Stack Trace of exception java.lang.ClassCastException: com.facebook.yoga.YogaNode$MockitoMock$1408896622 cannot be cast to com.facebook.yoga.YogaNodeJNIBase at com.facebook.yoga.YogaNodeJNIBase.addChildAt(YogaNodeJNIBase.java:86) at com.facebook.litho.DefaultInternalNode.addChildAt(DefaultInternalNode.java:220) at com.facebook.litho.DefaultInternalNode.child(DefaultInternalNode.java:377) at com.facebook.litho.DefaultInternalNode.child(DefaultInternalNode.java:360) at com.facebook.litho.Column.resolve(Column.java:118) at com.facebook.litho.Layout.create(Layout.java:172) Reviewed By: Andrey-Mishanin Differential Revision: D26114992 fbshipit-source-id: 774a689609e67f9244b81c6788b62cd61cd96d14 --- java/com/facebook/yoga/YogaNodeJNIBase.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index 7ab391cc..6b3dcd26 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -83,6 +83,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } public void addChildAt(YogaNode c, int i) { + if (!(c instanceof YogaNodeJNIBase)) { + return; + } YogaNodeJNIBase child = (YogaNodeJNIBase) c; if (child.mOwner != null) { throw new IllegalStateException("Child already has a parent, it must be removed first."); @@ -105,6 +108,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { } public void swapChildAt(YogaNode newChild, int position) { + if (!(newChild instanceof YogaNodeJNIBase)) { + return; + } YogaNodeJNIBase child = (YogaNodeJNIBase) newChild; mChildren.remove(position); mChildren.add(position, child); @@ -223,6 +229,9 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { @Override public void copyStyle(YogaNode srcNode) { + if (!(srcNode instanceof YogaNodeJNIBase)) { + return; + } YogaNative.jni_YGNodeCopyStyleJNI(mNativePointer, ((YogaNodeJNIBase) srcNode).mNativePointer); } From 651c527e946826b36e1466981adbe08701ceb7a6 Mon Sep 17 00:00:00 2001 From: Ruslan Serebriakov Date: Thu, 11 Feb 2021 10:37:41 -0800 Subject: [PATCH 19/33] CKDimension Summary: [rsrbk@devvm3461.lla0 /data/users/rsrbk/fbsource/fbobjc] fastmod --accept-all CKRelativeDimension RCRelativeDimension [rsrbk@devvm3461.lla0 /data/users/rsrbk/fbsource/fbobjc] fastmod --accept-all CKRelativeSize RCRelativeSize [rsrbk@devvm3461.lla0 /data/users/rsrbk/fbsource/fbobjc] fastmod --accept-all ComponentKit/RCDimension.h RenderCore/RCDimension.h Reviewed By: kfirapps Differential Revision: D26228615 fbshipit-source-id: 9c06128b324e1c6ece6fc21fbab1c041e5f5825a --- website/src/components/Playground/src/CodeComponentKit.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/src/components/Playground/src/CodeComponentKit.js b/website/src/components/Playground/src/CodeComponentKit.js index 74cc2db2..00111508 100644 --- a/website/src/components/Playground/src/CodeComponentKit.js +++ b/website/src/components/Playground/src/CodeComponentKit.js @@ -73,9 +73,9 @@ function keyLookup(key: string): string { function getValue(value) { if (typeof value === 'string' && /%$/.test(value)) { - return `CKRelativeDimension::Percent(${parseFloat(value)})`; + return `RCRelativeDimension::Percent(${parseFloat(value)})`; } else if (value === 'auto') { - return 'CKRelativeDimension::Auto()'; + return 'RCRelativeDimension::Auto()'; } else { return String(parseFloat(value)); } From de36e85004dce6ef0f2cee9208bfee9036db7e04 Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Tue, 16 Feb 2021 10:17:36 -0800 Subject: [PATCH 20/33] Adds InternalNode#freeze() API Summary: Litho needs a new API which is called immediately before yoga begins layout calculations so that the InternalNode gets the opportunity to finalise itself; i.e. perform the last mutations and in effect avoid any more mutations to the hierarchy. See D26373731 where the mutations from `Layout#collectResults` is moved back into the InternalNode. Changelog: [Internal] Adds new API to YogaNodeJNIBase Reviewed By: SidharthGuglani Differential Revision: D26373730 fbshipit-source-id: 471346d3444986ada91e86c95f5f9fb98bcd2fa6 --- java/com/facebook/yoga/YogaNode.java | 18 ++++++++++++------ java/com/facebook/yoga/YogaNodeJNIBase.java | 14 +++++++++++++- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index 9fc8bac9..dfec8ec5 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -10,6 +10,14 @@ package com.facebook.yoga; import javax.annotation.Nullable; public abstract class YogaNode { + + /** The interface the {@link #getData()} object can optionally implement. */ + public interface Inputs { + + /** Requests the data object to disable mutations of its inputs. */ + void freeze(); + } + public abstract void reset(); public abstract int getChildCount(); @@ -25,12 +33,10 @@ public abstract class YogaNode { public abstract YogaNode removeChildAt(int i); /** - * @returns the {@link YogaNode} that owns this {@link YogaNode}. - * The owner is used to identify the YogaTree that a {@link YogaNode} belongs - * to. - * This method will return the parent of the {@link YogaNode} when the - * {@link YogaNode} only belongs to one YogaTree or null when the - * {@link YogaNode} is shared between two or more YogaTrees. + * @returns the {@link YogaNode} that owns this {@link YogaNode}. The owner is used to identify + * the YogaTree that a {@link YogaNode} belongs to. This method will return the parent of the + * {@link YogaNode} when the {@link YogaNode} only belongs to one YogaTree or null when the + * {@link YogaNode} is shared between two or more YogaTrees. */ @Nullable public abstract YogaNode getOwner(); diff --git a/java/com/facebook/yoga/YogaNodeJNIBase.java b/java/com/facebook/yoga/YogaNodeJNIBase.java index 6b3dcd26..03354556 100644 --- a/java/com/facebook/yoga/YogaNodeJNIBase.java +++ b/java/com/facebook/yoga/YogaNodeJNIBase.java @@ -197,12 +197,17 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { long[] nativePointers = null; YogaNodeJNIBase[] nodes = null; + freeze(); + ArrayList n = new ArrayList<>(); n.add(this); for (int i = 0; i < n.size(); ++i) { List children = n.get(i).mChildren; if (children != null) { - n.addAll(children); + for (YogaNodeJNIBase child : children) { + child.freeze(); + n.add(child); + } } } @@ -215,6 +220,13 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable { YogaNative.jni_YGNodeCalculateLayoutJNI(mNativePointer, width, height, nativePointers, nodes); } + private void freeze() { + Object data = getData(); + if (data instanceof Inputs) { + ((Inputs) data).freeze(); + } + } + public void dirty() { YogaNative.jni_YGNodeMarkDirtyJNI(mNativePointer); } From 36e70c9ca0ef4817d8f05caf0f8f49709ab24141 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Thu, 25 Feb 2021 06:34:24 -0800 Subject: [PATCH 21/33] Fix Yoga test Summary: Changelog: [Internal][Yoga] Fixed unit test for default yoga style property Reviewed By: pasqualeanatriello Differential Revision: D26664040 fbshipit-source-id: 9c0af4e846ead3d90c75753e836570ccac760178 --- java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java b/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java index 649c7279..c39ea024 100644 --- a/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeStylePropertiesTest.java @@ -191,7 +191,7 @@ public class YogaNodeStylePropertiesTest { public void testPositionTypeDefault() { final YogaNode node = createNode(); - assertEquals(YogaPositionType.RELATIVE, node.getPositionType()); + assertEquals(YogaPositionType.STATIC, node.getPositionType()); } @Test From 0429704d5ec4f565056005d899dabd47089bf961 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Thu, 25 Feb 2021 06:34:24 -0800 Subject: [PATCH 22/33] version bump Reviewed By: pasqualeanatriello Differential Revision: D26664041 fbshipit-source-id: 5a4d0d176074c8831dd18681993463fe25e2642f --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 820eae63..4dc8a8e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1536M -VERSION_NAME=1.16.0-SNAPSHOT +VERSION_NAME=1.17.0 POM_URL=https://github.com/facebook/yoga POM_SCM_URL=https://github.com/facebook/yoga.git POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git From c1a28f3f54bfed299199b4a8916818891a7be055 Mon Sep 17 00:00:00 2001 From: Sidharth Guglani Date: Thu, 25 Feb 2021 06:34:24 -0800 Subject: [PATCH 23/33] Add back snapshot in version for next release Summary: Changelog: [Internal][Yoga] version bump Reviewed By: pasqualeanatriello Differential Revision: D26664063 fbshipit-source-id: ceb8d31a99f85db7d1fde20bd77584a537d356c6 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4dc8a8e6..382f62fa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ org.gradle.jvmargs=-Xmx1536M -VERSION_NAME=1.17.0 +VERSION_NAME=1.17.0-SNAPSHOT POM_URL=https://github.com/facebook/yoga POM_SCM_URL=https://github.com/facebook/yoga.git POM_SCM_CONNECTION=scm:git:https://github.com/facebook/yoga.git From ccdea0f31bc71d9297b767ba567f7c1f2e2ee30a Mon Sep 17 00:00:00 2001 From: Stiopa Koltsov Date: Mon, 1 Mar 2021 13:13:44 -0800 Subject: [PATCH 24/33] xplat: switch random files to Starlark Summary: We need to get rid of all `# BUILD FILE SYNTAX: PYTHON_DSL` to disable hybrid parser after we make Starlark default everywhere. This is first bunch of changes. Reviewed By: mzlee Differential Revision: D26727784 fbshipit-source-id: 05c5f4d039feb4ce06169ac6d2fc5c49711125cd --- java/BUCK | 2 -- 1 file changed, 2 deletions(-) diff --git a/java/BUCK b/java/BUCK index fa0250a3..627c5678 100644 --- a/java/BUCK +++ b/java/BUCK @@ -1,5 +1,3 @@ -# BUILD FILE SYNTAX: PYTHON_DSL - # Copyright (c) Facebook, Inc. and its affiliates. # # This source code is licensed under the MIT license found in the From 1745c23a122cf04013e18631802670421415be21 Mon Sep 17 00:00:00 2001 From: Andrew Coates <30809111+acoates-ms@users.noreply.github.com> Date: Wed, 10 Mar 2021 12:36:47 -0800 Subject: [PATCH 25/33] Fix various C++ warnings (#31002) Summary: Fix warnings about implicit type truncation. ## Changelog [Internal] [Fixed] - Fix various C++ warnings Pull Request resolved: https://github.com/facebook/react-native/pull/31002 Test Plan: Almost all the changes here are simply making explicit conversions which are already occurring. With the exception of a couple of constants being changed from doubles to floats. With these changes I am able to remove a bunch of warning suppressions in react-native-windows. Reviewed By: shergin Differential Revision: D26900502 Pulled By: rozele fbshipit-source-id: d5e415282815c2212a840a863713287bbf118c10 --- yoga/BitUtils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yoga/BitUtils.h b/yoga/BitUtils.h index 1c32e9ec..2161effc 100644 --- a/yoga/BitUtils.h +++ b/yoga/BitUtils.h @@ -45,8 +45,9 @@ void setEnumData(uint32_t& flags, size_t index, int newValue) { template void setEnumData(uint8_t& flags, size_t index, int newValue) { - flags = (flags & ~mask(bitWidthFn(), index)) | - ((newValue << index) & (mask(bitWidthFn(), index))); + flags = (flags & ~static_cast(mask(bitWidthFn(), index))) | + ((newValue << index) & + (static_cast(mask(bitWidthFn(), index)))); } constexpr bool getBooleanData(int flags, size_t index) { From 342aebe1d73e5770a1862b6a94c6b877c1439a9b Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 10 Mar 2021 13:08:48 -0800 Subject: [PATCH 26/33] Fixes layout of nodes with YGDisplayNone and YGPositionTypeAbsolute (#1068) Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1068 There is an issue in react-native when the Yoga node position type is set to absolute and display: none is set where the node layout calculation gives the absolute dimensions, rather than the expected 0 x 0. Here are some OSS issues tracking this: https://github.com/facebook/react-native/issues/18415 https://github.com/microsoft/react-native-windows/issues/7289 ## Changelog [General] [Fix] - Fixes layout of nodes with YGDisplayNone and YGPositionTypeAbsolute Reviewed By: Andrey-Mishanin Differential Revision: D26849307 fbshipit-source-id: 197618aa3c4e1b3b7efeba7ea4efd30b2d1c982d --- csharp/tests/Facebook.Yoga/YGDisplayTest.cs | 49 ++++++++++++++++-- gentest/fixtures/YGDisplayTest.html | 4 ++ gentest/gentest.js | 6 +-- gentest/gentest.rb | 15 +++--- .../com/facebook/yoga/YGDisplayTest.java | 48 ++++++++++++++++-- .../tests/Facebook.Yoga/YGDisplayTest.js | 50 ++++++++++++++++++- tests/YGDisplayTest.cpp | 47 ++++++++++++++++- yoga/Yoga.cpp | 3 +- 8 files changed, 201 insertions(+), 21 deletions(-) diff --git a/csharp/tests/Facebook.Yoga/YGDisplayTest.cs b/csharp/tests/Facebook.Yoga/YGDisplayTest.cs index 237686ba..659cb37f 100644 --- a/csharp/tests/Facebook.Yoga/YGDisplayTest.cs +++ b/csharp/tests/Facebook.Yoga/YGDisplayTest.cs @@ -1,9 +1,10 @@ -/** +/* * Copyright (c) Facebook, Inc. and its affiliates. * - * This source code is licensed under the MIT license found in the LICENSE - * file in the root directory of this source tree. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ + // @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html using System; @@ -333,5 +334,47 @@ namespace Facebook.Yoga Assert.AreEqual(0f, root_child1.LayoutHeight); } + [Test] + public void Test_display_none_with_position_absolute() + { + YogaConfig config = new YogaConfig(); + + YogaNode root = new YogaNode(config); + root.Width = 100; + root.Height = 100; + + YogaNode root_child0 = new YogaNode(config); + root_child0.PositionType = YogaPositionType.Absolute; + root_child0.Width = 100; + root_child0.Height = 100; + root_child0.Display = YogaDisplay.None; + root.Insert(0, root_child0); + root.StyleDirection = YogaDirection.LTR; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(0f, root_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0.LayoutHeight); + + root.StyleDirection = YogaDirection.RTL; + root.CalculateLayout(); + + Assert.AreEqual(0f, root.LayoutX); + Assert.AreEqual(0f, root.LayoutY); + Assert.AreEqual(100f, root.LayoutWidth); + Assert.AreEqual(100f, root.LayoutHeight); + + Assert.AreEqual(0f, root_child0.LayoutX); + Assert.AreEqual(0f, root_child0.LayoutY); + Assert.AreEqual(0f, root_child0.LayoutWidth); + Assert.AreEqual(0f, root_child0.LayoutHeight); + } + } } diff --git a/gentest/fixtures/YGDisplayTest.html b/gentest/fixtures/YGDisplayTest.html index 74d11ba4..f11533f8 100644 --- a/gentest/fixtures/YGDisplayTest.html +++ b/gentest/fixtures/YGDisplayTest.html @@ -25,3 +25,7 @@

+ +
+
+
diff --git a/gentest/gentest.js b/gentest/gentest.js index ca370928..12e76f33 100755 --- a/gentest/gentest.js +++ b/gentest/gentest.js @@ -41,11 +41,11 @@ function assert(condition, message) { function printTest(e, LTRContainer, RTLContainer, genericContainer) { e.push([ - '/**', + '/*', ' * Copyright (c) Facebook, Inc. and its affiliates.', ' *', - ' * This source code is licensed under the MIT license found in the LICENSE', - ' * file in the root directory of this source tree.', + ' * This source code is licensed under the MIT license found in the', + ' * LICENSE file in the root directory of this source tree.', ' */', '// @Generated by gentest/gentest.rb from gentest/fixtures/' + document.title + '.html', '', diff --git a/gentest/gentest.rb b/gentest/gentest.rb index 22114501..01fec93e 100644 --- a/gentest/gentest.rb +++ b/gentest/gentest.rb @@ -7,13 +7,14 @@ require 'watir' require 'fileutils' -caps = Selenium::WebDriver::Remote::Capabilities.chrome( - "loggingPrefs"=>{ - "browser"=>"ALL", - "performance"=>"ALL" - } -) -browser = Watir::Browser.new(:chrome, :desired_capabilities => caps, :switches => ['--force-device-scale-factor=1', '--window-position=0,0']) +browser = Watir::Browser.new(:chrome, "goog:loggingPrefs" => { + "browser" => "ALL", + "performance" => "ALL" + }, + "chromeOptions" => { + "w3c" => "false" + }, + :switches => ['--force-device-scale-factor=1', '--window-position=0,0']) Dir.chdir(File.dirname($0)) diff --git a/java/tests/com/facebook/yoga/YGDisplayTest.java b/java/tests/com/facebook/yoga/YGDisplayTest.java index f1e6f896..999548bd 100644 --- a/java/tests/com/facebook/yoga/YGDisplayTest.java +++ b/java/tests/com/facebook/yoga/YGDisplayTest.java @@ -1,9 +1,10 @@ -/** +/* * Copyright (c) Facebook, Inc. and its affiliates. * - * This source code is licensed under the MIT license found in the LICENSE - * file in the root directory of this source tree. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ + // @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html package com.facebook.yoga; @@ -337,6 +338,47 @@ public class YGDisplayTest { assertEquals(0f, root_child1.getLayoutHeight(), 0.0f); } + @Test + public void test_display_none_with_position_absolute() { + YogaConfig config = YogaConfigFactory.create(); + + final YogaNode root = createNode(config); + root.setWidth(100f); + root.setHeight(100f); + + final YogaNode root_child0 = createNode(config); + root_child0.setPositionType(YogaPositionType.ABSOLUTE); + root_child0.setWidth(100f); + root_child0.setHeight(100f); + root_child0.setDisplay(YogaDisplay.NONE); + root.addChildAt(root_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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_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(100f, root.getLayoutWidth(), 0.0f); + assertEquals(100f, root.getLayoutHeight(), 0.0f); + + assertEquals(0f, root_child0.getLayoutX(), 0.0f); + assertEquals(0f, root_child0.getLayoutY(), 0.0f); + assertEquals(0f, root_child0.getLayoutWidth(), 0.0f); + assertEquals(0f, root_child0.getLayoutHeight(), 0.0f); + } + private YogaNode createNode(YogaConfig config) { return mNodeFactory.create(config); } diff --git a/javascript/tests/Facebook.Yoga/YGDisplayTest.js b/javascript/tests/Facebook.Yoga/YGDisplayTest.js index e5be4a55..cf65ab22 100644 --- a/javascript/tests/Facebook.Yoga/YGDisplayTest.js +++ b/javascript/tests/Facebook.Yoga/YGDisplayTest.js @@ -1,9 +1,10 @@ /** * Copyright (c) Facebook, Inc. and its affiliates. * - * This source code is licensed under the MIT license found in the LICENSE - * file in the root directory of this source tree. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ + // @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html var Yoga = Yoga || require("../../sources/entry-" + process.env.TEST_ENTRY); @@ -342,3 +343,48 @@ it("display_none_with_position", function () { config.free(); } }); +it("display_none_with_position_absolute", function () { + var config = Yoga.Config.create(); + + try { + var root = Yoga.Node.create(config); + root.setWidth(100); + root.setHeight(100); + + var root_child0 = Yoga.Node.create(config); + root_child0.setPositionType(Yoga.POSITION_TYPE_ABSOLUTE); + root_child0.setWidth(100); + root_child0.setHeight(100); + root_child0.setDisplay(Yoga.DISPLAY_NONE); + root.insertChild(root_child0, 0); + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_LTR); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + + root.calculateLayout(Yoga.UNDEFINED, Yoga.UNDEFINED, Yoga.DIRECTION_RTL); + + console.assert(0 === root.getComputedLeft(), "0 === root.getComputedLeft() (" + root.getComputedLeft() + ")"); + console.assert(0 === root.getComputedTop(), "0 === root.getComputedTop() (" + root.getComputedTop() + ")"); + console.assert(100 === root.getComputedWidth(), "100 === root.getComputedWidth() (" + root.getComputedWidth() + ")"); + console.assert(100 === root.getComputedHeight(), "100 === root.getComputedHeight() (" + root.getComputedHeight() + ")"); + + console.assert(0 === root_child0.getComputedLeft(), "0 === root_child0.getComputedLeft() (" + root_child0.getComputedLeft() + ")"); + console.assert(0 === root_child0.getComputedTop(), "0 === root_child0.getComputedTop() (" + root_child0.getComputedTop() + ")"); + console.assert(0 === root_child0.getComputedWidth(), "0 === root_child0.getComputedWidth() (" + root_child0.getComputedWidth() + ")"); + console.assert(0 === root_child0.getComputedHeight(), "0 === root_child0.getComputedHeight() (" + root_child0.getComputedHeight() + ")"); + } finally { + if (typeof root !== "undefined") { + root.freeRecursive(); + } + + config.free(); + } +}); diff --git a/tests/YGDisplayTest.cpp b/tests/YGDisplayTest.cpp index ebd2bcd5..edc53358 100644 --- a/tests/YGDisplayTest.cpp +++ b/tests/YGDisplayTest.cpp @@ -1,9 +1,10 @@ /* * Copyright (c) Facebook, Inc. and its affiliates. * - * This source code is licensed under the MIT license found in the LICENSE - * file in the root directory of this source tree. + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. */ + // @Generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html #include @@ -327,3 +328,45 @@ TEST(YogaTest, display_none_with_position) { YGConfigFree(config); } + +TEST(YogaTest, display_none_with_position_absolute) { + const YGConfigRef config = YGConfigNew(); + + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeStyleSetWidth(root, 100); + YGNodeStyleSetHeight(root, 100); + + const YGNodeRef root_child0 = YGNodeNewWithConfig(config); + YGNodeStyleSetPositionType(root_child0, YGPositionTypeAbsolute); + YGNodeStyleSetWidth(root_child0, 100); + YGNodeStyleSetHeight(root_child0, 100); + YGNodeStyleSetDisplay(root_child0, YGDisplayNone); + YGNodeInsertChild(root, root_child0, 0); + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionLTR); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + YGNodeCalculateLayout(root, YGUndefined, YGUndefined, YGDirectionRTL); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetWidth(root)); + ASSERT_FLOAT_EQ(100, YGNodeLayoutGetHeight(root)); + + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetLeft(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetTop(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetWidth(root_child0)); + ASSERT_FLOAT_EQ(0, YGNodeLayoutGetHeight(root_child0)); + + YGNodeFreeRecursive(root); + + YGConfigFree(config); +} diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 2db6be21..f24563df 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -3557,7 +3557,8 @@ static void YGNodelayoutImpl( if (performLayout) { // STEP 10: SIZING AND POSITIONING ABSOLUTE CHILDREN for (auto child : node->getChildren()) { - if (child->getStyle().positionType() != YGPositionTypeAbsolute) { + if (child->getStyle().display() == YGDisplayNone || + child->getStyle().positionType() != YGPositionTypeAbsolute) { continue; } YGNodeAbsoluteLayoutChild( From 41384fab7b64824d9e7dd15ba042ee86ad5dc1b6 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 15 Mar 2021 16:53:05 -0700 Subject: [PATCH 27/33] Optimize edge value resolution Summary: Noticed in simpleperf this was a very hot method, showing 8ms spent in these methods in our sample application. By splitting the method out in a horizontal and vertical variant we can simplify cases enormously and check for begin/end in one go. Changelog: [Internal] Reviewed By: SidharthGuglani Differential Revision: D27010008 fbshipit-source-id: 22fed58c7476e1d716b0191b55997c7a06e63223 --- yoga/YGNode.cpp | 221 ++++++++++++++++++++++--------------------- yoga/YGNode.h | 11 +++ yoga/YGNodePrint.cpp | 11 ++- yoga/Yoga-internal.h | 5 - yoga/Yoga.cpp | 30 ------ 5 files changed, 129 insertions(+), 149 deletions(-) diff --git a/yoga/YGNode.cpp b/yoga/YGNode.cpp index 1ee1bde6..f4c14bf3 100644 --- a/yoga/YGNode.cpp +++ b/yoga/YGNode.cpp @@ -50,89 +50,111 @@ void YGNode::print(void* printContext) { } } +CompactValue YGNode::computeEdgeValueForRow( + const YGStyle::Edges& edges, + YGEdge rowEdge, + YGEdge edge, + CompactValue defaultValue) { + if (!edges[rowEdge].isUndefined()) { + return edges[rowEdge]; + } else if (!edges[edge].isUndefined()) { + return edges[edge]; + } else if (!edges[YGEdgeHorizontal].isUndefined()) { + return edges[YGEdgeHorizontal]; + } else if (!edges[YGEdgeAll].isUndefined()) { + return edges[YGEdgeAll]; + } else { + return defaultValue; + } +} + +CompactValue YGNode::computeEdgeValueForColumn( + const YGStyle::Edges& edges, + YGEdge edge, + CompactValue defaultValue) { + if (!edges[edge].isUndefined()) { + return edges[edge]; + } else if (!edges[YGEdgeVertical].isUndefined()) { + return edges[YGEdgeVertical]; + } else if (!edges[YGEdgeAll].isUndefined()) { + return edges[YGEdgeAll]; + } else { + return defaultValue; + } +} + YGFloatOptional YGNode::getLeadingPosition( const YGFlexDirection axis, const float axisSize) const { - if (YGFlexDirectionIsRow(axis)) { - auto leadingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()); - if (!leadingPosition.isUndefined()) { - return YGResolveValue(leadingPosition, axisSize); - } - } - - auto leadingPosition = YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()); - - return leadingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(leadingPosition, axisSize); + auto leadingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeStart, + leading[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.position(), leading[axis], CompactValue::ofZero()); + return YGResolveValue(leadingPosition, axisSize); } YGFloatOptional YGNode::getTrailingPosition( const YGFlexDirection axis, const float axisSize) const { - if (YGFlexDirectionIsRow(axis)) { - auto trailingPosition = YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()); - if (!trailingPosition.isUndefined()) { - return YGResolveValue(trailingPosition, axisSize); - } - } - - auto trailingPosition = YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()); - - return trailingPosition.isUndefined() - ? YGFloatOptional{0} - : YGResolveValue(trailingPosition, axisSize); + auto trailingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeEnd, + trailing[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.position(), trailing[axis], CompactValue::ofZero()); + return YGResolveValue(trailingPosition, axisSize); } bool YGNode::isLeadingPositionDefined(const YGFlexDirection axis) const { - return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeStart, CompactValue::ofUndefined()) - .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), leading[axis], CompactValue::ofUndefined()) - .isUndefined(); + auto leadingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeStart, + leading[axis], + CompactValue::ofUndefined()) + : computeEdgeValueForColumn( + style_.position(), leading[axis], CompactValue::ofUndefined()); + return !leadingPosition.isUndefined(); } bool YGNode::isTrailingPosDefined(const YGFlexDirection axis) const { - return (YGFlexDirectionIsRow(axis) && - !YGComputedEdgeValue( - style_.position(), YGEdgeEnd, CompactValue::ofUndefined()) - .isUndefined()) || - !YGComputedEdgeValue( - style_.position(), trailing[axis], CompactValue::ofUndefined()) - .isUndefined(); + auto trailingPosition = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.position(), + YGEdgeEnd, + trailing[axis], + CompactValue::ofUndefined()) + : computeEdgeValueForColumn( + style_.position(), trailing[axis], CompactValue::ofUndefined()); + return !trailingPosition.isUndefined(); } YGFloatOptional YGNode::getLeadingMargin( const YGFlexDirection axis, const float widthSize) const { - if (YGFlexDirectionIsRow(axis) && - !style_.margin()[YGEdgeStart].isUndefined()) { - return YGResolveValueMargin(style_.margin()[YGEdgeStart], widthSize); - } - - return YGResolveValueMargin( - YGComputedEdgeValue( - style_.margin(), leading[axis], CompactValue::ofZero()), - widthSize); + auto leadingMargin = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.margin(), YGEdgeStart, leading[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.margin(), leading[axis], CompactValue::ofZero()); + return YGResolveValueMargin(leadingMargin, widthSize); } YGFloatOptional YGNode::getTrailingMargin( const YGFlexDirection axis, const float widthSize) const { - if (YGFlexDirectionIsRow(axis) && !style_.margin()[YGEdgeEnd].isUndefined()) { - return YGResolveValueMargin(style_.margin()[YGEdgeEnd], widthSize); - } - - return YGResolveValueMargin( - YGComputedEdgeValue( - style_.margin(), trailing[axis], CompactValue::ofZero()), - widthSize); + auto trailingMargin = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.margin(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.margin(), trailing[axis], CompactValue::ofZero()); + return YGResolveValueMargin(trailingMargin, widthSize); } YGFloatOptional YGNode::getMarginForAxis( @@ -147,7 +169,6 @@ YGSize YGNode::measure( float height, YGMeasureMode heightMode, void* layoutContext) { - return facebook::yoga::detail::getBooleanData(flags, measureUsesContext_) ? measure_.withContext( this, width, widthMode, height, heightMode, layoutContext) @@ -448,68 +469,48 @@ bool YGNode::isNodeFlexible() { } float YGNode::getLeadingBorder(const YGFlexDirection axis) const { - YGValue leadingBorder; - if (YGFlexDirectionIsRow(axis) && - !style_.border()[YGEdgeStart].isUndefined()) { - leadingBorder = style_.border()[YGEdgeStart]; - if (leadingBorder.value >= 0) { - return leadingBorder.value; - } - } - - leadingBorder = YGComputedEdgeValue( - style_.border(), leading[axis], CompactValue::ofZero()); - return YGFloatMax(leadingBorder.value, 0.0f); + YGValue leadingBorder = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.border(), YGEdgeStart, leading[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.border(), leading[axis], CompactValue::ofZero()); + return fmaxf(leadingBorder.value, 0.0f); } -float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) const { - YGValue trailingBorder; - if (YGFlexDirectionIsRow(flexDirection) && - !style_.border()[YGEdgeEnd].isUndefined()) { - trailingBorder = style_.border()[YGEdgeEnd]; - if (trailingBorder.value >= 0.0f) { - return trailingBorder.value; - } - } - - trailingBorder = YGComputedEdgeValue( - style_.border(), trailing[flexDirection], CompactValue::ofZero()); - return YGFloatMax(trailingBorder.value, 0.0f); +float YGNode::getTrailingBorder(const YGFlexDirection axis) const { + YGValue trailingBorder = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.border(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.border(), trailing[axis], CompactValue::ofZero()); + return fmaxf(trailingBorder.value, 0.0f); } YGFloatOptional YGNode::getLeadingPadding( const YGFlexDirection axis, const float widthSize) const { - const YGFloatOptional paddingEdgeStart = - YGResolveValue(style_.padding()[YGEdgeStart], widthSize); - if (YGFlexDirectionIsRow(axis) && - !style_.padding()[YGEdgeStart].isUndefined() && - !paddingEdgeStart.isUndefined() && paddingEdgeStart.unwrap() >= 0.0f) { - return paddingEdgeStart; - } - - YGFloatOptional resolvedValue = YGResolveValue( - YGComputedEdgeValue( - style_.padding(), leading[axis], CompactValue::ofZero()), - widthSize); - return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); + auto leadingPadding = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.padding(), + YGEdgeStart, + leading[axis], + CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.padding(), leading[axis], CompactValue::ofZero()); + return YGFloatOptionalMax( + YGResolveValue(leadingPadding, widthSize), YGFloatOptional(0.0f)); } YGFloatOptional YGNode::getTrailingPadding( const YGFlexDirection axis, const float widthSize) const { - const YGFloatOptional paddingEdgeEnd = - YGResolveValue(style_.padding()[YGEdgeEnd], widthSize); - if (YGFlexDirectionIsRow(axis) && paddingEdgeEnd >= YGFloatOptional{0.0f}) { - return paddingEdgeEnd; - } - - YGFloatOptional resolvedValue = YGResolveValue( - YGComputedEdgeValue( - style_.padding(), trailing[axis], CompactValue::ofZero()), - widthSize); - - return YGFloatOptionalMax(resolvedValue, YGFloatOptional(0.0f)); + auto trailingPadding = YGFlexDirectionIsRow(axis) + ? computeEdgeValueForRow( + style_.padding(), YGEdgeEnd, trailing[axis], CompactValue::ofZero()) + : computeEdgeValueForColumn( + style_.padding(), trailing[axis], CompactValue::ofZero()); + return YGFloatOptionalMax( + YGResolveValue(trailingPadding, widthSize), YGFloatOptional(0.0f)); } YGFloatOptional YGNode::getLeadingPaddingAndBorder( diff --git a/yoga/YGNode.h b/yoga/YGNode.h index 63d98fe3..4b6e6277 100644 --- a/yoga/YGNode.h +++ b/yoga/YGNode.h @@ -193,6 +193,17 @@ public: return resolvedDimensions_[index]; } + static CompactValue computeEdgeValueForColumn( + const YGStyle::Edges& edges, + YGEdge edge, + CompactValue defaultValue); + + static CompactValue computeEdgeValueForRow( + const YGStyle::Edges& edges, + YGEdge rowEdge, + YGEdge edge, + CompactValue defaultValue); + // Methods related to positions, margin, padding and border YGFloatOptional getLeadingPosition( const YGFlexDirection axis, diff --git a/yoga/YGNodePrint.cpp b/yoga/YGNodePrint.cpp index 26efa485..72d147db 100644 --- a/yoga/YGNodePrint.cpp +++ b/yoga/YGNodePrint.cpp @@ -104,10 +104,13 @@ static void appendEdgeIfNotUndefined( const string& str, const YGStyle::Edges& edges, const YGEdge edge) { - appendNumberIfNotUndefined( - base, - str, - YGComputedEdgeValue(edges, edge, detail::CompactValue::ofUndefined())); + // TODO: this doesn't take RTL / YGEdgeStart / YGEdgeEnd into account + auto value = (edge == YGEdgeLeft || edge == YGEdgeRight) + ? YGNode::computeEdgeValueForRow( + edges, edge, edge, detail::CompactValue::ofUndefined()) + : YGNode::computeEdgeValueForColumn( + edges, edge, detail::CompactValue::ofUndefined()); + appendNumberIfNotUndefined(base, str, value); } void YGNodeToString( diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h index 1a22f24c..b671f177 100644 --- a/yoga/Yoga-internal.h +++ b/yoga/Yoga-internal.h @@ -144,8 +144,3 @@ static const float kDefaultFlexShrink = 0.0f; static const float kWebDefaultFlexShrink = 1.0f; extern bool YGFloatsEqual(const float a, const float b); -extern facebook::yoga::detail::CompactValue YGComputedEdgeValue( - const facebook::yoga::detail::Values< - facebook::yoga::enums::count()>& edges, - YGEdge edge, - facebook::yoga::detail::CompactValue defaultValue); diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index f24563df..196fc7b7 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -110,36 +110,6 @@ YOGA_EXPORT bool YGFloatIsUndefined(const float value) { return facebook::yoga::isUndefined(value); } -detail::CompactValue YGComputedEdgeValue( - const YGStyle::Edges& edges, - YGEdge edge, - detail::CompactValue defaultValue) { - if (!edges[edge].isUndefined()) { - return edges[edge]; - } - - if ((edge == YGEdgeTop || edge == YGEdgeBottom) && - !edges[YGEdgeVertical].isUndefined()) { - return edges[YGEdgeVertical]; - } - - if ((edge == YGEdgeLeft || edge == YGEdgeRight || edge == YGEdgeStart || - edge == YGEdgeEnd) && - !edges[YGEdgeHorizontal].isUndefined()) { - return edges[YGEdgeHorizontal]; - } - - if (!edges[YGEdgeAll].isUndefined()) { - return edges[YGEdgeAll]; - } - - if (edge == YGEdgeStart || edge == YGEdgeEnd) { - return detail::CompactValue::ofUndefined(); - } - - return defaultValue; -} - YOGA_EXPORT void* YGNodeGetContext(YGNodeRef node) { return node->getContext(); } From e87f429703677061129a39ef6dc5f19da33608e1 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 15 Mar 2021 16:53:05 -0700 Subject: [PATCH 28/33] Simplify YGNodeCalculateAvailableInnerDim Summary: Avoid recalculating margin and padding by pre-subtracting the margin from `availableWidth` and inlining the calculation of `paddingAndBorderAxisCross`. Changelog: [Internal] Reviewed By: SidharthGuglani Differential Revision: D27010094 fbshipit-source-id: afc3cf251a0306b9e5d7f0dc6856feee8d1dca6e --- yoga/Yoga.cpp | 80 +++++++++++++++++++++++++++------------------------ yoga/Yoga.h | 2 +- 2 files changed, 43 insertions(+), 39 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 196fc7b7..db3a0704 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1848,21 +1848,11 @@ static void YGZeroOutLayoutRecursivly( static float YGNodeCalculateAvailableInnerDim( const YGNodeConstRef node, - YGFlexDirection axis, - float availableDim, - float ownerDim, - float ownerDimForMarginPadding) { - YGFlexDirection direction = - YGFlexDirectionIsRow(axis) ? YGFlexDirectionRow : YGFlexDirectionColumn; - YGDimension dimension = - YGFlexDirectionIsRow(axis) ? YGDimensionWidth : YGDimensionHeight; - - const float margin = - node->getMarginForAxis(direction, ownerDimForMarginPadding).unwrap(); - const float paddingAndBorder = - YGNodePaddingAndBorderForAxis(node, direction, ownerDimForMarginPadding); - - float availableInnerDim = availableDim - margin - paddingAndBorder; + const YGDimension dimension, + const float availableDim, + const float paddingAndBorder, + const float ownerDim) { + float availableInnerDim = availableDim - paddingAndBorder; // Max dimension overrides predefined dimension value; Min dimension in turn // overrides both of the above if (!YGFloatIsUndefined(availableInnerDim)) { @@ -2836,12 +2826,14 @@ static void YGNodelayoutImpl( const float mainAxisownerSize = isMainAxisRow ? ownerWidth : ownerHeight; const float crossAxisownerSize = isMainAxisRow ? ownerHeight : ownerWidth; - const float leadingPaddingAndBorderCross = - node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); const float paddingAndBorderAxisMain = YGNodePaddingAndBorderForAxis(node, mainAxis, ownerWidth); + const float leadingPaddingAndBorderCross = + node->getLeadingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); + const float trailingPaddingAndBorderCross = + node->getTrailingPaddingAndBorder(crossAxis, ownerWidth).unwrap(); const float paddingAndBorderAxisCross = - YGNodePaddingAndBorderForAxis(node, crossAxis, ownerWidth); + leadingPaddingAndBorderCross + trailingPaddingAndBorderCross; YGMeasureMode measureModeMainDim = isMainAxisRow ? widthMeasureMode : heightMeasureMode; @@ -2858,30 +2850,20 @@ static void YGNodelayoutImpl( const float marginAxisColumn = node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - const auto& minDimensions = node->getStyle().minDimensions(); - const auto& maxDimensions = node->getStyle().maxDimensions(); - const float minInnerWidth = - YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float maxInnerWidth = - YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - - paddingAndBorderAxisRow; - const float minInnerHeight = - YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - const float maxInnerHeight = - YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight).unwrap() - - paddingAndBorderAxisColumn; - - const float minInnerMainDim = isMainAxisRow ? minInnerWidth : minInnerHeight; - const float maxInnerMainDim = isMainAxisRow ? maxInnerWidth : maxInnerHeight; - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS float availableInnerWidth = YGNodeCalculateAvailableInnerDim( - node, YGFlexDirectionRow, availableWidth, ownerWidth, ownerWidth); + node, + YGDimensionWidth, + availableWidth - marginAxisRow, + paddingAndBorderAxisRow, + ownerWidth); float availableInnerHeight = YGNodeCalculateAvailableInnerDim( - node, YGFlexDirectionColumn, availableHeight, ownerHeight, ownerWidth); + node, + YGDimensionHeight, + availableHeight - marginAxisColumn, + paddingAndBorderAxisColumn, + ownerHeight); float availableInnerMainDim = isMainAxisRow ? availableInnerWidth : availableInnerHeight; @@ -2953,6 +2935,28 @@ static void YGNodelayoutImpl( // If we don't measure with exact main dimension we want to ensure we don't // violate min and max if (measureModeMainDim != YGMeasureModeExactly) { + const auto& minDimensions = node->getStyle().minDimensions(); + const auto& maxDimensions = node->getStyle().maxDimensions(); + const float minInnerWidth = + YGResolveValue(minDimensions[YGDimensionWidth], ownerWidth).unwrap() - + paddingAndBorderAxisRow; + const float maxInnerWidth = + YGResolveValue(maxDimensions[YGDimensionWidth], ownerWidth).unwrap() - + paddingAndBorderAxisRow; + const float minInnerHeight = + YGResolveValue(minDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - + paddingAndBorderAxisColumn; + const float maxInnerHeight = + YGResolveValue(maxDimensions[YGDimensionHeight], ownerHeight) + .unwrap() - + paddingAndBorderAxisColumn; + + const float minInnerMainDim = + isMainAxisRow ? minInnerWidth : minInnerHeight; + const float maxInnerMainDim = + isMainAxisRow ? maxInnerWidth : maxInnerHeight; + if (!YGFloatIsUndefined(minInnerMainDim) && collectedFlexItemsValues.sizeConsumedOnCurrentLine < minInnerMainDim) { diff --git a/yoga/Yoga.h b/yoga/Yoga.h index 87901a28..86cd65e2 100644 --- a/yoga/Yoga.h +++ b/yoga/Yoga.h @@ -107,7 +107,7 @@ WIN_EXPORT void YGNodeMarkDirty(YGNodeRef node); // Marks the current node and all its descendants as dirty. // -// Intended to be used for Uoga benchmarks. Don't use in production, as calling +// Intended to be used for Yoga benchmarks. Don't use in production, as calling // `YGCalculateLayout` will cause the recalculation of each and every node. WIN_EXPORT void YGNodeMarkDirtyAndPropogateToDescendants(YGNodeRef node); From b2095801ba3c5621e33ba7cbd7aae0c0371f40b3 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Mon, 15 Mar 2021 16:53:05 -0700 Subject: [PATCH 29/33] Simplify YGNodeEmptyContainer / YGNodeWithMeasureFunc / YGNodeFixedSize Summary: These methods are only ever called just after setting the various YGStyle props. Therefore we can read any padding / margin / border state from there rather than recalculating it. Changelog: [Internal] Reviewed By: SidharthGuglani Differential Revision: D27010098 fbshipit-source-id: a33f879b25c54cfdb0ffc724b6aa325858e97df5 --- yoga/Yoga.cpp | 124 +++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 72 deletions(-) diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index db3a0704..9553366e 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -1651,40 +1651,33 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( availableHeight = YGUndefined; } - const float paddingAndBorderAxisRow = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); - const float paddingAndBorderAxisColumn = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); + const auto& padding = node->getLayout().padding; + const auto& border = node->getLayout().border; + const float paddingAndBorderAxisRow = padding[YGEdgeLeft] + + padding[YGEdgeRight] + border[YGEdgeLeft] + border[YGEdgeRight]; + const float paddingAndBorderAxisColumn = padding[YGEdgeTop] + + padding[YGEdgeBottom] + border[YGEdgeTop] + border[YGEdgeBottom]; // We want to make sure we don't call measure with negative size const float innerWidth = YGFloatIsUndefined(availableWidth) ? availableWidth - : YGFloatMax(0, availableWidth - marginAxisRow - paddingAndBorderAxisRow); + : YGFloatMax(0, availableWidth - paddingAndBorderAxisRow); const float innerHeight = YGFloatIsUndefined(availableHeight) ? availableHeight - : YGFloatMax( - 0, availableHeight - marginAxisColumn - paddingAndBorderAxisColumn); + : YGFloatMax(0, availableHeight - paddingAndBorderAxisColumn); if (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly) { // Don't bother sizing the text if both dimensions are already defined. node->setLayoutMeasuredDimension( YGNodeBoundAxis( - node, - YGFlexDirectionRow, - availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + node, YGFlexDirectionRow, availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); node->setLayoutMeasuredDimension( YGNodeBoundAxis( node, YGFlexDirectionColumn, - availableHeight - marginAxisColumn, + availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1721,7 +1714,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( (widthMeasureMode == YGMeasureModeUndefined || widthMeasureMode == YGMeasureModeAtMost) ? measuredSize.width + paddingAndBorderAxisRow - : availableWidth - marginAxisRow, + : availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); @@ -1733,7 +1726,7 @@ static void YGNodeWithMeasureFuncSetMeasuredDimensions( (heightMeasureMode == YGMeasureModeUndefined || heightMeasureMode == YGMeasureModeAtMost) ? measuredSize.height + paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, + : availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -1750,37 +1743,28 @@ static void YGNodeEmptyContainerSetMeasuredDimensions( const YGMeasureMode heightMeasureMode, const float ownerWidth, const float ownerHeight) { - const float paddingAndBorderAxisRow = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionRow, ownerWidth); - const float paddingAndBorderAxisColumn = - YGNodePaddingAndBorderForAxis(node, YGFlexDirectionColumn, ownerWidth); - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); + const auto& padding = node->getLayout().padding; + const auto& border = node->getLayout().border; + float width = availableWidth; + if (widthMeasureMode == YGMeasureModeUndefined || + widthMeasureMode == YGMeasureModeAtMost) { + width = padding[YGEdgeLeft] + padding[YGEdgeRight] + border[YGEdgeLeft] + + border[YGEdgeRight]; + } node->setLayoutMeasuredDimension( - YGNodeBoundAxis( - node, - YGFlexDirectionRow, - (widthMeasureMode == YGMeasureModeUndefined || - widthMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisRow - : availableWidth - marginAxisRow, - ownerWidth, - ownerWidth), + YGNodeBoundAxis(node, YGFlexDirectionRow, width, ownerWidth, ownerWidth), YGDimensionWidth); + float height = availableHeight; + if (heightMeasureMode == YGMeasureModeUndefined || + heightMeasureMode == YGMeasureModeAtMost) { + height = padding[YGEdgeTop] + padding[YGEdgeBottom] + border[YGEdgeTop] + + border[YGEdgeBottom]; + } node->setLayoutMeasuredDimension( YGNodeBoundAxis( - node, - YGFlexDirectionColumn, - (heightMeasureMode == YGMeasureModeUndefined || - heightMeasureMode == YGMeasureModeAtMost) - ? paddingAndBorderAxisColumn - : availableHeight - marginAxisColumn, - ownerHeight, - ownerWidth), + node, YGFlexDirectionColumn, height, ownerHeight, ownerWidth), YGDimensionHeight); } @@ -1798,11 +1782,6 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( heightMeasureMode == YGMeasureModeAtMost && availableHeight <= 0.0f) || (widthMeasureMode == YGMeasureModeExactly && heightMeasureMode == YGMeasureModeExactly)) { - auto marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - auto marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - node->setLayoutMeasuredDimension( YGNodeBoundAxis( node, @@ -1811,7 +1790,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( (widthMeasureMode == YGMeasureModeAtMost && availableWidth < 0.0f) ? 0.0f - : availableWidth - marginAxisRow, + : availableWidth, ownerWidth, ownerWidth), YGDimensionWidth); @@ -1824,7 +1803,7 @@ static bool YGNodeFixedSizeSetMeasuredDimensions( (heightMeasureMode == YGMeasureModeAtMost && availableHeight < 0.0f) ? 0.0f - : availableHeight - marginAxisColumn, + : availableHeight, ownerHeight, ownerWidth), YGDimensionHeight); @@ -2739,16 +2718,22 @@ static void YGNodelayoutImpl( const YGEdge startEdge = direction == YGDirectionLTR ? YGEdgeLeft : YGEdgeRight; const YGEdge endEdge = direction == YGDirectionLTR ? YGEdgeRight : YGEdgeLeft; - node->setLayoutMargin( - node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(), startEdge); - node->setLayoutMargin( - node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(), endEdge); - node->setLayoutMargin( - node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeTop); - node->setLayoutMargin( - node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(), - YGEdgeBottom); + + const float marginRowLeading = + node->getLeadingMargin(flexRowDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginRowLeading, startEdge); + const float marginRowTrailing = + node->getTrailingMargin(flexRowDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginRowTrailing, endEdge); + const float marginColumnLeading = + node->getLeadingMargin(flexColumnDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginColumnLeading, YGEdgeTop); + const float marginColumnTrailing = + node->getTrailingMargin(flexColumnDirection, ownerWidth).unwrap(); + node->setLayoutMargin(marginColumnTrailing, YGEdgeBottom); + + const float marginAxisRow = marginRowLeading + marginRowTrailing; + const float marginAxisColumn = marginColumnLeading + marginColumnTrailing; node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), startEdge); node->setLayoutBorder(node->getTrailingBorder(flexRowDirection), endEdge); @@ -2771,8 +2756,8 @@ static void YGNodelayoutImpl( if (node->hasMeasureFunc()) { YGNodeWithMeasureFuncSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2787,8 +2772,8 @@ static void YGNodelayoutImpl( if (childCount == 0) { YGNodeEmptyContainerSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2801,8 +2786,8 @@ static void YGNodelayoutImpl( if (!performLayout && YGNodeFixedSizeSetMeasuredDimensions( node, - availableWidth, - availableHeight, + availableWidth - marginAxisRow, + availableHeight - marginAxisColumn, widthMeasureMode, heightMeasureMode, ownerWidth, @@ -2845,11 +2830,6 @@ static void YGNodelayoutImpl( const float paddingAndBorderAxisColumn = isMainAxisRow ? paddingAndBorderAxisCross : paddingAndBorderAxisMain; - const float marginAxisRow = - node->getMarginForAxis(YGFlexDirectionRow, ownerWidth).unwrap(); - const float marginAxisColumn = - node->getMarginForAxis(YGFlexDirectionColumn, ownerWidth).unwrap(); - // STEP 2: DETERMINE AVAILABLE SIZE IN MAIN AND CROSS DIRECTIONS float availableInnerWidth = YGNodeCalculateAvailableInnerDim( From 67b6c24d7bd1bac5869f95832ff1cf8b43d4a617 Mon Sep 17 00:00:00 2001 From: Altaibayar Tseveenbayar Date: Thu, 18 Mar 2021 03:42:31 -0700 Subject: [PATCH 30/33] Yoga Visual Studio project file fix Summary: Yoga Visual Studio project file was outdated. Made it back working/compilable Reviewed By: Andrey-Mishanin Differential Revision: D27138942 fbshipit-source-id: 5d57e61dbb415db54e255e148739c2e670f3bd23 --- csharp/Yoga/Yoga.vcxproj | 7 +- csharp/Yoga/Yoga.vcxproj.filters | 221 +++++++++++++++++-------------- 2 files changed, 124 insertions(+), 104 deletions(-) diff --git a/csharp/Yoga/Yoga.vcxproj b/csharp/Yoga/Yoga.vcxproj index 5899a0db..0bb66327 100755 --- a/csharp/Yoga/Yoga.vcxproj +++ b/csharp/Yoga/Yoga.vcxproj @@ -227,6 +227,8 @@ + + @@ -236,6 +238,7 @@ + @@ -243,14 +246,16 @@ + + - + diff --git a/csharp/Yoga/Yoga.vcxproj.filters b/csharp/Yoga/Yoga.vcxproj.filters index 3243c630..c03f853a 100755 --- a/csharp/Yoga/Yoga.vcxproj.filters +++ b/csharp/Yoga/Yoga.vcxproj.filters @@ -1,104 +1,119 @@ - - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Resource Files - - + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Resource Files + + \ No newline at end of file From db6be5286ebc7e4a824797178c6205613852cd5f Mon Sep 17 00:00:00 2001 From: Altaibayar Tseveenbayar Date: Fri, 19 Mar 2021 19:22:49 -0700 Subject: [PATCH 31/33] C4244 possible precision loss warning fix Summary: Fixing `warning C4244: 'argument': conversion from 'double' to 'float', possible loss of data` Changelog: [Internal] Reviewed By: SidharthGuglani Differential Revision: D27132355 fbshipit-source-id: 55ff35be368ef4f6093865eb88c17e753250d179 --- yoga/Utils.cpp | 2 +- yoga/Yoga-internal.h | 4 ++++ yoga/Yoga.cpp | 28 ++++++++++++++++------------ 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/yoga/Utils.cpp b/yoga/Utils.cpp index edb198d2..eaa74b06 100644 --- a/yoga/Utils.cpp +++ b/yoga/Utils.cpp @@ -55,7 +55,7 @@ bool YGFloatsEqual(const float a, const float b) { bool YGDoubleEqual(const double a, const double b) { if (!yoga::isUndefined(a) && !yoga::isUndefined(b)) { - return fabs(a - b) < 0.0001f; + return fabs(a - b) < 0.0001; } return yoga::isUndefined(a) && yoga::isUndefined(b); } diff --git a/yoga/Yoga-internal.h b/yoga/Yoga-internal.h index b671f177..acd173be 100644 --- a/yoga/Yoga-internal.h +++ b/yoga/Yoga-internal.h @@ -33,6 +33,10 @@ inline bool isUndefined(float value) { return std::isnan(value); } +inline bool isUndefined(double value) { + return std::isnan(value); +} + } // namespace yoga } // namespace facebook diff --git a/yoga/Yoga.cpp b/yoga/Yoga.cpp index 9553366e..33f70e82 100644 --- a/yoga/Yoga.cpp +++ b/yoga/Yoga.cpp @@ -106,6 +106,10 @@ static int YGDefaultLog( #undef YG_UNUSED #endif +static inline bool YGDoubleIsUndefined(const double value) { + return facebook::yoga::isUndefined(value); +} + YOGA_EXPORT bool YGFloatIsUndefined(const float value) { return facebook::yoga::isUndefined(value); } @@ -3620,10 +3624,10 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( const double pointScaleFactor, const bool forceCeil, const bool forceFloor) { - double scaledValue = ((double) value) * pointScaleFactor; + double scaledValue = value * pointScaleFactor; // We want to calculate `fractial` such that `floor(scaledValue) = scaledValue // - fractial`. - double fractial = fmod(scaledValue, 1.0f); + double fractial = fmod(scaledValue, 1.0); if (fractial < 0) { // This branch is for handling negative numbers for `value`. // @@ -3645,25 +3649,25 @@ YOGA_EXPORT float YGRoundValueToPixelGrid( if (YGDoubleEqual(fractial, 0)) { // First we check if the value is already rounded scaledValue = scaledValue - fractial; - } else if (YGDoubleEqual(fractial, 1.0f)) { - scaledValue = scaledValue - fractial + 1.0f; + } else if (YGDoubleEqual(fractial, 1.0)) { + scaledValue = scaledValue - fractial + 1.0; } else if (forceCeil) { // Next we check if we need to use forced rounding - scaledValue = scaledValue - fractial + 1.0f; + scaledValue = scaledValue - fractial + 1.0; } else if (forceFloor) { scaledValue = scaledValue - fractial; } else { // Finally we just round the value scaledValue = scaledValue - fractial + - (!YGFloatIsUndefined(fractial) && - (fractial > 0.5f || YGDoubleEqual(fractial, 0.5f)) - ? 1.0f - : 0.0f); + (!YGDoubleIsUndefined(fractial) && + (fractial > 0.5 || YGDoubleEqual(fractial, 0.5)) + ? 1.0 + : 0.0); } - return (YGFloatIsUndefined(scaledValue) || - YGFloatIsUndefined(pointScaleFactor)) + return (YGDoubleIsUndefined(scaledValue) || + YGDoubleIsUndefined(pointScaleFactor)) ? YGUndefined - : scaledValue / pointScaleFactor; + : (float) (scaledValue / pointScaleFactor); } YOGA_EXPORT bool YGNodeCanUseCachedMeasurement( From 6c2ba945be91cee985a0738552e960f3ed2059d8 Mon Sep 17 00:00:00 2001 From: Altaibayar Tseveenbayar Date: Mon, 22 Mar 2021 04:31:18 -0700 Subject: [PATCH 32/33] Making yoga by default a static library Summary: We are linking yoga as a static library in most of the places Reviewed By: SidharthGuglani Differential Revision: D27228933 fbshipit-source-id: 725d6551198c96925ae80b3a62ef9737ee7e3052 --- csharp/Yoga/Yoga.vcxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/Yoga/Yoga.vcxproj b/csharp/Yoga/Yoga.vcxproj index 0bb66327..306e8e15 100755 --- a/csharp/Yoga/Yoga.vcxproj +++ b/csharp/Yoga/Yoga.vcxproj @@ -36,7 +36,7 @@ - DynamicLibrary + StaticLibrary true v141 Unicode From 638690255c24c2d1a6e644b4f2694643408db228 Mon Sep 17 00:00:00 2001 From: Altaibayar Tseveenbayar Date: Mon, 22 Mar 2021 07:41:16 -0700 Subject: [PATCH 33/33] Yoga set as a static library also for debug+release builds in x64 Summary: Yoga set as a static library also for debug+release builds in x64 Reviewed By: SidharthGuglani Differential Revision: D27230019 fbshipit-source-id: d77e2c4130cd8303d1585723bfad927b9ddba23e --- csharp/Yoga/Yoga.vcxproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csharp/Yoga/Yoga.vcxproj b/csharp/Yoga/Yoga.vcxproj index 306e8e15..974919de 100755 --- a/csharp/Yoga/Yoga.vcxproj +++ b/csharp/Yoga/Yoga.vcxproj @@ -48,7 +48,7 @@ Unicode - DynamicLibrary + StaticLibrary false v141 true @@ -62,13 +62,13 @@ Unicode - DynamicLibrary + StaticLibrary true v141 Unicode - DynamicLibrary + StaticLibrary false v141 true