Skip to content

Commit

Permalink
Refactor YogaNode.Inputs freeze API
Browse files Browse the repository at this point in the history
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
  • Loading branch information
adityasharat authored and facebook-github-bot committed Mar 30, 2021
1 parent 72d45de commit 24bfa46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.java
Expand Up @@ -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();
Expand Down
Expand Up @@ -197,15 +197,16 @@ public void calculateLayout(float width, float height) {
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);
}
}
Expand All @@ -220,10 +221,10 @@ public void calculateLayout(float width, float height) {
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);
}
}

Expand Down

0 comments on commit 24bfa46

Please sign in to comment.