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 коммит произвёл Facebook Github Bot
Родитель 98eabbe61c
Коммит 110a382b59
2 изменённых файлов: 6 добавлений и 4 удалений

Просмотреть файл

@ -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<Float>()) {
result = yogaStyleValueFromFloat((Float)value);
return;

Просмотреть файл

@ -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);