Skip to content

Commit

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

Differential Revision: D6711666

fbshipit-source-id: fe4fdfc2db59d03beb763317e1a6f9de52f851d4
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Jan 15, 2018
1 parent 210ae5b commit 8208858
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
13 changes: 13 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,16 @@ float YGNode::getLeadingBorder(const YGFlexDirection axis) {
YGComputedEdgeValue(style_.border, leading[axis], &YGValueZero)->value,
0.0f);
}

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

return fmaxf(
YGComputedEdgeValue(style_.border, trailing[flexDirection], &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 @@ -86,6 +86,7 @@ struct YGNode {
float getLeadingMargin(const YGFlexDirection axis, const float widthSize);
float getTrailingMargin(const YGFlexDirection axis, const float widthSize);
float getLeadingBorder(const YGFlexDirection flexDirection);
float getTrailingBorder(const YGFlexDirection flexDirection);
// Setters

void setContext(void* context);
Expand Down
31 changes: 8 additions & 23 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 YGNodeTrailingBorder(
const YGNodeRef node,
const YGFlexDirection axis) {
if (YGFlexDirectionIsRow(axis) &&
node->getStyle().border[YGEdgeEnd].unit != YGUnitUndefined &&
node->getStyle().border[YGEdgeEnd].value >= 0.0f) {
return node->getStyle().border[YGEdgeEnd].value;
}

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

static inline float YGNodeLeadingPaddingAndBorder(
const YGNodeRef node,
const YGFlexDirection axis,
Expand All @@ -823,7 +808,8 @@ static inline float YGNodeLeadingPaddingAndBorder(
static inline float YGNodeTrailingPaddingAndBorder(const YGNodeRef node,
const YGFlexDirection axis,
const float widthSize) {
return YGNodeTrailingPadding(node, axis, widthSize) + YGNodeTrailingBorder(node, axis);
return YGNodeTrailingPadding(node, axis, widthSize) +
node->getTrailingBorder(axis);
}

static inline float YGNodeMarginForAxis(const YGNodeRef node,
Expand Down Expand Up @@ -1221,7 +1207,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->isTrailingPosDefined(YGFlexDirectionRow)) {
childWidth = node->getLayout().measuredDimensions[YGDimensionWidth] -
(node->getLeadingBorder(YGFlexDirectionRow) +
YGNodeTrailingBorder(node, YGFlexDirectionRow)) -
node->getTrailingBorder(YGFlexDirectionRow)) -
(child->getLeadingPosition(YGFlexDirectionRow, width) +
child->getTrailingPosition(YGFlexDirectionRow, width));
childWidth = YGNodeBoundAxis(child, YGFlexDirectionRow, childWidth, width, width);
Expand All @@ -1240,7 +1226,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->isTrailingPosDefined(YGFlexDirectionColumn)) {
childHeight = node->getLayout().measuredDimensions[YGDimensionHeight] -
(node->getLeadingBorder(YGFlexDirectionColumn) +
YGNodeTrailingBorder(node, YGFlexDirectionColumn)) -
node->getTrailingBorder(YGFlexDirectionColumn)) -
(child->getLeadingPosition(YGFlexDirectionColumn, height) +
child->getTrailingPosition(YGFlexDirectionColumn, height));
childHeight = YGNodeBoundAxis(child, YGFlexDirectionColumn, childHeight, height, width);
Expand Down Expand Up @@ -1311,7 +1297,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->setLayoutPosition(
node->getLayout().measuredDimensions[dim[mainAxis]] -
child->getLayout().measuredDimensions[dim[mainAxis]] -
YGNodeTrailingBorder(node, mainAxis) -
node->getTrailingBorder(mainAxis) -
child->getTrailingMargin(mainAxis, width) -
child->getTrailingPosition(
mainAxis, isMainAxisRow ? width : height),
Expand All @@ -1338,7 +1324,7 @@ static void YGNodeAbsoluteLayoutChild(const YGNodeRef node,
child->setLayoutPosition(
node->getLayout().measuredDimensions[dim[crossAxis]] -
child->getLayout().measuredDimensions[dim[crossAxis]] -
YGNodeTrailingBorder(node, crossAxis) -
node->getTrailingBorder(crossAxis) -
child->getTrailingMargin(crossAxis, width) -
child->getTrailingPosition(
crossAxis, isMainAxisRow ? height : width),
Expand Down Expand Up @@ -1775,11 +1761,10 @@ static void YGNodelayoutImpl(const YGNodeRef node,
node->getTrailingMargin(flexColumnDirection, parentWidth), YGEdgeBottom);

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

node->setLayoutPadding(
YGNodeLeadingPadding(node, flexRowDirection, parentWidth), YGEdgeStart);
Expand Down

0 comments on commit 8208858

Please sign in to comment.