From f180300606b1ae894c26721889670c23594eee25 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 21 May 2018 19:59:05 -0700 Subject: [PATCH] Fabric: Support for object notation in dynamic-to-Point/Size/Edges converstions Summary: Trivial. Reviewed By: fkgozali Differential Revision: D8086650 fbshipit-source-id: 0850c799811f7cda2dd6786aada6222dcc28a3e4 --- ReactCommon/fabric/graphics/conversions.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/ReactCommon/fabric/graphics/conversions.h b/ReactCommon/fabric/graphics/conversions.h index 2ca159c73..061725c01 100644 --- a/ReactCommon/fabric/graphics/conversions.h +++ b/ReactCommon/fabric/graphics/conversions.h @@ -60,6 +60,10 @@ inline void fromDynamic(const folly::dynamic &value, Float &result) { } inline void fromDynamic(const folly::dynamic &value, Point &result) { + if (value.isObject()) { + result = Point {(Float)value["x"].asDouble(), (Float)value["y"].asDouble()}; + return; + } if (value.isArray()) { result = Point {(Float)value[0].asDouble(), (Float)value[1].asDouble()}; return; @@ -68,6 +72,10 @@ inline void fromDynamic(const folly::dynamic &value, Point &result) { } inline void fromDynamic(const folly::dynamic &value, Size &result) { + if (value.isObject()) { + result = Size {(Float)value["width"].asDouble(), (Float)value["height"].asDouble()}; + return; + } if (value.isArray()) { result = Size {(Float)value[0].asDouble(), (Float)value[1].asDouble()}; return; @@ -76,6 +84,15 @@ inline void fromDynamic(const folly::dynamic &value, Size &result) { } inline void fromDynamic(const folly::dynamic &value, EdgeInsets &result) { + if (value.isObject()) { + result = EdgeInsets { + (Float)value["top"].asDouble(), + (Float)value["left"].asDouble(), + (Float)value["bottom"].asDouble(), + (Float)value["right"].asDouble() + }; + return; + } if (value.isArray()) { result = EdgeInsets { (Float)value[0].asDouble(),