From cea862a6bf9665db1ce53f154a5a80bd5f939cf5 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 --- yoga/YGStyle.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yoga/YGStyle.h b/yoga/YGStyle.h index dd946832..953c6ae8 100644 --- a/yoga/YGStyle.h +++ b/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);