Remove usage of Dimension arrays and YGDimension as index (#1402)
Summary: Pull Request resolved: https://github.com/facebook/yoga/pull/1402 X-link: https://github.com/facebook/react-native/pull/39567 This change hides away most usages of YGDimension as an index. We do this for a couple reasons: 1. Right now the style interface may return a full array of resolved edge or dimension values, as a CompactValue. As we abstract away from CompactValue, and move towards ValuePool, this will no longer be the internal interface, and cheap to return. We instead change the interface to return a single value at once, which lets us resolve values lazily. 2. As we move internal usage to scoped enums, enums are not implicitly convertible to intergers (broadly a good thing). Hiding the enum as index prevents the need for callers to cast or convert to underlying. Instead of making a new version of `IdxRef` for this, I converted to a more traditional setter. I will be making similar changes later for other styles, when I hide CompactValue from the public interface. To review I would recommend filtering to changes in `xplat`, or viewing this in a single one of the OSS PRs exported. Everything apart from the below 20 files is a mirror. {F1096792573} Changelog: [Internal] Reviewed By: javache Differential Revision: D49362819 fbshipit-source-id: 30d730d78e62f36597d43f477120f65694e51ea3
This commit is contained in:
committed by
Facebook GitHub Bot
parent
81754d8cb2
commit
83705c2942
@@ -280,25 +280,25 @@ class YG_EXPORT Style {
|
||||
return {*this};
|
||||
}
|
||||
|
||||
const Dimensions& dimensions() const {
|
||||
return dimensions_;
|
||||
CompactValue dimension(YGDimension axis) const {
|
||||
return dimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::dimensions_> dimensions() {
|
||||
return {*this};
|
||||
void setDimension(YGDimension axis, CompactValue value) {
|
||||
dimensions_[axis] = value;
|
||||
}
|
||||
|
||||
const Dimensions& minDimensions() const {
|
||||
return minDimensions_;
|
||||
CompactValue minDimension(YGDimension axis) const {
|
||||
return minDimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::minDimensions_> minDimensions() {
|
||||
return {*this};
|
||||
void setMinDimension(YGDimension axis, CompactValue value) {
|
||||
minDimensions_[axis] = value;
|
||||
}
|
||||
|
||||
const Dimensions& maxDimensions() const {
|
||||
return maxDimensions_;
|
||||
CompactValue maxDimension(YGDimension axis) const {
|
||||
return maxDimensions_[axis];
|
||||
}
|
||||
IdxRef<YGDimension, &Style::maxDimensions_> maxDimensions() {
|
||||
return {*this};
|
||||
void setMaxDimension(YGDimension axis, CompactValue value) {
|
||||
maxDimensions_[axis] = value;
|
||||
}
|
||||
|
||||
// Yoga specific properties, not compatible with flexbox specification
|
||||
@@ -308,10 +308,26 @@ class YG_EXPORT Style {
|
||||
Ref<FloatOptional, &Style::aspectRatio_> aspectRatio() {
|
||||
return {*this};
|
||||
}
|
||||
|
||||
bool operator==(const Style& other) const {
|
||||
return flags == other.flags && inexactEquals(flex_, other.flex_) &&
|
||||
inexactEquals(flexGrow_, other.flexGrow_) &&
|
||||
inexactEquals(flexShrink_, other.flexShrink_) &&
|
||||
inexactEquals(flexBasis_, other.flexBasis_) &&
|
||||
inexactEquals(margin_, other.margin_) &&
|
||||
inexactEquals(position_, other.position_) &&
|
||||
inexactEquals(padding_, other.padding_) &&
|
||||
inexactEquals(border_, other.border_) &&
|
||||
inexactEquals(gap_, other.gap_) &&
|
||||
inexactEquals(dimensions_, other.dimensions_) &&
|
||||
inexactEquals(minDimensions_, other.minDimensions_) &&
|
||||
inexactEquals(maxDimensions_, other.maxDimensions_) &&
|
||||
inexactEquals(aspectRatio_, other.aspectRatio_);
|
||||
}
|
||||
|
||||
bool operator!=(const Style& other) const {
|
||||
return !(*this == other);
|
||||
}
|
||||
};
|
||||
|
||||
YG_EXPORT bool operator==(const Style& lhs, const Style& rhs);
|
||||
YG_EXPORT inline bool operator!=(const Style& lhs, const Style& rhs) {
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
} // namespace facebook::yoga
|
||||
|
Reference in New Issue
Block a user