From 375311091c8a45b5c075b8c3356335069e70df65 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Tue, 18 Dec 2018 02:44:35 -0800 Subject: [PATCH] Decouple from storage type in `YGStyle` Summary: @public The storage format of `YGValue` in `YGStyle` is an implementation detail that is going to change soon. It is only guaranteed to be assignable from, and castable to `YGValue`. Here, we remove tight coupling from the actual implementation in React Native. Reviewed By: shergin Differential Revision: D13465113 fbshipit-source-id: 41dfcb90c2a1cd825a6732854bf84d4c3318d835 --- ReactCommon/fabric/components/view/conversions.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/ReactCommon/fabric/components/view/conversions.h b/ReactCommon/fabric/components/view/conversions.h index 19ab084f273..630b88417cb 100644 --- a/ReactCommon/fabric/components/view/conversions.h +++ b/ReactCommon/fabric/components/view/conversions.h @@ -60,7 +60,7 @@ inline YGValue yogaStyleValueFromFloat(const Float &value) { } inline folly::Optional optionalFloatFromYogaValue( - const YGValue &value, + const YGValue value, folly::Optional base = {}) { switch (value.unit) { case YGUnitUndefined: @@ -297,7 +297,9 @@ inline void fromDynamic(const folly::dynamic &value, YGDisplay &result) { abort(); } -inline void fromDynamic(const folly::dynamic &value, YGValue &result) { +inline void fromDynamic( + const folly::dynamic &value, + decltype(YGStyle{}.margin[0]) /* type is subject to change */ &result) { if (value.isNumber()) { result = yogaStyleValueFromFloat(value.asDouble()); return; @@ -308,12 +310,12 @@ inline void fromDynamic(const folly::dynamic &value, YGValue &result) { return; } else { if (stringValue.back() == '%') { - result = { + result = YGValue{ folly::to(stringValue.substr(0, stringValue.length() - 1)), YGUnitPercent}; return; } else { - result = {folly::to(stringValue), YGUnitPoint}; + result = YGValue{folly::to(stringValue), YGUnitPoint}; return; } } @@ -602,10 +604,11 @@ inline std::string toString(const YGStyle::Edges &value) { auto separator = std::string{", "}; for (auto i = 0; i < YGEdgeCount; i++) { - if (value[i].unit == YGUnitUndefined) { + YGValue v = value[i]; + if (v.unit == YGUnitUndefined) { continue; } - result += names[i] + ": " + toString(value[i]) + separator; + result += names[i] + ": " + toString(v) + separator; } if (!result.empty()) {