From 5b173c1b6121603f0bc9c30287c18dcdd657db6c Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Wed, 29 Mar 2017 03:06:19 -0700 Subject: [PATCH] Set web defaults when resetting Summary: Set web defaults when resetting Reviewed By: astreet Differential Revision: D4779742 fbshipit-source-id: 5b8c5d7bd432a12984e4ebfd3187da3d680272cd --- tests/YGDefaultValuesTest.cpp | 14 ++++++++++++++ yoga/Yoga.c | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/tests/YGDefaultValuesTest.cpp b/tests/YGDefaultValuesTest.cpp index 7e6b341f..5fcd9fd9 100644 --- a/tests/YGDefaultValuesTest.cpp +++ b/tests/YGDefaultValuesTest.cpp @@ -103,3 +103,17 @@ TEST(YogaTest, assert_webdefault_values) { YGNodeFreeRecursive(root); YGConfigFree(config); } + +TEST(YogaTest, assert_webdefault_values_reset) { + YGConfig * config = YGConfigNew(); + YGConfigSetUseWebDefaults(config, true); + const YGNodeRef root = YGNodeNewWithConfig(config); + YGNodeReset(root); + + ASSERT_EQ(YGFlexDirectionRow, YGNodeStyleGetFlexDirection(root)); + ASSERT_EQ(YGAlignStretch, YGNodeStyleGetAlignContent(root)); + ASSERT_FLOAT_EQ(1.0f, YGNodeStyleGetFlexShrink(root)); + + YGNodeFreeRecursive(root); + YGConfigFree(config); +} diff --git a/yoga/Yoga.c b/yoga/Yoga.c index 75e2348c..52999d2b 100644 --- a/yoga/Yoga.c +++ b/yoga/Yoga.c @@ -362,6 +362,10 @@ void YGNodeReset(const YGNodeRef node) { const YGConfigRef config = node->config; memcpy(node, &gYGNodeDefaults, sizeof(YGNode)); + if (config->useWebDefaults) { + node->style.flexDirection = YGFlexDirectionRow; + node->style.alignContent = YGAlignStretch; + } node->config = config; }