Remove yoga::Style::Ref (#1462)

Summary:
Pull Request resolved: https://github.com/facebook/yoga/pull/1462

X-link: https://github.com/facebook/react-native/pull/41389

Moves the last usages of `yoga::Style::Ref` to setters.

Changelog: [Internal]

Reviewed By: joevilches

Differential Revision: D51154501

fbshipit-source-id: 52dbca7a76de500a8841387eb59fded463864de7
This commit is contained in:
Nick Gerleman
2023-11-27 21:20:20 -08:00
committed by Facebook GitHub Bot
parent 325ccea068
commit ed6e91479c
2 changed files with 31 additions and 35 deletions

View File

@@ -35,6 +35,15 @@ void updateStyle(YGNodeRef node, Ref (Style::*prop)(), ValueT value) {
[prop](Style& s, ValueT x) { (s.*prop)() = x; }); [prop](Style& s, ValueT x) { (s.*prop)() = x; });
} }
template <auto GetterT, auto SetterT, typename ValueT>
void updateStyle(YGNodeRef node, ValueT value) {
updateStyle(
resolveRef(node),
value,
[](Style& s, ValueT x) { return (s.*GetterT)() != x; },
[](Style& s, ValueT x) { (s.*SetterT)(x); });
}
template <auto GetterT, auto SetterT, typename IdxT, typename ValueT> template <auto GetterT, auto SetterT, typename IdxT, typename ValueT>
void updateIndexedStyleProp(YGNodeRef node, IdxT idx, ValueT value) { void updateIndexedStyleProp(YGNodeRef node, IdxT idx, ValueT value) {
updateStyle( updateStyle(
@@ -162,7 +171,7 @@ YGDisplay YGNodeStyleGetDisplay(const YGNodeConstRef node) {
} }
void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) { void YGNodeStyleSetFlex(const YGNodeRef node, const float flex) {
updateStyle<MSVC_HINT(flex)>(node, &Style::flex, FloatOptional{flex}); updateStyle<&Style::flex, &Style::setFlex>(node, FloatOptional{flex});
} }
float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) { float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
@@ -173,8 +182,8 @@ float YGNodeStyleGetFlex(const YGNodeConstRef nodeRef) {
} }
void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) { void YGNodeStyleSetFlexGrow(const YGNodeRef node, const float flexGrow) {
updateStyle<MSVC_HINT(flexGrow)>( updateStyle<&Style::flexGrow, &Style::setFlexGrow>(
node, &Style::flexGrow, FloatOptional{flexGrow}); node, FloatOptional{flexGrow});
} }
float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) { float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
@@ -185,8 +194,8 @@ float YGNodeStyleGetFlexGrow(const YGNodeConstRef nodeRef) {
} }
void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) { void YGNodeStyleSetFlexShrink(const YGNodeRef node, const float flexShrink) {
updateStyle<MSVC_HINT(flexShrink)>( updateStyle<&Style::flexShrink, &Style::setFlexShrink>(
node, &Style::flexShrink, FloatOptional{flexShrink}); node, FloatOptional{flexShrink});
} }
float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) { float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
@@ -198,19 +207,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
} }
void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) { void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
updateStyle<MSVC_HINT(flexBasis)>( updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, &Style::flexBasis, value::points(flexBasis)); node, value::points(flexBasis));
} }
void YGNodeStyleSetFlexBasisPercent( void YGNodeStyleSetFlexBasisPercent(
const YGNodeRef node, const YGNodeRef node,
const float flexBasisPercent) { const float flexBasisPercent) {
updateStyle<MSVC_HINT(flexBasis)>( updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, &Style::flexBasis, value::percent(flexBasisPercent)); node, value::percent(flexBasisPercent));
} }
void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) { void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
updateStyle<MSVC_HINT(flexBasis)>(node, &Style::flexBasis, value::ofAuto()); updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto());
} }
YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) { YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
@@ -303,8 +312,8 @@ float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
} }
void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) { void YGNodeStyleSetAspectRatio(const YGNodeRef node, const float aspectRatio) {
updateStyle<MSVC_HINT(aspectRatio)>( updateStyle<&Style::aspectRatio, &Style::setAspectRatio>(
node, &Style::aspectRatio, FloatOptional{aspectRatio}); node, FloatOptional{aspectRatio});
} }
float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) { float YGNodeStyleGetAspectRatio(const YGNodeConstRef node) {

View File

@@ -68,18 +68,6 @@ class YG_EXPORT Style {
} }
}; };
template <typename T, T Style::*Prop>
struct Ref {
Style& style;
operator T() const {
return style.*Prop;
}
Ref<T, Prop>& operator=(T value) {
style.*Prop = value;
return *this;
}
};
Style() { Style() {
alignContent() = Align::FlexStart; alignContent() = Align::FlexStart;
alignItems() = Align::Stretch; alignItems() = Align::Stretch;
@@ -202,29 +190,29 @@ class YG_EXPORT Style {
FloatOptional flex() const { FloatOptional flex() const {
return flex_; return flex_;
} }
Ref<FloatOptional, &Style::flex_> flex() { void setFlex(FloatOptional value) {
return {*this}; flex_ = value;
} }
FloatOptional flexGrow() const { FloatOptional flexGrow() const {
return flexGrow_; return flexGrow_;
} }
Ref<FloatOptional, &Style::flexGrow_> flexGrow() { void setFlexGrow(FloatOptional value) {
return {*this}; flexGrow_ = value;
} }
FloatOptional flexShrink() const { FloatOptional flexShrink() const {
return flexShrink_; return flexShrink_;
} }
Ref<FloatOptional, &Style::flexShrink_> flexShrink() { void setFlexShrink(FloatOptional value) {
return {*this}; flexShrink_ = value;
} }
Style::Length flexBasis() const { Style::Length flexBasis() const {
return flexBasis_; return flexBasis_;
} }
Ref<Style::Length, &Style::flexBasis_> flexBasis() { void setFlexBasis(Style::Length value) {
return {*this}; flexBasis_ = value;
} }
Style::Length margin(Edge edge) const { Style::Length margin(Edge edge) const {
@@ -283,12 +271,11 @@ class YG_EXPORT Style {
maxDimensions_[yoga::to_underlying(axis)] = value; maxDimensions_[yoga::to_underlying(axis)] = value;
} }
// Yoga specific properties, not compatible with flexbox specification
FloatOptional aspectRatio() const { FloatOptional aspectRatio() const {
return aspectRatio_; return aspectRatio_;
} }
Ref<FloatOptional, &Style::aspectRatio_> aspectRatio() { void setAspectRatio(FloatOptional value) {
return {*this}; aspectRatio_ = value;
} }
Length resolveColumnGap() const { Length resolveColumnGap() const {