From f2da2d1963ffac05319aebc03f2d3985dd636c1c Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 15 Oct 2018 23:23:35 -0700 Subject: [PATCH] Fabric: Proxying `LayoutConstraints::direction` down to RootNode's styles Summary: Trivial. We have to proxy layout directions as well as min and max sizes to RootNode's Props to properly communicate the constrains to Yoga. Reviewed By: sahrens Differential Revision: D10387798 fbshipit-source-id: a02ec0a20b3ef28f6230738e5b3a4a2b0b8e0961 --- ReactCommon/fabric/components/root/RootProps.cpp | 3 +++ ReactCommon/fabric/components/view/conversions.h | 11 +++++++++++ ReactCommon/fabric/core/layout/LayoutConstraints.h | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ReactCommon/fabric/components/root/RootProps.cpp b/ReactCommon/fabric/components/root/RootProps.cpp index 32cab81aa..d30da924e 100644 --- a/ReactCommon/fabric/components/root/RootProps.cpp +++ b/ReactCommon/fabric/components/root/RootProps.cpp @@ -26,6 +26,9 @@ static YGStyle yogaStyleFromLayoutConstraints( yogaStyle.maxDimensions[YGDimensionHeight] = yogaStyleValueFromFloat(layoutConstraints.maximumSize.height); + yogaStyle.direction = + yogaDirectionFromLayoutDirection(layoutConstraints.layoutDirection); + return yogaStyle; } diff --git a/ReactCommon/fabric/components/view/conversions.h b/ReactCommon/fabric/components/view/conversions.h index 707a4622f..0b541379e 100644 --- a/ReactCommon/fabric/components/view/conversions.h +++ b/ReactCommon/fabric/components/view/conversions.h @@ -113,6 +113,17 @@ inline LayoutMetrics layoutMetricsFromYogaNode(YGNode &yogaNode) { return layoutMetrics; } +inline YGDirection yogaDirectionFromLayoutDirection(LayoutDirection direction) { + switch (direction) { + case LayoutDirection::Undefined: + return YGDirectionInherit; + case LayoutDirection::LeftToRight: + return YGDirectionLTR; + case LayoutDirection::RightToLeft: + return YGDirectionRTL; + } +} + inline void fromDynamic(const folly::dynamic &value, YGDirection &result) { assert(value.isString()); auto stringValue = value.asString(); diff --git a/ReactCommon/fabric/core/layout/LayoutConstraints.h b/ReactCommon/fabric/core/layout/LayoutConstraints.h index f93017363..33607c300 100644 --- a/ReactCommon/fabric/core/layout/LayoutConstraints.h +++ b/ReactCommon/fabric/core/layout/LayoutConstraints.h @@ -19,7 +19,7 @@ namespace react { struct LayoutConstraints { Size minimumSize{0, 0}; Size maximumSize{kFloatUndefined, kFloatUndefined}; - LayoutDirection layoutDirection; + LayoutDirection layoutDirection{LayoutDirection::Undefined}; }; } // namespace react