in litho-core/src/main/java/com/facebook/litho/LithoNode.java [1131:1222]
YogaLayoutProps writeToYogaNode(final YogaNode node) {
final YogaLayoutProps writer = createYogaNodeWriter(node);
// Apply the extra layout props
if (mLayoutDirection != null) {
node.setDirection(mLayoutDirection);
}
if (mFlexDirection != null) {
node.setFlexDirection(mFlexDirection);
}
if (mJustifyContent != null) {
node.setJustifyContent(mJustifyContent);
}
if (mAlignContent != null) {
node.setAlignContent(mAlignContent);
}
if (mAlignItems != null) {
node.setAlignItems(mAlignItems);
}
if (mYogaWrap != null) {
node.setWrap(mYogaWrap);
}
if (mYogaMeasureFunction != null) {
node.setMeasureFunction(mYogaMeasureFunction);
}
// Apply the layout props from the components to the YogaNode
for (ScopedComponentInfo info : mScopedComponentInfos) {
final Component component = info.getComponent();
// If a NestedTreeHolder is set then transfer its resolved props into this LithoNode.
if (mNestedTreeHolder != null && isLayoutSpecWithSizeSpec(component)) {
mNestedTreeHolder.transferInto(this);
if (mBackground != null) {
setPaddingFromDrawable(writer, mBackground);
}
} else {
final CommonProps props = component.getCommonProps();
if (props != null) {
final int styleAttr = props.getDefStyleAttr();
final int styleRes = props.getDefStyleRes();
if (styleAttr != 0 || styleRes != 0) {
final Context context = getTailComponentContext().getAndroidContext();
final TypedArray a =
context.obtainStyledAttributes(
null, com.facebook.litho.R.styleable.ComponentLayout, styleAttr, styleRes);
applyLayoutStyleAttributes(writer, a);
a.recycle();
}
// Set the padding from the background
final Drawable background = props.getBackground();
if (background != null) {
setPaddingFromDrawable(writer, background);
}
// Copy the layout props into this LithoNode.
props.copyLayoutProps(writer);
}
}
}
// Apply the border widths
if ((mPrivateFlags & PFLAG_BORDER_IS_SET) != 0L) {
for (int i = 0, length = mBorderEdgeWidths.length; i < length; ++i) {
writer.setBorderWidth(Border.edgeFromIndex(i), mBorderEdgeWidths[i]);
}
}
// Maybe apply the padding if parent is a Nested Tree Holder
if (mNestedPaddingEdges != null) {
for (int i = 0; i < Edges.EDGES_LENGTH; i++) {
float value = mNestedPaddingEdges.getRaw(i);
if (!YogaConstants.isUndefined(value)) {
final YogaEdge edge = YogaEdge.fromInt(i);
if (mNestedIsPaddingPercent != null && mNestedIsPaddingPercent[edge.intValue()]) {
writer.paddingPercent(edge, value);
} else {
writer.paddingPx(edge, (int) value);
}
}
}
}
if (mDebugLayoutProps != null) {
mDebugLayoutProps.copyInto(writer);
}
mIsPaddingSet = writer.isPaddingSet;
return writer;
}