From d85da86dc7c7833e71099c6a621547bc3cec8d4f Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 8 Jan 2018 02:48:39 -0800 Subject: [PATCH] Move YGNodeResolveFlexShrink to a method on YGNode Reviewed By: emilsjolander Differential Revision: D6611418 fbshipit-source-id: 6e5ba39b555d313a967800589891027920112c15 --- ReactCommon/yoga/yoga/YGNode.cpp | 14 ++++++++++++++ ReactCommon/yoga/yoga/YGNode.h | 1 + ReactCommon/yoga/yoga/Yoga.cpp | 29 +++++++---------------------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index c53cc26ea..5099a2467 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -435,3 +435,17 @@ float YGNode::resolveFlexGrow() { } return kDefaultFlexGrow; } + +float YGNode::resolveFlexShrink() { + if (parent_ == nullptr) { + return 0.0; + } + if (!YGFloatIsUndefined(style_.flexShrink)) { + return style_.flexShrink; + } + if (!config_->useWebDefaults && !YGFloatIsUndefined(style_.flex) && + style_.flex < 0.0f) { + return -style_.flex; + } + return config_->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink; +} diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index 122220fb2..46e0c2f7f 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -123,4 +123,5 @@ struct YGNode { void cloneChildrenIfNeeded(); void markDirtyAndPropogate(); float resolveFlexGrow(); + float resolveFlexShrink(); }; diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 9206df016..186c6ce46 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -470,23 +470,6 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) { : node->getStyle().flexShrink; } -static inline float YGNodeResolveFlexShrink(const YGNodeRef node) { - // Root nodes flexShrink should always be 0 - if (node->getParent() == nullptr) { - return 0.0; - } - if (!YGFloatIsUndefined(node->getStyle().flexShrink)) { - return node->getStyle().flexShrink; - } - if (!node->getConfig()->useWebDefaults && - !YGFloatIsUndefined(node->getStyle().flex) && - node->getStyle().flex < 0.0f) { - return -node->getStyle().flex; - } - return node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink - : kDefaultFlexShrink; -} - #define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \ type, name, paramName, instanceName) \ void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \ @@ -1021,7 +1004,7 @@ static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection, static inline bool YGNodeIsFlex(const YGNodeRef node) { return ( node->getStyle().positionType == YGPositionTypeRelative && - (node->resolveFlexGrow() != 0 || YGNodeResolveFlexShrink(node) != 0)); + (node->resolveFlexGrow() != 0 || node->resolveFlexShrink() != 0)); } static bool YGIsBaselineLayout(const YGNodeRef node) { @@ -2028,7 +2011,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, } } else if ( child->resolveFlexGrow() > 0.0f && - YGNodeResolveFlexShrink(child) > 0.0f) { + child->resolveFlexShrink() > 0.0f) { singleFlexChild = child; } } @@ -2176,7 +2159,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, totalFlexGrowFactors += child->resolveFlexGrow(); // Unlike the grow factor, the shrink factor is scaled relative to the child dimension. - totalFlexShrinkScaledFactors += -YGNodeResolveFlexShrink(child) * + totalFlexShrinkScaledFactors += -child->resolveFlexShrink() * child->getLayout().computedFlexBasis; } @@ -2296,7 +2279,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, currentRelativeChild->getLayout().computedFlexBasis)); if (remainingFreeSpace < 0) { - flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis; + flexShrinkScaledFactor = + -currentRelativeChild->resolveFlexShrink() * childFlexBasis; // Is this child able to shrink? if (flexShrinkScaledFactor != 0) { @@ -2369,7 +2353,8 @@ static void YGNodelayoutImpl(const YGNodeRef node, float updatedMainSize = childFlexBasis; if (remainingFreeSpace < 0) { - flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis; + flexShrinkScaledFactor = + -currentRelativeChild->resolveFlexShrink() * childFlexBasis; // Is this child able to shrink? if (flexShrinkScaledFactor != 0) { float childSize;