Fabric: Using YGNodeLayoutGet* family functions to access Yoga layout

Summary:
... instead of using direction access to `ygNode.getLayout()` object.
Suddenly, YGLayout object that YGNode exposes contains unresolved/directional-unaware styles. To get resolved directional-aware styles we have to use functions from Yoga.h.
I am not happy with this solution, I will try to implement something like `ygNode.getResolvedLayout()` and use that instead.

This change fixes strange missing horizontal padding around some views.

Reviewed By: mdvacca

Differential Revision: D10112049

fbshipit-source-id: 4b6ef39d8dd34e78a4592962e8af4eeaa5028768
This commit is contained in:
Valentin Shergin 2018-09-28 14:46:28 -07:00 committed by Facebook Github Bot
parent 97f0e43710
commit 9edf63534e
1 changed files with 13 additions and 14 deletions

View File

@ -73,38 +73,37 @@ inline folly::Optional<Float> optionalFloatFromYogaValue(const YGValue &value, f
inline LayoutMetrics layoutMetricsFromYogaNode(YGNode &yogaNode) {
auto layoutMetrics = LayoutMetrics {};
auto layout = yogaNode.getLayout();
layoutMetrics.frame = Rect {
Point {
floatFromYogaFloat(layout.position[YGEdgeLeft]),
floatFromYogaFloat(layout.position[YGEdgeTop])
floatFromYogaFloat(YGNodeLayoutGetLeft(&yogaNode)),
floatFromYogaFloat(YGNodeLayoutGetTop(&yogaNode))
},
Size {
floatFromYogaFloat(layout.dimensions[YGDimensionWidth]),
floatFromYogaFloat(layout.dimensions[YGDimensionHeight])
floatFromYogaFloat(YGNodeLayoutGetWidth(&yogaNode)),
floatFromYogaFloat(YGNodeLayoutGetHeight(&yogaNode))
}
};
layoutMetrics.borderWidth = EdgeInsets {
floatFromYogaFloat(layout.border[YGEdgeLeft]),
floatFromYogaFloat(layout.border[YGEdgeTop]),
floatFromYogaFloat(layout.border[YGEdgeRight]),
floatFromYogaFloat(layout.border[YGEdgeBottom])
floatFromYogaFloat(YGNodeLayoutGetBorder(&yogaNode, YGEdgeLeft)),
floatFromYogaFloat(YGNodeLayoutGetBorder(&yogaNode, YGEdgeTop)),
floatFromYogaFloat(YGNodeLayoutGetBorder(&yogaNode, YGEdgeRight)),
floatFromYogaFloat(YGNodeLayoutGetBorder(&yogaNode, YGEdgeBottom))
};
layoutMetrics.contentInsets = EdgeInsets {
floatFromYogaFloat(layout.border[YGEdgeLeft] + layout.padding[YGEdgeLeft]),
floatFromYogaFloat(layout.border[YGEdgeTop] + layout.padding[YGEdgeTop]),
floatFromYogaFloat(layout.border[YGEdgeRight] + layout.padding[YGEdgeRight]),
floatFromYogaFloat(layout.border[YGEdgeBottom] + layout.padding[YGEdgeBottom])
layoutMetrics.borderWidth.left + floatFromYogaFloat(YGNodeLayoutGetPadding(&yogaNode, YGEdgeLeft)),
layoutMetrics.borderWidth.top + floatFromYogaFloat(YGNodeLayoutGetPadding(&yogaNode, YGEdgeTop)),
layoutMetrics.borderWidth.right + floatFromYogaFloat(YGNodeLayoutGetPadding(&yogaNode, YGEdgeRight)),
layoutMetrics.borderWidth.bottom + floatFromYogaFloat(YGNodeLayoutGetPadding(&yogaNode, YGEdgeBottom))
};
layoutMetrics.displayType =
yogaNode.getStyle().display == YGDisplayNone ? DisplayType::None : DisplayType::Flex;
layoutMetrics.layoutDirection =
layout.direction == YGDirectionRTL ? LayoutDirection::RightToLeft : LayoutDirection::LeftToRight;
YGNodeLayoutGetDirection(&yogaNode) == YGDirectionRTL ? LayoutDirection::RightToLeft : LayoutDirection::LeftToRight;
return layoutMetrics;
}