Skip to content

Commit

Permalink
Fabric: Complete implementation of layoutMetricsFromYogaNode
Browse files Browse the repository at this point in the history
Summary: That was simply incomplete.

Reviewed By: fkgozali

Differential Revision: D7330336

fbshipit-source-id: c495c7f61d8e551fa963bfa6cc0408343eb8439b
  • Loading branch information
shergin authored and facebook-github-bot committed Mar 20, 2018
1 parent a5a3456 commit ff288b7
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ namespace facebook {
namespace react {

Float fabricFloatFromYogaFloat(float value) {
if (value == YGUndefined) {
return Undefined;
}

return (Float)value;
}

float yogaFloatFromFabricFloat(Float value) {
if (value == Undefined) {
return YGUndefined;
}

return (float)value;
}

Expand All @@ -44,11 +52,35 @@ LayoutMetrics layoutMetricsFromYogaNode(YGNode &yogaNode) {
YGLayout layout = yogaNode.getLayout();

layoutMetrics.frame = Rect {
Point {fabricFloatFromYogaFloat(layout.position[0]), fabricFloatFromYogaFloat(layout.position[1])},
Size {fabricFloatFromYogaFloat(layout.dimensions[0]), fabricFloatFromYogaFloat(layout.dimensions[1])}
Point {
fabricFloatFromYogaFloat(layout.position[YGEdgeLeft]),
fabricFloatFromYogaFloat(layout.position[YGEdgeTop])
},
Size {
fabricFloatFromYogaFloat(layout.dimensions[YGDimensionWidth]),
fabricFloatFromYogaFloat(layout.dimensions[YGDimensionHeight])
}
};

// FIXME: Add more.
layoutMetrics.borderWidth = EdgeInsets {
fabricFloatFromYogaFloat(layout.border[YGEdgeLeft]),
fabricFloatFromYogaFloat(layout.border[YGEdgeTop]),
fabricFloatFromYogaFloat(layout.border[YGEdgeRight]),
fabricFloatFromYogaFloat(layout.border[YGEdgeBottom])
};

layoutMetrics.contentInsets = EdgeInsets {
fabricFloatFromYogaFloat(layout.border[YGEdgeLeft] + layout.padding[YGEdgeLeft]),
fabricFloatFromYogaFloat(layout.border[YGEdgeTop] + layout.padding[YGEdgeTop]),
fabricFloatFromYogaFloat(layout.border[YGEdgeRight] + layout.padding[YGEdgeRight]),
fabricFloatFromYogaFloat(layout.border[YGEdgeBottom] + layout.padding[YGEdgeBottom])
};

layoutMetrics.displayType =
yogaNode.getStyle().display == YGDisplayNone ? None : Flex;

layoutMetrics.layoutDirection =
layout.direction == YGDirectionRTL ? RightToLeft : LeftToRight;

return layoutMetrics;
}
Expand Down

0 comments on commit ff288b7

Please sign in to comment.