Skip to content

Commit

Permalink
Remove the usage of YGUndefined in the default values of Border in YG…
Browse files Browse the repository at this point in the history
…Style

Reviewed By: emilsjolander

Differential Revision: D7195115

fbshipit-source-id: e635cf55ac94d8a90caef6cafce281579da2cbfc
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Mar 14, 2018
1 parent 8466db0 commit af4a363
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ReactCommon/yoga/yoga/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,7 @@ bool YGFloatsEqual(const float a, const float b) {
}
return YGFloatIsUndefined(a) && YGFloatIsUndefined(b);
}

float YGFloatSanitize(const float& val) {
return YGFloatIsUndefined(val) ? 0 : val;
}
3 changes: 3 additions & 0 deletions ReactCommon/yoga/yoga/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ bool YGFloatArrayEqual(
return areEqual;
}

// This function returns 0 if YGFloatIsUndefined(val) is true and val otherwise
float YGFloatSanitize(const float& val);

YGFlexDirection YGFlexDirectionCross(
const YGFlexDirection flexDirection,
const YGDirection direction);
Expand Down
2 changes: 1 addition & 1 deletion ReactCommon/yoga/yoga/YGStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "YGStyle.h"

const YGValue kYGValueUndefined = {YGUndefined, YGUnitUndefined};
const YGValue kYGValueUndefined = {0, YGUnitUndefined};

const YGValue kYGValueAuto = {YGUndefined, YGUnitAuto};

Expand Down
30 changes: 29 additions & 1 deletion ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,35 @@ YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Position, position, position);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Margin, margin, margin);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Margin, margin);
YG_NODE_STYLE_EDGE_PROPERTY_UNIT_IMPL(YGValue, Padding, padding, padding);
YG_NODE_STYLE_EDGE_PROPERTY_IMPL(float, Border, border, border);

// TODO: Change the API to accept YGFloatOptional.
void YGNodeStyleSetBorder(
const YGNodeRef node,
const YGEdge edge,
const float border) {
YGValue value = {
.value = YGFloatSanitize(border),
.unit = YGFloatIsUndefined(border) ? YGUnitUndefined : YGUnitPoint,
};
if ((node->getStyle().border[edge].value != value.value &&
value.unit != YGUnitUndefined) ||
node->getStyle().border[edge].unit != value.unit) {
YGStyle style = node->getStyle();
style.border[edge] = value;
node->setStyle(style);
node->markDirtyAndPropogate();
}
}

float YGNodeStyleGetBorder(const YGNodeRef node, const YGEdge edge) {
if (node->getStyle().border[edge].unit == YGUnitUndefined) {
// TODO: Rather than returning YGUndefined, change the api to return
// YGFloatOptional.
return YGUndefined;
}

return node->getStyle().border[edge].value;
}

YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Width, width, dimensions[YGDimensionWidth]);
YG_NODE_STYLE_PROPERTY_UNIT_AUTO_IMPL(YGValue, Height, height, dimensions[YGDimensionHeight]);
Expand Down
5 changes: 5 additions & 0 deletions ReactCommon/yoga/yoga/Yoga.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ typedef struct YGValue {
YGUnit unit;
} YGValue;

struct YGFloatOptional {
bool isUndefined;
float value;
};

extern const YGValue YGValueUndefined;
extern const YGValue YGValueAuto;

Expand Down

0 comments on commit af4a363

Please sign in to comment.