Skip to content

Commit 6627d77

Browse files
Moved YGResolveFlexGrow as a method on YGNode
Reviewed By: emilsjolander Differential Revision: D6611385 fbshipit-source-id: 71660946c469fac77c5ffa0284c793e6adc9db7b
1 parent 0a9e652 commit 6627d77

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

ReactCommon/yoga/yoga/YGNode.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,17 @@ void YGNode::markDirtyAndPropogate() {
421421
}
422422
}
423423
}
424+
425+
float YGNode::resolveFlexGrow() {
426+
// Root nodes flexGrow should always be 0
427+
if (parent_ == nullptr) {
428+
return 0.0;
429+
}
430+
if (!YGFloatIsUndefined(style_.flexGrow)) {
431+
return style_.flexGrow;
432+
}
433+
if (!YGFloatIsUndefined(style_.flex) && style_.flex > 0.0f) {
434+
return style_.flex;
435+
}
436+
return kDefaultFlexGrow;
437+
}

ReactCommon/yoga/yoga/YGNode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,5 @@ struct YGNode {
122122
// Other methods
123123
void cloneChildrenIfNeeded();
124124
void markDirtyAndPropogate();
125+
float resolveFlexGrow();
125126
};

ReactCommon/yoga/yoga/Yoga.cpp

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -457,21 +457,6 @@ void YGNodeCopyStyle(const YGNodeRef dstNode, const YGNodeRef srcNode) {
457457
}
458458
}
459459

460-
static inline float YGResolveFlexGrow(const YGNodeRef node) {
461-
// Root nodes flexGrow should always be 0
462-
if (node->getParent() == nullptr) {
463-
return 0.0;
464-
}
465-
if (!YGFloatIsUndefined(node->getStyle().flexGrow)) {
466-
return node->getStyle().flexGrow;
467-
}
468-
if (!YGFloatIsUndefined(node->getStyle().flex) &&
469-
node->getStyle().flex > 0.0f) {
470-
return node->getStyle().flex;
471-
}
472-
return kDefaultFlexGrow;
473-
}
474-
475460
float YGNodeStyleGetFlexGrow(const YGNodeRef node) {
476461
return YGFloatIsUndefined(node->getStyle().flexGrow)
477462
? kDefaultFlexGrow
@@ -1036,7 +1021,7 @@ static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
10361021
static inline bool YGNodeIsFlex(const YGNodeRef node) {
10371022
return (
10381023
node->getStyle().positionType == YGPositionTypeRelative &&
1039-
(YGResolveFlexGrow(node) != 0 || YGNodeResolveFlexShrink(node) != 0));
1024+
(node->resolveFlexGrow() != 0 || YGNodeResolveFlexShrink(node) != 0));
10401025
}
10411026

10421027
static bool YGIsBaselineLayout(const YGNodeRef node) {
@@ -2041,7 +2026,9 @@ static void YGNodelayoutImpl(const YGNodeRef node,
20412026
singleFlexChild = nullptr;
20422027
break;
20432028
}
2044-
} else if (YGResolveFlexGrow(child) > 0.0f && YGNodeResolveFlexShrink(child) > 0.0f) {
2029+
} else if (
2030+
child->resolveFlexGrow() > 0.0f &&
2031+
YGNodeResolveFlexShrink(child) > 0.0f) {
20452032
singleFlexChild = child;
20462033
}
20472034
}
@@ -2186,7 +2173,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
21862173
itemsOnLine++;
21872174

21882175
if (YGNodeIsFlex(child)) {
2189-
totalFlexGrowFactors += YGResolveFlexGrow(child);
2176+
totalFlexGrowFactors += child->resolveFlexGrow();
21902177

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

23382325
// Is this child able to grow?
23392326
if (flexGrowFactor != 0) {
@@ -2402,7 +2389,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
24022389
availableInnerWidth);
24032390
}
24042391
} else if (remainingFreeSpace > 0) {
2405-
flexGrowFactor = YGResolveFlexGrow(currentRelativeChild);
2392+
flexGrowFactor = currentRelativeChild->resolveFlexGrow();
24062393

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

0 commit comments

Comments
 (0)