Add YogaNode.cloneWithoutChildren
Summary: Adding flat clone method back to YogaNode for reconciliation. Reviewed By: davidaurelio Differential Revision: D14683019 fbshipit-source-id: 08ed2ffbb16052cb11aa464f67a7ba9a64297985
This commit is contained in:
committed by
Facebook Github Bot
parent
e0bc0ebe29
commit
a1e47e37ae
@@ -111,4 +111,5 @@ public class YogaNative {
|
|||||||
static native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
|
static native void jni_YGNodeSetHasBaselineFunc(long nativePointer, boolean hasMeasureFunc);
|
||||||
static native void jni_YGNodePrint(long nativePointer);
|
static native void jni_YGNodePrint(long nativePointer);
|
||||||
static native void jni_YGNodeSetStyleInputs(long nativePointer, float[] styleInputsArray, int size);
|
static native void jni_YGNodeSetStyleInputs(long nativePointer, float[] styleInputsArray, int size);
|
||||||
|
static native long jni_YGNodeClone(long nativePointer);
|
||||||
}
|
}
|
||||||
|
@@ -221,4 +221,6 @@ public abstract class YogaNode {
|
|||||||
public abstract void print();
|
public abstract void print();
|
||||||
|
|
||||||
public abstract void setStyleInputs(float[] styleInputs, int size);
|
public abstract void setStyleInputs(float[] styleInputs, int size);
|
||||||
|
|
||||||
|
public abstract YogaNode cloneWithoutChildren();
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ import java.util.List;
|
|||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
public abstract class YogaNodeJNIBase extends YogaNode {
|
public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
|
||||||
|
|
||||||
@Nullable private YogaNodeJNIBase mOwner;
|
@Nullable private YogaNodeJNIBase mOwner;
|
||||||
@Nullable private List<YogaNodeJNIBase> mChildren;
|
@Nullable private List<YogaNodeJNIBase> mChildren;
|
||||||
@@ -93,6 +93,21 @@ public abstract class YogaNodeJNIBase extends YogaNode {
|
|||||||
return YogaNative.jni_YGNodeIsReferenceBaseline(mNativePointer);
|
return YogaNative.jni_YGNodeIsReferenceBaseline(mNativePointer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public YogaNodeJNIBase cloneWithoutChildren() {
|
||||||
|
try {
|
||||||
|
YogaNodeJNIBase clonedYogaNode = (YogaNodeJNIBase) super.clone();
|
||||||
|
long clonedNativePointer = YogaNative.jni_YGNodeClone(mNativePointer);
|
||||||
|
clonedYogaNode.mOwner = null;
|
||||||
|
clonedYogaNode.mNativePointer = clonedNativePointer;
|
||||||
|
clonedYogaNode.clearChildren();
|
||||||
|
return clonedYogaNode;
|
||||||
|
} catch (CloneNotSupportedException ex) {
|
||||||
|
// This class implements Cloneable, this should not happen
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void clearChildren() {
|
private void clearChildren() {
|
||||||
mChildren = null;
|
mChildren = null;
|
||||||
YogaNative.jni_YGNodeClearChildren(mNativePointer);
|
YogaNative.jni_YGNodeClearChildren(mNativePointer);
|
||||||
|
@@ -372,6 +372,14 @@ static inline YGConfigRef _jlong2YGConfigRef(jlong addr) {
|
|||||||
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
|
return reinterpret_cast<YGConfigRef>(static_cast<intptr_t>(addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jlong jni_YGNodeClone(alias_ref<jobject> thiz, jlong nativePointer) {
|
||||||
|
auto node = _jlong2YGNodeRef(nativePointer);
|
||||||
|
const YGNodeRef clonedYogaNode = YGNodeClone(node);
|
||||||
|
clonedYogaNode->setContext(node->getContext());
|
||||||
|
|
||||||
|
return reinterpret_cast<jlong>(clonedYogaNode);
|
||||||
|
}
|
||||||
|
|
||||||
static YGSize YGJNIMeasureFunc(
|
static YGSize YGJNIMeasureFunc(
|
||||||
YGNodeRef node,
|
YGNodeRef node,
|
||||||
float width,
|
float width,
|
||||||
@@ -1103,6 +1111,7 @@ jint JNI_OnLoad(JavaVM* vm, void*) {
|
|||||||
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
YGMakeCriticalNativeMethod(jni_YGNodeStyleSetAspectRatio),
|
||||||
YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount),
|
YGMakeCriticalNativeMethod(jni_YGNodeGetInstanceCount),
|
||||||
YGMakeCriticalNativeMethod(jni_YGNodePrint),
|
YGMakeCriticalNativeMethod(jni_YGNodePrint),
|
||||||
|
YGMakeNativeMethod(jni_YGNodeClone),
|
||||||
YGMakeNativeMethod(jni_YGNodeSetStyleInputs),
|
YGMakeNativeMethod(jni_YGNodeSetStyleInputs),
|
||||||
YGMakeNativeMethod(jni_YGConfigNew),
|
YGMakeNativeMethod(jni_YGConfigNew),
|
||||||
YGMakeNativeMethod(jni_YGConfigFree),
|
YGMakeNativeMethod(jni_YGConfigFree),
|
||||||
|
Reference in New Issue
Block a user