Skip to content

Commit

Permalink
Remove yoga::Style::BitfieldRef (#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 26, 2023
1 parent 6b53970 commit 02a2ccc
Show file tree
Hide file tree
Showing 10 changed files with 169 additions and 203 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(flex);
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
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 @@ -253,7 +253,7 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.setPadding(yoga::Edge::All, yoga::value::points(42));
yogaStyle.setMargin(yoga::Edge::All, yoga::value::points(42));
yogaStyle.positionType() = yoga::PositionType::Absolute;
yogaStyle.setPositionType(yoga::PositionType::Absolute);
props.shadowRadius = 42;
props.shadowOffset = Size{42, 42};
props.backgroundColor = clearColor();
Expand All @@ -269,7 +269,7 @@ TEST_F(StackingContextTest, mostPropsDoNotForceViewsToMaterialize) {

mutateViewShadowNodeProps_(nodeBBA_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);

props.borderRadii.all = 42;
props.borderColors.all = blackColor();
Expand Down Expand Up @@ -456,7 +456,7 @@ TEST_F(StackingContextTest, somePropsForceViewsToMaterialize2) {

mutateViewShadowNodeProps_(nodeBBB_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 42;
});

Expand Down Expand Up @@ -538,37 +538,37 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) {

mutateViewShadowNodeProps_(nodeAA_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 9001;
});

mutateViewShadowNodeProps_(nodeBA_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 9000;
});

mutateViewShadowNodeProps_(nodeBBA_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 8999;
});

mutateViewShadowNodeProps_(nodeBBB_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 8998;
});

mutateViewShadowNodeProps_(nodeBC_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 8997;
});

mutateViewShadowNodeProps_(nodeBD_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 8996;
});

Expand Down Expand Up @@ -652,7 +652,7 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) {

mutateViewShadowNodeProps_(nodeBB_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Relative;
yogaStyle.setPositionType(yoga::PositionType::Relative);
props.zIndex = 42;
});

Expand Down Expand Up @@ -680,7 +680,7 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) {

mutateViewShadowNodeProps_(nodeBB_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.positionType() = yoga::PositionType::Static;
yogaStyle.setPositionType(yoga::PositionType::Static);
props.zIndex = {};
});

Expand Down Expand Up @@ -764,7 +764,7 @@ TEST_F(StackingContextTest, zIndexAndFlattenedNodes) {

mutateViewShadowNodeProps_(nodeBB_, [](ViewProps& props) {
auto& yogaStyle = props.yogaStyle;
yogaStyle.display() = yoga::Display::None;
yogaStyle.setDisplay(yoga::Display::None);
});

testViewTree_([](const StubViewTree& viewTree) {
Expand Down
Loading

0 comments on commit 02a2ccc

Please sign in to comment.