Skip to content

Commit d85da86

Browse files
priteshrnandgaonkarfacebook-github-bot
authored andcommittedJan 8, 2018
Move YGNodeResolveFlexShrink to a method on YGNode
Reviewed By: emilsjolander Differential Revision: D6611418 fbshipit-source-id: 6e5ba39b555d313a967800589891027920112c15
1 parent 6627d77 commit d85da86

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed
 

‎ReactCommon/yoga/yoga/YGNode.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,17 @@ float YGNode::resolveFlexGrow() {
435435
}
436436
return kDefaultFlexGrow;
437437
}
438+
439+
float YGNode::resolveFlexShrink() {
440+
if (parent_ == nullptr) {
441+
return 0.0;
442+
}
443+
if (!YGFloatIsUndefined(style_.flexShrink)) {
444+
return style_.flexShrink;
445+
}
446+
if (!config_->useWebDefaults && !YGFloatIsUndefined(style_.flex) &&
447+
style_.flex < 0.0f) {
448+
return -style_.flex;
449+
}
450+
return config_->useWebDefaults ? kWebDefaultFlexShrink : kDefaultFlexShrink;
451+
}

‎ReactCommon/yoga/yoga/YGNode.h

+1
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,5 @@ struct YGNode {
123123
void cloneChildrenIfNeeded();
124124
void markDirtyAndPropogate();
125125
float resolveFlexGrow();
126+
float resolveFlexShrink();
126127
};

‎ReactCommon/yoga/yoga/Yoga.cpp

+7-22
Original file line numberDiff line numberDiff line change
@@ -470,23 +470,6 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
470470
: node->getStyle().flexShrink;
471471
}
472472

473-
static inline float YGNodeResolveFlexShrink(const YGNodeRef node) {
474-
// Root nodes flexShrink should always be 0
475-
if (node->getParent() == nullptr) {
476-
return 0.0;
477-
}
478-
if (!YGFloatIsUndefined(node->getStyle().flexShrink)) {
479-
return node->getStyle().flexShrink;
480-
}
481-
if (!node->getConfig()->useWebDefaults &&
482-
!YGFloatIsUndefined(node->getStyle().flex) &&
483-
node->getStyle().flex < 0.0f) {
484-
return -node->getStyle().flex;
485-
}
486-
return node->getConfig()->useWebDefaults ? kWebDefaultFlexShrink
487-
: kDefaultFlexShrink;
488-
}
489-
490473
#define YG_NODE_STYLE_PROPERTY_SETTER_IMPL( \
491474
type, name, paramName, instanceName) \
492475
void YGNodeStyleSet##name(const YGNodeRef node, const type paramName) { \
@@ -1021,7 +1004,7 @@ static YGFlexDirection YGFlexDirectionCross(const YGFlexDirection flexDirection,
10211004
static inline bool YGNodeIsFlex(const YGNodeRef node) {
10221005
return (
10231006
node->getStyle().positionType == YGPositionTypeRelative &&
1024-
(node->resolveFlexGrow() != 0 || YGNodeResolveFlexShrink(node) != 0));
1007+
(node->resolveFlexGrow() != 0 || node->resolveFlexShrink() != 0));
10251008
}
10261009

10271010
static bool YGIsBaselineLayout(const YGNodeRef node) {
@@ -2028,7 +2011,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
20282011
}
20292012
} else if (
20302013
child->resolveFlexGrow() > 0.0f &&
2031-
YGNodeResolveFlexShrink(child) > 0.0f) {
2014+
child->resolveFlexShrink() > 0.0f) {
20322015
singleFlexChild = child;
20332016
}
20342017
}
@@ -2176,7 +2159,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
21762159
totalFlexGrowFactors += child->resolveFlexGrow();
21772160

21782161
// Unlike the grow factor, the shrink factor is scaled relative to the child dimension.
2179-
totalFlexShrinkScaledFactors += -YGNodeResolveFlexShrink(child) *
2162+
totalFlexShrinkScaledFactors += -child->resolveFlexShrink() *
21802163
child->getLayout().computedFlexBasis;
21812164
}
21822165

@@ -2296,7 +2279,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
22962279
currentRelativeChild->getLayout().computedFlexBasis));
22972280

22982281
if (remainingFreeSpace < 0) {
2299-
flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis;
2282+
flexShrinkScaledFactor =
2283+
-currentRelativeChild->resolveFlexShrink() * childFlexBasis;
23002284

23012285
// Is this child able to shrink?
23022286
if (flexShrinkScaledFactor != 0) {
@@ -2369,7 +2353,8 @@ static void YGNodelayoutImpl(const YGNodeRef node,
23692353
float updatedMainSize = childFlexBasis;
23702354

23712355
if (remainingFreeSpace < 0) {
2372-
flexShrinkScaledFactor = -YGNodeResolveFlexShrink(currentRelativeChild) * childFlexBasis;
2356+
flexShrinkScaledFactor =
2357+
-currentRelativeChild->resolveFlexShrink() * childFlexBasis;
23732358
// Is this child able to shrink?
23742359
if (flexShrinkScaledFactor != 0) {
23752360
float childSize;

0 commit comments

Comments
 (0)
Please sign in to comment.