Avoid cleaning up Owner of YGNode during clonning
Summary: This diff refactors the cloning mechanism for YogaNode used from Fabric UI renderer and RN iOS graphs. Previously, we were cleaning the owner of the child's cloned node inside the C++ implementation of YogaNode. This was a mistake because this modified the last commited YogaTree, causing side effect in RN iOS graphs. Reviewed By: shergin Differential Revision: D8672627 fbshipit-source-id: c9902d00690e0361fd58aed84b506c42258bd995
This commit is contained in:
committed by
Facebook Github Bot
parent
77ea79490f
commit
f4d29e6f11
@@ -175,6 +175,8 @@ public class YogaNode implements Cloneable {
|
||||
jni_YGNodeInsertSharedChild(mNativePointer, child.mNativePointer, i);
|
||||
}
|
||||
|
||||
private native void jni_YGNodeSetOwner(long nativePointer, long newOwnerNativePointer);
|
||||
|
||||
private native long jni_YGNodeClone(long nativePointer, Object newNode);
|
||||
|
||||
@Override
|
||||
@@ -182,6 +184,14 @@ public class YogaNode implements Cloneable {
|
||||
try {
|
||||
YogaNode clonedYogaNode = (YogaNode) super.clone();
|
||||
long clonedNativePointer = jni_YGNodeClone(mNativePointer, clonedYogaNode);
|
||||
|
||||
if (mChildren != null) {
|
||||
for (YogaNode child : mChildren) {
|
||||
child.jni_YGNodeSetOwner(child.mNativePointer, 0);
|
||||
child.mOwner = null;
|
||||
}
|
||||
}
|
||||
|
||||
clonedYogaNode.mNativePointer = clonedNativePointer;
|
||||
clonedYogaNode.mOwner = null;
|
||||
clonedYogaNode.mChildren =
|
||||
|
@@ -268,6 +268,16 @@ jlong jni_YGNodeNewWithConfig(alias_ref<jobject> thiz, jlong configPointer) {
|
||||
return reinterpret_cast<jlong>(node);
|
||||
}
|
||||
|
||||
void jni_YGNodeSetOwner(
|
||||
alias_ref<jobject> thiz,
|
||||
jlong nativePointer,
|
||||
jlong newOwnerNativePointer) {
|
||||
const YGNodeRef node = _jlong2YGNodeRef(nativePointer);
|
||||
const YGNodeRef newOwnerNode = _jlong2YGNodeRef(newOwnerNativePointer);
|
||||
|
||||
node->setOwner(newOwnerNode);
|
||||
}
|
||||
|
||||
jlong jni_YGNodeClone(
|
||||
alias_ref<jobject> thiz,
|
||||
jlong nativePointer,
|
||||
@@ -667,6 +677,7 @@ jint JNI_OnLoad(JavaVM *vm, void *) {
|
||||
YGMakeNativeMethod(jni_YGNodeGetInstanceCount),
|
||||
YGMakeNativeMethod(jni_YGNodePrint),
|
||||
YGMakeNativeMethod(jni_YGNodeClone),
|
||||
YGMakeNativeMethod(jni_YGNodeSetOwner),
|
||||
});
|
||||
registerNatives(
|
||||
"com/facebook/yoga/YogaConfig",
|
||||
|
@@ -244,9 +244,6 @@ YGNodeRef YGNodeClone(YGNodeRef oldNode) {
|
||||
oldNode->getConfig(),
|
||||
node != nullptr,
|
||||
"Could not allocate memory for node");
|
||||
for (auto &item : oldNode->getChildren()) {
|
||||
item->setOwner(nullptr);
|
||||
}
|
||||
gNodeInstanceCount++;
|
||||
node->setOwner(nullptr);
|
||||
return node;
|
||||
|
Reference in New Issue
Block a user