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
This commit is contained in:
Emil Sjolander
2017-02-11 06:19:56 -08:00
committed by Facebook Github Bot
parent 6ceb4af2d4
commit 168ae4099d
2 changed files with 15 additions and 3 deletions

View File

@@ -382,7 +382,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
@Override
public YogaValue getMargin(YogaEdge edge) {
if (!mHasSetMargin) {
return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED;
return YogaValue.UNDEFINED;
}
return (YogaValue) jni_YGNodeStyleGetMargin(mNativePointer, edge.intValue());
}
@@ -405,7 +405,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
@Override
public YogaValue getPadding(YogaEdge edge) {
if (!mHasSetPadding) {
return edge.intValue() < YogaEdge.START.intValue() ? YogaValue.ZERO : YogaValue.UNDEFINED;
return YogaValue.UNDEFINED;
}
return (YogaValue) jni_YGNodeStyleGetPadding(mNativePointer, edge.intValue());
}
@@ -428,7 +428,7 @@ public class YogaNode implements YogaNodeAPI<YogaNode> {
@Override
public float getBorder(YogaEdge edge) {
if (!mHasSetBorder) {
return edge.intValue() < YogaEdge.START.intValue() ? 0 : YogaConstants.UNDEFINED;
return YogaConstants.UNDEFINED;
}
return jni_YGNodeStyleGetBorder(mNativePointer, edge.intValue());
}

View File

@@ -230,4 +230,16 @@ public class YogaNodeTest {
assertEquals(5, (int) node.getLayoutPadding(YogaEdge.TOP));
assertEquals(5, (int) node.getLayoutPadding(YogaEdge.BOTTOM));
}
@Test
public void testDefaultEdgeValues() {
final YogaNode node = new YogaNode();
for (YogaEdge edge : YogaEdge.values()) {
assertEquals(YogaUnit.UNDEFINED, node.getMargin(edge).unit);
assertEquals(YogaUnit.UNDEFINED, node.getPadding(edge).unit);
assertEquals(YogaUnit.UNDEFINED, node.getPosition(edge).unit);
assertTrue(YogaConstants.isUndefined(node.getBorder(edge)));
}
}
}