Skip to content

Commit

Permalink
Fix setter and getter of margin, position, border and padding
Browse files Browse the repository at this point in the history
Reviewed By: emilsjolander

Differential Revision: D7274115

fbshipit-source-id: 942a91e6562ef789ae79102a828f397889468fa7
  • Loading branch information
priteshrnandgaonkar authored and facebook-github-bot committed Mar 15, 2018
1 parent 6b1dc71 commit 040642d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
5 changes: 4 additions & 1 deletion ReactCommon/yoga/yoga/YGNodePrint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ appendNumberIfNotAuto(string* base, const string& key, const YGValue number) {

static void
appendNumberIfNotZero(string* base, const string& str, const YGValue number) {
if (!YGFloatsEqual(number.value, 0)) {

if (number.unit == YGUnitAuto) {
base->append(str + ": auto; ");
} else if (!YGFloatsEqual(number.value, 0)) {
appendNumberIfNotUndefined(base, str, number);
}
}
Expand Down
34 changes: 9 additions & 25 deletions ReactCommon/yoga/yoga/Yoga.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
void YGNodeStyleSet##name##Auto(const YGNodeRef node, const YGEdge edge) { \
if (node->getStyle().instanceName[edge].unit != YGUnitAuto) { \
YGStyle style = node->getStyle(); \
style.instanceName[edge].value = YGUndefined; \
style.instanceName[edge].value = 0; \
style.instanceName[edge].unit = YGUnitAuto; \
node->setStyle(style); \
node->markDirtyAndPropogate(); \
Expand All @@ -649,7 +649,7 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
void YGNodeStyleSet##name( \
const YGNodeRef node, const YGEdge edge, const float paramName) { \
YGValue value = { \
.value = paramName, \
.value = YGFloatSanitize(paramName), \
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
}; \
if ((node->getStyle().instanceName[edge].value != value.value && \
Expand All @@ -665,7 +665,7 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
void YGNodeStyleSet##name##Percent( \
const YGNodeRef node, const YGEdge edge, const float paramName) { \
YGValue value = { \
.value = paramName, \
.value = YGFloatSanitize(paramName), \
.unit = \
YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPercent, \
}; \
Expand All @@ -681,28 +681,11 @@ float YGNodeStyleGetFlexShrink(const YGNodeRef node) {
\
WIN_STRUCT(type) \
YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
return WIN_STRUCT_REF(node->getStyle().instanceName[edge]); \
}

#define YG_NODE_STYLE_EDGE_PROPERTY_IMPL(type, name, paramName, instanceName) \
void YGNodeStyleSet##name( \
const YGNodeRef node, const YGEdge edge, const float paramName) { \
YGValue value = { \
.value = paramName, \
.unit = YGFloatIsUndefined(paramName) ? YGUnitUndefined : YGUnitPoint, \
}; \
if ((node->getStyle().instanceName[edge].value != value.value && \
value.unit != YGUnitUndefined) || \
node->getStyle().instanceName[edge].unit != value.unit) { \
YGStyle style = node->getStyle(); \
style.instanceName[edge] = value; \
node->setStyle(style); \
node->markDirtyAndPropogate(); \
YGValue value = node->getStyle().instanceName[edge]; \
if (value.unit == YGUnitUndefined || value.unit == YGUnitAuto) { \
value.value = YGUndefined; \
} \
} \
\
float YGNodeStyleGet##name(const YGNodeRef node, const YGEdge edge) { \
return node->getStyle().instanceName[edge].value; \
return WIN_STRUCT_REF(value); \
}

#define YG_NODE_LAYOUT_PROPERTY_IMPL(type, name, instanceName) \
Expand Down Expand Up @@ -873,7 +856,8 @@ void YGNodeStyleSetBorder(
}

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

0 comments on commit 040642d

Please sign in to comment.