Make Java YogaNode cloneable

Reviewed By: priteshrnandgaonkar

Differential Revision: D6935971

fbshipit-source-id: a2008f1eb849b5074585b48699b7de56d5ac90d4
This commit is contained in:
David Vacca
2018-02-14 18:10:23 -08:00
committed by Facebook Github Bot
parent db391a500c
commit 51def5ef7f
2 changed files with 25 additions and 2 deletions

View File

@@ -16,7 +16,7 @@ import java.util.List;
import javax.annotation.Nullable;
@DoNotStrip
public class YogaNode {
public class YogaNode implements Cloneable {
static {
SoLoader.loadLibrary("yoga");
@@ -31,7 +31,7 @@ public class YogaNode {
private List<YogaNode> mChildren;
private YogaMeasureFunction mMeasureFunction;
private YogaBaselineFunction mBaselineFunction;
private final long mNativePointer;
private long mNativePointer;
private Object mData;
/* Those flags needs be in sync with YGJNI.cpp */
@@ -160,6 +160,18 @@ public class YogaNode {
jni_YGNodeInsertChild(mNativePointer, child.mNativePointer, i);
}
private native long jni_YGNodeClone(long nativePointer, Object newNode);
@Override
public YogaNode clone() throws CloneNotSupportedException {
YogaNode clonedYogaNode = (YogaNode) super.clone();
long clonedNativePointer = jni_YGNodeClone(mNativePointer, clonedYogaNode);
clonedYogaNode.mNativePointer = clonedNativePointer;
clonedYogaNode.mChildren =
mChildren != null ? (List<YogaNode>) ((ArrayList) mChildren).clone() : null;
return clonedYogaNode;
}
private native void jni_YGNodeRemoveChild(long nativePointer, long childPointer);
public YogaNode removeChildAt(int i) {