Skip to content

Commit

Permalink
Remove yoga::Style::BitfieldRef (facebook#41393)
Browse files Browse the repository at this point in the history
Summary:

X-link: facebook/yoga#1459

Removes the last of the non setter-style style setters.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D51155925
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Nov 28, 2023
1 parent 41e765e commit 18ae3c8
Show file tree
Hide file tree
Showing 11 changed files with 173 additions and 204 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ - (void)setUp
auto &props = *sharedProps;
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(0));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
Expand Down Expand Up @@ -213,7 +213,7 @@ - (void)setUp
auto &props = *sharedProps;
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(30));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
Expand Down Expand Up @@ -257,7 +257,7 @@ - (void)setUp
auto &props = *sharedProps;
props.accessible = true;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(90));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
Expand Down Expand Up @@ -431,7 +431,7 @@ - (void)testEntireParagraphLink
props.accessible = true;
props.accessibilityTraits = AccessibilityTraits::Link;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(0));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(90));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(200));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ void YogaLayoutableShadowNode::setPositionType(
ensureUnsealed();

auto style = yogaNode_.getStyle();
style.positionType() = yoga::scopedEnum(positionType);
style.setPositionType(yoga::scopedEnum(positionType));
yogaNode_.setStyle(style);
yogaNode_.setDirty(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,15 @@ static inline T const getFieldValue(
return defaultValue;
}

#define REBUILD_FIELD_SWITCH_CASE2(field, fieldName) \
case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \
yogaStyle.field() = getFieldValue(context, value, ygDefaults.field()); \
return; \
}

// @lint-ignore CLANGTIDY cppcoreguidelines-macro-usage
#define REBUILD_FIELD_SWITCH_CASE_YSP(field) \
REBUILD_FIELD_SWITCH_CASE2(field, #field)

#define REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(field, setter) \
case CONSTEXPR_RAW_PROPS_KEY_HASH(#field): { \
#define REBUILD_FIELD_SWITCH_CASE2(field, setter, fieldName) \
case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \
yogaStyle.setter(getFieldValue(context, value, ygDefaults.field())); \
return; \
}

#define REBUILD_FIELD_SWITCH_CASE_YSP(field, setter) \
REBUILD_FIELD_SWITCH_CASE2(field, setter, #field)

#define REBUILD_YG_FIELD_SWITCH_CASE_INDEXED(field, setter, index, fieldName) \
case CONSTEXPR_RAW_PROPS_KEY_HASH(fieldName): { \
yogaStyle.setter( \
Expand Down Expand Up @@ -138,22 +131,22 @@ void YogaStylableProps::setProp(
Props::setProp(context, hash, propName, value);

switch (hash) {
REBUILD_FIELD_SWITCH_CASE_YSP(direction);
REBUILD_FIELD_SWITCH_CASE_YSP(flexDirection);
REBUILD_FIELD_SWITCH_CASE_YSP(justifyContent);
REBUILD_FIELD_SWITCH_CASE_YSP(alignContent);
REBUILD_FIELD_SWITCH_CASE_YSP(alignItems);
REBUILD_FIELD_SWITCH_CASE_YSP(alignSelf);
REBUILD_FIELD_SWITCH_CASE_YSP(flexWrap);
REBUILD_FIELD_SWITCH_CASE_YSP(overflow);
REBUILD_FIELD_SWITCH_CASE_YSP(display);
REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(flex, setFlex);
REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(flexGrow, setFlexGrow);
REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(flexShrink, setFlexShrink);
REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(flexBasis, setFlexBasis);
REBUILD_FIELD_SWITCH_CASE2(positionType, "position");
REBUILD_FIELD_SWITCH_CASE_YSP(direction, setDirection);
REBUILD_FIELD_SWITCH_CASE_YSP(flexDirection, setFlexDirection);
REBUILD_FIELD_SWITCH_CASE_YSP(justifyContent, setJustifyContent);
REBUILD_FIELD_SWITCH_CASE_YSP(alignContent, setAlignContent);
REBUILD_FIELD_SWITCH_CASE_YSP(alignItems, setAlignItems);
REBUILD_FIELD_SWITCH_CASE_YSP(alignSelf, setAlignSelf);
REBUILD_FIELD_SWITCH_CASE_YSP(flexWrap, setFlexWrap);
REBUILD_FIELD_SWITCH_CASE_YSP(overflow, setOverflow);
REBUILD_FIELD_SWITCH_CASE_YSP(display, setDisplay);
REBUILD_FIELD_SWITCH_CASE_YSP(flex, setFlex);
REBUILD_FIELD_SWITCH_CASE_YSP(flexGrow, setFlexGrow);
REBUILD_FIELD_SWITCH_CASE_YSP(flexShrink, setFlexShrink);
REBUILD_FIELD_SWITCH_CASE_YSP(flexBasis, setFlexBasis);
REBUILD_FIELD_SWITCH_CASE2(positionType, setPositionType, "position");
REBUILD_FIELD_YG_GUTTER(gap, setGap, "rowGap", "columnGap", "gap");
REBUILD_FIELD_SWITCH_CASE_YSP_SETTER(aspectRatio, setAspectRatio);
REBUILD_FIELD_SWITCH_CASE_YSP(aspectRatio, setAspectRatio);
REBUILD_FIELD_YG_DIMENSION(dimension, setDimension, "width", "height");
REBUILD_FIELD_YG_DIMENSION(
minDimension, setMinDimension, "minWidth", "minHeight");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,62 +23,76 @@ static inline yoga::Style convertRawProp(
const RawProps& rawProps,
const yoga::Style& sourceValue) {
yoga::Style yogaStyle{};
yogaStyle.direction() = convertRawProp(

yogaStyle.setDirection(convertRawProp(
context,
rawProps,
"direction",
sourceValue.direction(),
yogaStyle.direction());
yogaStyle.flexDirection() = convertRawProp(
yogaStyle.direction()));

yogaStyle.setFlexDirection(convertRawProp(
context,
rawProps,
"flexDirection",
sourceValue.flexDirection(),
yogaStyle.flexDirection());
yogaStyle.justifyContent() = convertRawProp(
yogaStyle.flexDirection()));

yogaStyle.setJustifyContent(convertRawProp(
context,
rawProps,
"justifyContent",
sourceValue.justifyContent(),
yogaStyle.justifyContent());
yogaStyle.alignContent() = convertRawProp(
yogaStyle.justifyContent()));

yogaStyle.setAlignContent(convertRawProp(
context,
rawProps,
"alignContent",
sourceValue.alignContent(),
yogaStyle.alignContent());
yogaStyle.alignItems() = convertRawProp(
yogaStyle.alignContent()));

yogaStyle.setAlignItems(convertRawProp(
context,
rawProps,
"alignItems",
sourceValue.alignItems(),
yogaStyle.alignItems());
yogaStyle.alignSelf() = convertRawProp(
yogaStyle.alignItems()));

yogaStyle.setAlignSelf(convertRawProp(
context,
rawProps,
"alignSelf",
sourceValue.alignSelf(),
yogaStyle.alignSelf());
yogaStyle.positionType() = convertRawProp(
yogaStyle.alignSelf()));

yogaStyle.setPositionType(convertRawProp(
context,
rawProps,
"position",
sourceValue.positionType(),
yogaStyle.positionType());
yogaStyle.flexWrap() = convertRawProp(
yogaStyle.positionType()));

yogaStyle.setFlexWrap(convertRawProp(
context,
rawProps,
"flexWrap",
sourceValue.flexWrap(),
yogaStyle.flexWrap());
yogaStyle.overflow() = convertRawProp(
yogaStyle.flexWrap()));

yogaStyle.setOverflow(convertRawProp(
context,
rawProps,
"overflow",
sourceValue.overflow(),
yogaStyle.overflow());
yogaStyle.display() = convertRawProp(
context, rawProps, "display", sourceValue.display(), yogaStyle.display());
yogaStyle.overflow()));

yogaStyle.setDisplay(convertRawProp(
context,
rawProps,
"display",
sourceValue.display(),
yogaStyle.display()));

yogaStyle.setFlex(convertRawProp(
context, rawProps, "flex", sourceValue.flex(), yogaStyle.flex()));
Expand Down Expand Up @@ -463,6 +477,7 @@ static inline yoga::Style convertRawProp(
"width",
sourceValue.dimension(yoga::Dimension::Width),
{}));

yogaStyle.setDimension(
yoga::Dimension::Height,
convertRawProp(
Expand All @@ -480,6 +495,7 @@ static inline yoga::Style convertRawProp(
"minWidth",
sourceValue.minDimension(yoga::Dimension::Width),
{}));

yogaStyle.setMinDimension(
yoga::Dimension::Height,
convertRawProp(
Expand All @@ -497,6 +513,7 @@ static inline yoga::Style convertRawProp(
"maxWidth",
sourceValue.maxDimension(yoga::Dimension::Width),
{}));

yogaStyle.setMaxDimension(
yoga::Dimension::Height,
convertRawProp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class LayoutTest : public ::testing::Test {
auto sharedProps = std::make_shared<ViewShadowNodeProps>();
auto &props = *sharedProps;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(50));
yogaStyle.setDimension(yoga::Dimension::Height, yoga::value::points(50));
return sharedProps;
Expand All @@ -102,7 +102,7 @@ class LayoutTest : public ::testing::Test {
auto sharedProps = std::make_shared<ViewShadowNodeProps>();
auto &props = *sharedProps;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(10));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(10));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(30));
Expand Down Expand Up @@ -132,10 +132,10 @@ class LayoutTest : public ::testing::Test {
auto &yogaStyle = props.yogaStyle;

if (testCase == CLIPPING) {
yogaStyle.overflow() = yoga::Overflow::Hidden;
yogaStyle.setOverflow(yoga::Overflow::Hidden);
}

yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(10));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(10));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(110));
Expand All @@ -150,7 +150,7 @@ class LayoutTest : public ::testing::Test {
auto sharedProps = std::make_shared<ViewShadowNodeProps>();
auto &props = *sharedProps;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(70));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(-50));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(30));
Expand All @@ -165,7 +165,7 @@ class LayoutTest : public ::testing::Test {
auto sharedProps = std::make_shared<ViewShadowNodeProps>();
auto &props = *sharedProps;
auto &yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
yogaStyle.setPosition(yoga::Edge::Left, yoga::value::points(-60));
yogaStyle.setPosition(yoga::Edge::Top, yoga::value::points(50));
yogaStyle.setDimension(yoga::Dimension::Width, yoga::value::points(70));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class YogaDirtyFlagTest : public ::testing::Test {
auto &props = *mutableViewProps;
props.nativeId = "native Id";
props.opacity = 0.5;
props.yogaStyle.alignContent() = yoga::Align::Baseline;
props.yogaStyle.flexDirection() = yoga::FlexDirection::RowReverse;
props.yogaStyle.setAlignContent(yoga::Align::Baseline);
props.yogaStyle.setFlexDirection(yoga::FlexDirection::RowReverse);
return mutableViewProps;
}),
Element<ViewShadowNode>()
Expand Down Expand Up @@ -136,8 +136,8 @@ TEST_F(YogaDirtyFlagTest, changingLayoutSubPropsMustDirtyYogaNode) {
auto viewProps = std::make_shared<ViewShadowNodeProps>();
auto& props = *viewProps;

props.yogaStyle.alignContent() = yoga::Align::Baseline;
props.yogaStyle.display() = yoga::Display::None;
props.yogaStyle.setAlignContent(yoga::Align::Baseline);
props.yogaStyle.setDisplay(yoga::Display::None);

return oldShadowNode.clone(ShadowNodeFragment{viewProps});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ TEST(FindNodeAtPointTest, overlappingViewsWithZIndex) {
auto sharedProps = std::make_shared<ViewShadowNodeProps>();
sharedProps->zIndex = 1;
auto &yogaStyle = sharedProps->yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
return sharedProps;
})
.finalize([](ViewShadowNode &shadowNode){
Expand Down
Loading

0 comments on commit 18ae3c8

Please sign in to comment.