Expose the value type used by YGStyle as ValueRepr

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
This commit is contained in:
David Aurelio
2019-04-29 09:18:57 -07:00
committed by Facebook Github Bot
parent cc02a20c9e
commit cea862a6bf

View File

@@ -7,7 +7,7 @@
#pragma once
#include <algorithm>
#include <array>
#include <initializer_list>
#include <type_traits>
#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<decltype(margin_[0])>::type;
};
bool operator==(const YGStyle& lhs, const YGStyle& rhs);