Adds InternalNode#freeze() API
Summary: Litho needs a new API which is called immediately before yoga begins layout calculations so that the InternalNode gets the opportunity to finalise itself; i.e. perform the last mutations and in effect avoid any more mutations to the hierarchy. See D26373731 where the mutations from `Layout#collectResults` is moved back into the InternalNode. Changelog: [Internal] Adds new API to YogaNodeJNIBase Reviewed By: SidharthGuglani Differential Revision: D26373730 fbshipit-source-id: 471346d3444986ada91e86c95f5f9fb98bcd2fa6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
651c527e94
commit
de36e85004
@@ -10,6 +10,14 @@ package com.facebook.yoga;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class YogaNode {
|
||||
|
||||
/** The interface the {@link #getData()} object can optionally implement. */
|
||||
public interface Inputs {
|
||||
|
||||
/** Requests the data object to disable mutations of its inputs. */
|
||||
void freeze();
|
||||
}
|
||||
|
||||
public abstract void reset();
|
||||
|
||||
public abstract int getChildCount();
|
||||
@@ -25,12 +33,10 @@ public abstract class YogaNode {
|
||||
public abstract YogaNode removeChildAt(int i);
|
||||
|
||||
/**
|
||||
* @returns the {@link YogaNode} that owns this {@link YogaNode}.
|
||||
* The owner is used to identify the YogaTree that a {@link YogaNode} belongs
|
||||
* to.
|
||||
* This method will return the parent of the {@link YogaNode} when the
|
||||
* {@link YogaNode} only belongs to one YogaTree or null when the
|
||||
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||
* @returns the {@link YogaNode} that owns this {@link YogaNode}. The owner is used to identify
|
||||
* the YogaTree that a {@link YogaNode} belongs to. This method will return the parent of the
|
||||
* {@link YogaNode} when the {@link YogaNode} only belongs to one YogaTree or null when the
|
||||
* {@link YogaNode} is shared between two or more YogaTrees.
|
||||
*/
|
||||
@Nullable
|
||||
public abstract YogaNode getOwner();
|
||||
|
@@ -197,12 +197,17 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
|
||||
long[] nativePointers = null;
|
||||
YogaNodeJNIBase[] nodes = null;
|
||||
|
||||
freeze();
|
||||
|
||||
ArrayList<YogaNodeJNIBase> n = new ArrayList<>();
|
||||
n.add(this);
|
||||
for (int i = 0; i < n.size(); ++i) {
|
||||
List<YogaNodeJNIBase> children = n.get(i).mChildren;
|
||||
if (children != null) {
|
||||
n.addAll(children);
|
||||
for (YogaNodeJNIBase child : children) {
|
||||
child.freeze();
|
||||
n.add(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,6 +220,13 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
|
||||
YogaNative.jni_YGNodeCalculateLayoutJNI(mNativePointer, width, height, nativePointers, nodes);
|
||||
}
|
||||
|
||||
private void freeze() {
|
||||
Object data = getData();
|
||||
if (data instanceof Inputs) {
|
||||
((Inputs) data).freeze();
|
||||
}
|
||||
}
|
||||
|
||||
public void dirty() {
|
||||
YogaNative.jni_YGNodeMarkDirtyJNI(mNativePointer);
|
||||
}
|
||||
|
Reference in New Issue
Block a user