Skip to content

Commit 168ae40

Browse files
Emil Sjolanderfacebook-github-bot
authored andcommitted
Always return undefined value if nothing is set
Summary: This reflects a check to native code where style values will always return the value that was set on them and default to undefined. Reviewed By: astreet Differential Revision: D4531779 fbshipit-source-id: 97a789e70dcf0fb5174e2039991e7a2b27f45f01
1 parent 6ceb4af commit 168ae40

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

java/com/facebook/yoga/YogaNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public void setFlexBasisPercent(float percent) {
382382
@Override
383383
public YogaValue getMargin(YogaEdge edge) {
384384
if (!mHasSetMargin) {
385-
return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED;
385+
return YogaValue.UNDEFINED;
386386
}
387387
return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
388388
}
@@ -405,7 +405,7 @@ public void setMarginPercent(YogaEdge edge, float percent) {
405405
@Override
406406
public YogaValue getPadding(YogaEdge edge) {
407407
if (!mHasSetPadding) {
408-
return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED;
408+
return YogaValue.UNDEFINED;
409409
}
410410
return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
411411
}
@@ -428,7 +428,7 @@ public void setPaddingPercent(YogaEdge edge, float percent) {
428428
@Override
429429
public float getBorder(YogaEdge edge) {
430430
if (!mHasSetBorder) {
431-
return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED;
431+
return YogaConstants.UNDEFINED;
432432
}
433433
return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
434434
}

java/tests/com/facebook/yoga/YogaNodeTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,16 @@ public void testPercentPaddingOnRoot() {
230230
assertEquals(5, (int) node.getLayoutPadding(YogaEdge.TOP));
231231
assertEquals(5, (int) node.getLayoutPadding(YogaEdge.BOTTOM));
232232
}
233+
234+
@Test
235+
public void testDefaultEdgeValues() {
236+
final YogaNode node = new YogaNode();
237+
238+
for (YogaEdge edge : YogaEdge.values()) {
239+
assertEquals(YogaUnit.UNDEFINED, node.getMargin(edge).unit);
240+
assertEquals(YogaUnit.UNDEFINED, node.getPadding(edge).unit);
241+
assertEquals(YogaUnit.UNDEFINED, node.getPosition(edge).unit);
242+
assertTrue(YogaConstants.isUndefined(node.getBorder(edge)));
243+
}
244+
}
233245
}

0 commit comments

Comments
 (0)