Make Java YogaNode cloneable
Summary: This diff exposes the YogaNode clone operation to JNI in order to be able to clone Java YogaNode objects. The clone method performs a shallow copy of the java YogaNode. I made YogaNode to implement Cloneable, I know that this might not be a good idea but in this case it simplifies the cloning mechanism. I am open to suggestions. IMPORTANT NOTES: - The current implementation IS NOT making a deep copy of the mData instance variable. - The mParent Java instance variable will reference the parent of the original Java YogaNode, is that ok sebmarkbage? Reviewed By: priteshrnandgaonkar Differential Revision: D6935971 fbshipit-source-id: a2008f1eb849b5074585b48699b7de56d5ac90d4
This commit is contained in:
committed by
Facebook Github Bot
parent
43fda26275
commit
747c2a4208
@@ -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) {
|
||||
|
||||
|
Reference in New Issue
Block a user