From 110a382b5954bdab17a4947cc99ab5e776f69606 Mon Sep 17 00:00:00 2001 From: David Aurelio Date: Mon, 29 Apr 2019 09:18:57 -0700 Subject: [PATCH] Expose the value type used by `YGStyle` as `ValueRepr` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: @public Adds `YGStyle::ValueRepr` to make code depending on the actual type easier to write. So far, we have treated `yoga::detail::CompactValue` as an implementation detail, and that’s what it’s supposed to stay. React Native Fabric has one value conversion overload that depends on that type, though, and used `decltype(YGStyle{}.margin()[0])` until now. That’s problematic for two reasons: - we want to constrain the parameter of `operator[](...)` to enum types, making the `0` unsuitable - we want to return the non-const overload of the operator to return a custom `Ref` type, which is not the type needed by Fabric. Making the storage type explicit allows to write more forward-compatible code. Reviewed By: SidharthGuglani Differential Revision: D15078960 fbshipit-source-id: 932c27ef2f2cdc6ce965b79894268170f0ccdce5 --- ReactCommon/fabric/components/view/conversions.h | 4 +--- ReactCommon/yoga/yoga/YGStyle.h | 6 +++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ReactCommon/fabric/components/view/conversions.h b/ReactCommon/fabric/components/view/conversions.h index 753e2ac7620..c8d9b9a035f 100644 --- a/ReactCommon/fabric/components/view/conversions.h +++ b/ReactCommon/fabric/components/view/conversions.h @@ -302,9 +302,7 @@ inline void fromRawValue(const RawValue &value, YGDisplay &result) { LOG(FATAL) << "Could not parse YGDisplay:" << stringValue; } -inline void fromRawValue( - const RawValue &value, - decltype(YGStyle{}.margin()[0]) /* type is subject to change */ &result) { +inline void fromRawValue(const RawValue &value, YGStyle::ValueRepr &result) { if (value.hasType()) { result = yogaStyleValueFromFloat((Float)value); return; diff --git a/ReactCommon/yoga/yoga/YGStyle.h b/ReactCommon/yoga/yoga/YGStyle.h index dd94683224f..953c6ae8f5c 100644 --- a/ReactCommon/yoga/yoga/YGStyle.h +++ b/ReactCommon/yoga/yoga/YGStyle.h @@ -7,7 +7,7 @@ #pragma once #include #include -#include +#include #include "CompactValue.h" #include "YGEnums.h" #include "YGFloatOptional.h" @@ -171,6 +171,10 @@ private: BITFIELD_ACCESSORS(flexWrap); BITFIELD_ACCESSORS(overflow); BITFIELD_ACCESSORS(display); + +public: + // for library users needing a type + using ValueRepr = std::remove_reference::type; }; bool operator==(const YGStyle& lhs, const YGStyle& rhs);