Skip to content

Commit

Permalink
Moved YGResolveFlexGrow as a method on YGNode
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D6611385

fbshipit-source-id: 71660946c469fac77c5ffa0284c793e6adc9db7b
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Jan 8, 2018
1 parent 0a9e652 commit 6627d77
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
14 changes: 14 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,17 @@ void YGNode::markDirtyAndPropogate() {
}
}
}

float YGNode::resolveFlexGrow() {
// Root nodes flexGrow should always be 0
if (parent_ == nullptr) {
return 0.0;
}
if (!YGFloatIsUndefined(style_.flexGrow)) {
return style_.flexGrow;
}
if (!YGFloatIsUndefined(style_.flex) && style_.flex > 0.0f) {
return style_.flex;
}
return kDefaultFlexGrow;
}
1 change: 1 addition & 0 deletions ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ struct YGNode {
// Other methods
void cloneChildrenIfNeeded();
void markDirtyAndPropogate();
float resolveFlexGrow();
};
29 changes: 8 additions & 21 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,21 +457,6 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
}
}

static inline float YGResolveFlexGrow(const YGNodeRef node) {
// Root nodes flexGrow should always be 0
if (node->getParent() == nullptr) {
return 0.0;
}
if (!YGFloatIsUndefined(node->getStyle().flexGrow)) {
return node->getStyle().flexGrow;
}
if (!YGFloatIsUndefined(node->getStyle().flex) &&
node->getStyle().flex > 0.0f) {
return node->getStyle().flex;
}
return kDefaultFlexGrow;
}

float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
return YGFloatIsUndefined(node->getStyle().flexGrow)
? kDefaultFlexGrow
Expand Down Expand Up @@ -1036,7 +1021,7 @@ static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
static inline bool YGNodeIsFlex(const YGNodeRef node) {
return (
node->getStyle().positionType == YGPositionTypeRelative &&
(YGResolveFlexGrow(node) != 0 || YGNodeResolveFlexShrink(node) != 0));
(node->resolveFlexGrow() != 0 || YGNodeResolveFlexShrink(node) != 0));
}

static bool YGIsBaselineLayout(const YGNodeRef node) {
Expand Down Expand Up @@ -2041,7 +2026,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
singleFlexChild = nullptr;
break;
}
} else if (YGResolveFlexGrow(child) > 0.0f && YGNodeResolveFlexShrink(child) > 0.0f) {
} else if (
child->resolveFlexGrow() > 0.0f &&
YGNodeResolveFlexShrink(child) > 0.0f) {
singleFlexChild = child;
}
}
Expand Down Expand Up @@ -2186,7 +2173,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
itemsOnLine++;

if (YGNodeIsFlex(child)) {
totalFlexGrowFactors += YGResolveFlexGrow(child);
totalFlexGrowFactors += child->resolveFlexGrow();

// Unlike the grow factor, the shrink factor is scaled relative to the child dimension.
totalFlexShrinkScaledFactors += -YGNodeResolveFlexShrink(child) *
Expand Down Expand Up @@ -2240,7 +2227,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
availableInnerMainDim = maxInnerMainDim;
} else {
if (!node->getConfig()->useLegacyStretchBehaviour &&
(totalFlexGrowFactors == 0 || YGResolveFlexGrow(node) == 0)) {
(totalFlexGrowFactors == 0 || node->resolveFlexGrow() == 0)) {
// If we don't have any children to flex or we can't flex the node itself,
// space we've used is all space we need. Root node also should be shrunk to minimum
availableInnerMainDim = sizeConsumedOnCurrentLine;
Expand Down Expand Up @@ -2333,7 +2320,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
}
}
} else if (remainingFreeSpace > 0) {
flexGrowFactor = YGResolveFlexGrow(currentRelativeChild);
flexGrowFactor = currentRelativeChild->resolveFlexGrow();

// Is this child able to grow?
if (flexGrowFactor != 0) {
Expand Down Expand Up @@ -2402,7 +2389,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
availableInnerWidth);
}
} else if (remainingFreeSpace > 0) {
flexGrowFactor = YGResolveFlexGrow(currentRelativeChild);
flexGrowFactor = currentRelativeChild->resolveFlexGrow();

// Is this child able to grow?
if (flexGrowFactor != 0) {
Expand Down

0 comments on commit 6627d77

Please sign in to comment.