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
@@ -250,6 +250,16 @@ jlong jni_YGNodeNewWithConfig(alias_ref<jobject> thiz, jlong configPointer) {
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
jlong jni_YGNodeClone(
|
||||
alias_ref<jobject> thiz,
|
||||
jlong nativePointer,
|
||||
alias_ref<jobject> clonedJavaObject) {
|
||||
const YGNodeRef clonedYogaNode = YGNodeClone(_jlong2YGNodeRef(nativePointer));
|
||||
clonedYogaNode->setContext(
|
||||
new weak_ref<jobject>(make_weak(clonedJavaObject)));
|
||||
return reinterpret_cast<jlong>(clonedYogaNode);
|
||||
}
|
||||
|
||||
void jni_YGNodeFree(alias_ref<jobject> thiz, jlong nativePointer) {
|
||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||
delete YGNodeJobject(node);
|
||||
@@ -612,6 +622,7 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
YGMakeNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
||||
YGMakeNativeMethod(jni_YGNodeGetInstanceCount),
|
||||
YGMakeNativeMethod(jni_YGNodePrint),
|
||||
YGMakeNativeMethod(jni_YGNodeClone),
|
||||
});
|
||||
registerNatives("com/facebook/yoga/YogaConfig",
|
||||
{
|
||||
|
Reference in New Issue
Block a user