Skip to content

Commit

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

Differential Revision: D6711830

fbshipit-source-id: d2f6f55ec23b007bb51f8a91385e02236f46dc7b
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Jan 15, 2018
1 parent 7f94bff commit bd7bf94
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
15 changes: 15 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,18 @@ float YGNode::getTrailingBorder(const YGFlexDirection flexDirection) {
->value,
0.0f);
}

float YGNode::getLeadingPadding(
const YGFlexDirection axis,
const float widthSize) {
if (YGFlexDirectionIsRow(axis) &&
style_.padding[YGEdgeStart].unit != YGUnitUndefined &&
YGResolveValue(style_.padding[YGEdgeStart], widthSize) >= 0.0f) {
return YGResolveValue(style_.padding[YGEdgeStart], widthSize);
}
return fmaxf(
YGResolveValue(
*YGComputedEdgeValue(style_.padding, leading[axis], &YGValueZero),
widthSize),
0.0f);
}
2 changes: 2 additions & 0 deletions ReactCommon/yoga/yoga/YGNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct YGNode {
std::array<YGValue, 2> getResolvedDimensions() const;
YGValue getResolvedDimension(int index);

// Methods related to positions, margin, padding and border
float getLeadingPosition(const YGFlexDirection axis, const float axisSize);
bool isLeadingPositionDefined(const YGFlexDirection axis);
bool isTrailingPosDefined(const YGFlexDirection axis);
Expand All @@ -87,6 +88,7 @@ struct YGNode {
float getTrailingMargin(const YGFlexDirection axis, const float widthSize);
float getLeadingBorder(const YGFlexDirection flexDirection);
float getTrailingBorder(const YGFlexDirection flexDirection);
float getLeadingPadding(const YGFlexDirection axis, const float widthSize);
// Setters

void setContext(void* context);
Expand Down
24 changes: 3 additions & 21 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,24 +762,6 @@ static const std::array<YGEdge, 4> pos = {{
static const std::array<YGDimension, 4> dim = {
{YGDimensionHeight, YGDimensionHeight, YGDimensionWidth, YGDimensionWidth}};

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

return fmaxf(
YGResolveValue(
*YGComputedEdgeValue(
node->getStyle().padding, leading[axis], &YGValueZero),
widthSize),
0.0f);
}

static float YGNodeTrailingPadding(const YGNodeRef node,
const YGFlexDirection axis,
const float widthSize) {
Expand All @@ -801,7 +783,7 @@ static inline float YGNodeLeadingPaddingAndBorder(
const YGNodeRef node,
const YGFlexDirection axis,
const float widthSize) {
return YGNodeLeadingPadding(node, axis, widthSize) +
return node->getLeadingPadding(axis, widthSize) +
node->getLeadingBorder(axis);
}

Expand Down Expand Up @@ -1757,11 +1739,11 @@ static void YGNodelayoutImpl(const YGNodeRef node,
node->getTrailingBorder(flexColumnDirection), YGEdgeBottom);

node->setLayoutPadding(
YGNodeLeadingPadding(node, flexRowDirection, parentWidth), YGEdgeStart);
node->getLeadingPadding(flexRowDirection, parentWidth), YGEdgeStart);
node->setLayoutPadding(
YGNodeTrailingPadding(node, flexRowDirection, parentWidth), YGEdgeEnd);
node->setLayoutPadding(
YGNodeLeadingPadding(node, flexColumnDirection, parentWidth), YGEdgeTop);
node->getLeadingPadding(flexColumnDirection, parentWidth), YGEdgeTop);
node->setLayoutPadding(
YGNodeTrailingPadding(node, flexColumnDirection, parentWidth),
YGEdgeBottom);
Expand Down

0 comments on commit bd7bf94

Please sign in to comment.