From ff288b7416977d81ac442fd9fbf210b6f2b85e31 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 19 Mar 2018 16:51:32 -0700 Subject: [PATCH] Fabric: Complete implementation of `layoutMetricsFromYogaNode` Summary: That was simply incomplete. Reviewed By: fkgozali Differential Revision: D7330336 fbshipit-source-id: c495c7f61d8e551fa963bfa6cc0408343eb8439b --- .../view/yoga/yogaValuesConversions.cpp | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp b/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp index e329b8437..e780d2cec 100644 --- a/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp +++ b/ReactCommon/fabric/view/yoga/yogaValuesConversions.cpp @@ -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; } @@ -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; }