Skip to content

Commit

Permalink
Move YGNodeResolveFlexShrink to a method on YGNode
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D6611418

fbshipit-source-id: 6e5ba39b555d313a967800589891027920112c15
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Jan 8, 2018
1 parent 6627d77 commit d85da86
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
14 changes: 14 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
1 change: 1 addition & 0 deletions ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ struct YGNode {
void cloneChildrenIfNeeded();
void markDirtyAndPropogate();
float resolveFlexGrow();
float resolveFlexShrink();
};
29 changes: 7 additions & 22 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) { \
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d85da86

Please sign in to comment.