Skip to content

Commit f66f52d

Browse files
Make YogaLayout create programmatically. Make YogaNode of YogaLayout …
Summary: Make YogaLayout constructible programmatically. Make YogaLayout's YogaNode accessible from outside. Closes #436 Differential Revision: D4850451 Pulled By: emilsjolander fbshipit-source-id: 2821a6ef4160854244c0227a3c4c96369f7b2e64
1 parent 49e1873 commit f66f52d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

android/src/main/java/com/facebook/yoga/android/YogaLayout.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,20 @@ public YogaLayout(Context context, AttributeSet attrs, int defStyleAttr) {
9191
mYogaNode.setData(this);
9292
mYogaNode.setMeasureFunction(new ViewMeasureFunction());
9393

94-
final LayoutParams layoutParams = new LayoutParams(context, attrs);
94+
LayoutParams layoutParams = null;
95+
if (attrs != null) {
96+
layoutParams = new LayoutParams(context, attrs);
97+
} else {
98+
layoutParams = (LayoutParams) generateDefaultLayoutParams();
99+
}
95100
applyLayoutParams(layoutParams, mYogaNode, this);
96101
}
97102

98-
YogaNode getYogaNode() {
103+
public YogaNode getYogaNode() {
99104
return mYogaNode;
100105
}
101106

102-
YogaNode getYogaNodeForView(View view) {
107+
public YogaNode getYogaNodeForView(View view) {
103108
return mYogaNodes.get(view);
104109
}
105110

@@ -154,7 +159,11 @@ public void addView(View child, int index, ViewGroup.LayoutParams params) {
154159
if (child instanceof YogaLayout) {
155160
childNode = ((YogaLayout) child).getYogaNode();
156161
} else {
157-
childNode = new YogaNode();
162+
if(mYogaNodes.containsKey(child)) {
163+
childNode = mYogaNodes.get(child);
164+
} else {
165+
childNode = new YogaNode();
166+
}
158167

159168
childNode.setData(child);
160169
childNode.setMeasureFunction(new ViewMeasureFunction());

0 commit comments

Comments
 (0)