Skip to content

Commit

Permalink
Move leading border function as a method on YGNode
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D6711523

fbshipit-source-id: 76e90083a9dd0728dc9557cc3b0a1f431f3afd5d
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Jan 15, 2018
1 parent 2b27f1a commit 210ae5b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
12 changes: 12 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,3 +596,15 @@ bool YGNode::isNodeFlexible() {
(style_.positionType == YGPositionTypeRelative) &&
(resolveFlexGrow() != 0 || resolveFlexShrink() != 0));
}

float YGNode::getLeadingBorder(const YGFlexDirection axis) {
if (YGFlexDirectionIsRow(axis) &&
style_.border[YGEdgeStart].unit != YGUnitUndefined &&
style_.border[YGEdgeStart].value >= 0.0f) {
return style_.border[YGEdgeStart].value;
}

return fmaxf(
YGComputedEdgeValue(style_.border, leading[axis], &YGValueZero)->value,
0.0f);
}
1 change: 1 addition & 0 deletions ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ struct YGNode {
float getTrailingPosition(const YGFlexDirection axis, const float axisSize);
float getLeadingMargin(const YGFlexDirection axis, const float widthSize);
float getTrailingMargin(const YGFlexDirection axis, const float widthSize);
float getLeadingBorder(const YGFlexDirection flexDirection);
// Setters

void setContext(void* context);
Expand Down
35 changes: 9 additions & 26 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,21 +797,6 @@ static float YGNodeTrailingPadding(const YGNodeRef node,
0.0f);
}

static float YGNodeLeadingBorder(
const YGNodeRef node,
const YGFlexDirection axis) {
if (YGFlexDirectionIsRow(axis) &&
node->getStyle().border[YGEdgeStart].unit != YGUnitUndefined &&
node->getStyle().border[YGEdgeStart].value >= 0.0f) {
return node->getStyle().border[YGEdgeStart].value;
}

return fmaxf(
YGComputedEdgeValue(node->getStyle().border, leading[axis], &YGValueZero)
->value,
0.0f);
}

static float YGNodeTrailingBorder(
const YGNodeRef node,
const YGFlexDirection axis) {
Expand All @@ -832,7 +817,7 @@ static inline float YGNodeLeadingPaddingAndBorder(
const YGFlexDirection axis,
const float widthSize) {
return YGNodeLeadingPadding(node, axis, widthSize) +
YGNodeLeadingBorder(node, axis);
node->getLeadingBorder(axis);
}

static inline float YGNodeTrailingPaddingAndBorder(const YGNodeRef node,
Expand Down Expand Up @@ -1235,7 +1220,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
if (child->isLeadingPositionDefined(YGFlexDirectionRow) &&
child->isTrailingPosDefined(YGFlexDirectionRow)) {
childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] -
(YGNodeLeadingBorder(node, YGFlexDirectionRow) +
(node->getLeadingBorder(YGFlexDirectionRow) +
YGNodeTrailingBorder(node, YGFlexDirectionRow)) -
(child->getLeadingPosition(YGFlexDirectionRow, width) +
child->getTrailingPosition(YGFlexDirectionRow, width));
Expand All @@ -1254,7 +1239,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
if (child->isLeadingPositionDefined(YGFlexDirectionColumn) &&
child->isTrailingPosDefined(YGFlexDirectionColumn)) {
childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] -
(YGNodeLeadingBorder(node, YGFlexDirectionColumn) +
(node->getLeadingBorder(YGFlexDirectionColumn) +
YGNodeTrailingBorder(node, YGFlexDirectionColumn)) -
(child->getLeadingPosition(YGFlexDirectionColumn, height) +
child->getTrailingPosition(YGFlexDirectionColumn, height));
Expand Down Expand Up @@ -1789,12 +1774,10 @@ static void YGNodelayoutImpl(const YGNodeRef node,
node->setLayoutMargin(
node->getTrailingMargin(flexColumnDirection, parentWidth), YGEdgeBottom);

node->setLayoutBorder(
YGNodeLeadingBorder(node, flexRowDirection), YGEdgeStart);
node->setLayoutBorder(node->getLeadingBorder(flexRowDirection), YGEdgeStart);
node->setLayoutBorder(
YGNodeTrailingBorder(node, flexRowDirection), YGEdgeEnd);
node->setLayoutBorder(
YGNodeLeadingBorder(node, flexColumnDirection), YGEdgeTop);
node->setLayoutBorder(node->getLeadingBorder(flexColumnDirection), YGEdgeTop);
node->setLayoutBorder(
YGNodeTrailingBorder(node, flexColumnDirection), YGEdgeBottom);

Expand Down Expand Up @@ -2459,7 +2442,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
// (and margin/border).
child->setLayoutPosition(
child->getLeadingPosition(mainAxis, availableInnerMainDim) +
YGNodeLeadingBorder(node, mainAxis) +
node->getLeadingBorder(mainAxis) +
child->getLeadingMargin(mainAxis, availableInnerWidth),
pos[mainAxis]);
}
Expand Down Expand Up @@ -2501,7 +2484,7 @@ static void YGNodelayoutImpl(const YGNodeRef node,
} else if (performLayout) {
child->setLayoutPosition(
child->getLayout().position[pos[mainAxis]] +
YGNodeLeadingBorder(node, mainAxis) + leadingMainDim,
node->getLeadingBorder(mainAxis) + leadingMainDim,
pos[mainAxis]);
}
}
Expand Down Expand Up @@ -2552,15 +2535,15 @@ static void YGNodelayoutImpl(const YGNodeRef node,
if (isChildLeadingPosDefined) {
child->setLayoutPosition(
child->getLeadingPosition(crossAxis, availableInnerCrossDim) +
YGNodeLeadingBorder(node, crossAxis) +
node->getLeadingBorder(crossAxis) +
child->getLeadingMargin(crossAxis, availableInnerWidth),
pos[crossAxis]);
}
// If leading position is not defined or calculations result in Nan, default to border + margin
if (!isChildLeadingPosDefined ||
YGFloatIsUndefined(child->getLayout().position[pos[crossAxis]])) {
child->setLayoutPosition(
YGNodeLeadingBorder(node, crossAxis) +
node->getLeadingBorder(crossAxis) +
child->getLeadingMargin(crossAxis, availableInnerWidth),
pos[crossAxis]);
}
Expand Down

0 comments on commit 210ae5b

Please sign in to comment.