From 56279110c0b8e7c246091f333b7657703635e72c Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Fri, 7 Oct 2016 05:15:59 -0700 Subject: [PATCH] Resolve some differences between CSSNode and CSSNodeJNI Summary: This diff resolves some differences in behaviour between jni and java css nodes. This ensures certain test cases pass with both implementations. Reviewed By: lucasr Differential Revision: D3960755 fbshipit-source-id: 3e13a9435208851a96a619c07625ef2a5402f5ec --- java/com/facebook/csslayout/CSSNode.java | 1 + java/com/facebook/csslayout/CSSNodeJNI.java | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/java/com/facebook/csslayout/CSSNode.java b/java/com/facebook/csslayout/CSSNode.java index ae9f07b9..2795d8ce 100644 --- a/java/com/facebook/csslayout/CSSNode.java +++ b/java/com/facebook/csslayout/CSSNode.java @@ -649,5 +649,6 @@ public class CSSNode implements CSSNodeAPI { layout.resetResult(); lineIndex = 0; mLayoutState = LayoutState.DIRTY; + mMeasureFunction = null; } } diff --git a/java/com/facebook/csslayout/CSSNodeJNI.java b/java/com/facebook/csslayout/CSSNodeJNI.java index 356bddcc..3f770464 100644 --- a/java/com/facebook/csslayout/CSSNodeJNI.java +++ b/java/com/facebook/csslayout/CSSNodeJNI.java @@ -56,6 +56,9 @@ public class CSSNodeJNI implements CSSNodeAPI { @Override public void reset() { assertNativeInstance(); + if (mParent != null || (mChildren != null && mChildren.size() > 0)) { + throw new IllegalStateException("You should not reset an attached CSSNode"); + } jni_CSSNodeFree(mNativePointer); mNativePointer = 0; @@ -78,6 +81,9 @@ public class CSSNodeJNI implements CSSNodeAPI { @Override public void addChildAt(CSSNodeJNI child, int i) { assertNativeInstance(); + if (child.mParent != null) { + throw new IllegalStateException("Child already has a parent, it must be removed first."); + } mChildren.add(i, child); child.mParent = this;