From 7f94bff89a09547e76b50ae4c96ec59de73a153a Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Mon, 15 Jan 2018 10:09:50 -0800 Subject: [PATCH] Resolve direction function is now as a method on YGNode Reviewed By: emilsjolander Differential Revision: D6711755 fbshipit-source-id: a0e80596e10f0c7fb7a31b75377da4db846c4bbb --- ReactCommon/yoga/yoga/YGNode.cpp | 9 +++++++++ ReactCommon/yoga/yoga/YGNode.h | 1 + ReactCommon/yoga/yoga/Yoga.cpp | 14 ++------------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ReactCommon/yoga/yoga/YGNode.cpp b/ReactCommon/yoga/yoga/YGNode.cpp index ebe733e760cc85..112fa280642c4a 100644 --- a/ReactCommon/yoga/yoga/YGNode.cpp +++ b/ReactCommon/yoga/yoga/YGNode.cpp @@ -510,6 +510,15 @@ void YGNode::resolveDimension() { } } +YGDirection YGNode::resolveDirection(const YGDirection parentDirection) { + if (style_.direction == YGDirectionInherit) { + return parentDirection > YGDirectionInherit ? parentDirection + : YGDirectionLTR; + } else { + return style_.direction; + } +} + void YGNode::clearChildren() { children_.clear(); children_.shrink_to_fit(); diff --git a/ReactCommon/yoga/yoga/YGNode.h b/ReactCommon/yoga/yoga/YGNode.h index 503894c19ba8b6..f116c3436e31fb 100644 --- a/ReactCommon/yoga/yoga/YGNode.h +++ b/ReactCommon/yoga/yoga/YGNode.h @@ -129,6 +129,7 @@ struct YGNode { YGValue marginTrailingValue(const YGFlexDirection axis) const; YGValue resolveFlexBasisPtr() const; void resolveDimension(); + YGDirection resolveDirection(const YGDirection parentDirection); void clearChildren(); /// Replaces the occurrences of oldChild with newChild void replaceChild(YGNodeRef oldChild, YGNodeRef newChild); diff --git a/ReactCommon/yoga/yoga/Yoga.cpp b/ReactCommon/yoga/yoga/Yoga.cpp index 3b536141d1e343..67db51bafb7d07 100644 --- a/ReactCommon/yoga/yoga/Yoga.cpp +++ b/ReactCommon/yoga/yoga/Yoga.cpp @@ -837,15 +837,6 @@ static inline YGAlign YGNodeAlignItem(const YGNodeRef node, const YGNodeRef chil return align; } -static inline YGDirection YGNodeResolveDirection(const YGNodeRef node, - const YGDirection parentDirection) { - if (node->getStyle().direction == YGDirectionInherit) { - return parentDirection > YGDirectionInherit ? parentDirection : YGDirectionLTR; - } else { - return node->getStyle().direction; - } -} - static float YGBaseline(const YGNodeRef node) { if (node->getBaseline() != nullptr) { const float baseline = node->getBaseline()( @@ -1602,8 +1593,7 @@ static void YGNodeComputeFlexBasisForChildren( } if (performLayout) { // Set the initial position (relative to the parent). - const YGDirection childDirection = - YGNodeResolveDirection(child, direction); + const YGDirection childDirection = child->resolveDirection(direction); const float mainDim = YGFlexDirectionIsRow(mainAxis) ? availableInnerWidth : availableInnerHeight; @@ -1744,7 +1734,7 @@ static void YGNodelayoutImpl(const YGNodeRef node, "YGMeasureModeUndefined"); // Set the resolved resolution in the node's layout. - const YGDirection direction = YGNodeResolveDirection(node, parentDirection); + const YGDirection direction = node->resolveDirection(parentDirection); node->setLayoutDirection(direction); const YGFlexDirection flexRowDirection = YGResolveFlexDirection(YGFlexDirectionRow, direction);