From 168ae4099d039d20129f44d4eb63499e00db9073 Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Sat, 11 Feb 2017 06:19:56 -0800 Subject: [PATCH] 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 --- java/com/facebook/yoga/YogaNode.java | 6 +++--- java/tests/com/facebook/yoga/YogaNodeTest.java | 12 ++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/java/com/facebook/yoga/YogaNode.java b/java/com/facebook/yoga/YogaNode.java index c53aecc6..08edbd46 100644 --- a/java/com/facebook/yoga/YogaNode.java +++ b/java/com/facebook/yoga/YogaNode.java @@ -382,7 +382,7 @@ public class YogaNode implements YogaNodeAPI { @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 { @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 { @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()); } diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java index e5575d46..5b21a28e 100644 --- a/java/tests/com/facebook/yoga/YogaNodeTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -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))); + } + } }