diff --git a/ReactCommon/fabric/graphics/Geometry.h b/ReactCommon/fabric/graphics/Geometry.h index 9c198c4be..e44dba31e 100644 --- a/ReactCommon/fabric/graphics/Geometry.h +++ b/ReactCommon/fabric/graphics/Geometry.h @@ -125,5 +125,25 @@ struct EdgeInsets { } }; +/* + * CornerInsets + */ +struct CornerInsets { + Float topLeft {0}; + Float topRight {0}; + Float bottomLeft {0}; + Float bottomRight {0}; + + bool operator ==(const CornerInsets& rhs) const { + return + std::tie(this->topLeft, this->topRight, this->bottomLeft, this->bottomRight) == + std::tie(rhs.topLeft, rhs.topRight, rhs.bottomLeft, rhs.bottomRight); + } + + bool operator !=(const CornerInsets& rhs) const { + return !(*this == rhs); + } +}; + } // namespace react } // namespace facebook diff --git a/ReactCommon/fabric/graphics/conversions.h b/ReactCommon/fabric/graphics/conversions.h index 061725c01..7c79d0b38 100644 --- a/ReactCommon/fabric/graphics/conversions.h +++ b/ReactCommon/fabric/graphics/conversions.h @@ -105,6 +105,28 @@ inline void fromDynamic(const folly::dynamic &value, EdgeInsets &result) { abort(); } +inline void fromDynamic(const folly::dynamic &value, CornerInsets &result) { + if (value.isObject()) { + result = CornerInsets { + (Float)value["topLeft"].asDouble(), + (Float)value["topRight"].asDouble(), + (Float)value["bottomLeft"].asDouble(), + (Float)value["bottomRight"].asDouble() + }; + return; + } + if (value.isArray()) { + result = CornerInsets { + (Float)value[0].asDouble(), + (Float)value[1].asDouble(), + (Float)value[2].asDouble(), + (Float)value[3].asDouble() + }; + return; + } + abort(); +} + inline std::string toString(const Point &point) { return "{" + folly::to(point.x) + ", " + folly::to(point.y) + "}"; } @@ -125,5 +147,13 @@ inline std::string toString(const EdgeInsets &edgeInsets) { folly::to(edgeInsets.bottom) + "}"; } +inline std::string toString(const CornerInsets &cornerInsets) { + return "{" + + folly::to(cornerInsets.topLeft) + ", " + + folly::to(cornerInsets.topRight) + ", " + + folly::to(cornerInsets.bottomLeft) + ", " + + folly::to(cornerInsets.bottomRight) + "}"; +} + } // namespace react } // namespace facebook