Refactor YogaNode.Inputs freeze API

Summary:
`InternalNode` will eventually not have a pointer to its parent. This diff removes one of the usages of the `InternalNode#getParent()` API. `InternalNode` will also not host the `YogaNode` eventually; so this diff also removes one of the usages of the `InternalNode#getYogaNode()` api.

Now the `Inputs#freeze` api will pass the parent's `YogaNode` and the `YogaNode` of the node (this) being measured.

Changelog: [Internal] Passes The YogaNode and parent YogaNode in the Inputs.freeze API

Reviewed By: SidharthGuglani

Differential Revision: D27240229

fbshipit-source-id: efc4ec3249a963c3181111f9b989d8ed9e17feb4
This commit is contained in:
Aditya Sharat
2021-03-30 05:41:22 -07:00
committed by Facebook GitHub Bot
parent 07eaeea7a4
commit cbf6495d66
2 changed files with 7 additions and 6 deletions

View File

@@ -15,7 +15,7 @@ public abstract class YogaNode implements YogaProps {
public interface Inputs {
/** Requests the data object to disable mutations of its inputs. */
void freeze();
void freeze(final YogaNode node, final @Nullable YogaNode parent);
}
public abstract void reset();

View File

@@ -197,15 +197,16 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
long[] nativePointers = null;
YogaNodeJNIBase[] nodes = null;
freeze();
freeze(null);
ArrayList<YogaNodeJNIBase> n = new ArrayList<>();
n.add(this);
for (int i = 0; i < n.size(); ++i) {
List<YogaNodeJNIBase> children = n.get(i).mChildren;
final YogaNodeJNIBase parent = n.get(i);
List<YogaNodeJNIBase> children = parent.mChildren;
if (children != null) {
for (YogaNodeJNIBase child : children) {
child.freeze();
child.freeze(parent);
n.add(child);
}
}
@@ -220,10 +221,10 @@ public abstract class YogaNodeJNIBase extends YogaNode implements Cloneable {
YogaNative.jni_YGNodeCalculateLayoutJNI(mNativePointer, width, height, nativePointers, nodes);
}
private void freeze() {
private void freeze(YogaNode parent) {
Object data = getData();
if (data instanceof Inputs) {
((Inputs) data).freeze();
((Inputs) data).freeze(this, parent);
}
}