Skip to content

Commit

Permalink
Sunset the value namespace (#1720)
Browse files Browse the repository at this point in the history
Summary:

X-link: facebook/react-native#46930

This is not really needed anymore, we can just use `StyleLength` statics instead

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63922280
  • Loading branch information
joevilches authored and facebook-github-bot committed Oct 9, 2024
1 parent f6f9d6f commit d523c59
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 95 deletions.
8 changes: 4 additions & 4 deletions tests/StyleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,30 @@ namespace facebook::yoga {

TEST(Style, computed_padding_is_floored) {
yoga::Style style;
style.setPadding(Edge::All, value::points(-1.0f));
style.setPadding(Edge::All, StyleLength::points(-1.0f));
auto paddingStart = style.computeInlineStartPadding(
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
ASSERT_EQ(paddingStart, 0.0f);
}

TEST(Style, computed_border_is_floored) {
yoga::Style style;
style.setBorder(Edge::All, value::points(-1.0f));
style.setBorder(Edge::All, StyleLength::points(-1.0f));
auto borderStart =
style.computeInlineStartBorder(FlexDirection::Row, Direction::LTR);
ASSERT_EQ(borderStart, 0.0f);
}

TEST(Style, computed_gap_is_floored) {
yoga::Style style;
style.setGap(Gutter::Column, value::points(-1.0f));
style.setGap(Gutter::Column, StyleLength::points(-1.0f));
auto gapBetweenColumns = style.computeGapForAxis(FlexDirection::Row, 0.0);
ASSERT_EQ(gapBetweenColumns, 0.0f);
}

TEST(Style, computed_margin_is_not_floored) {
yoga::Style style;
style.setMargin(Edge::All, value::points(-1.0f));
style.setMargin(Edge::All, StyleLength::points(-1.0f));
auto marginStart = style.computeInlineStartMargin(
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
ASSERT_EQ(marginStart, -1.0f);
Expand Down
48 changes: 24 additions & 24 deletions tests/StyleValuePoolTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ TEST(StyleValuePool, undefined_at_init) {

EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined());
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
EXPECT_EQ(pool.getNumber(handle), FloatOptional{});
}

Expand All @@ -25,63 +25,63 @@ TEST(StyleValuePool, auto_at_init) {
auto handle = StyleValueHandle::ofAuto();

EXPECT_TRUE(handle.isAuto());
EXPECT_EQ(pool.getLength(handle), value::ofAuto());
EXPECT_EQ(pool.getLength(handle), StyleLength::ofAuto());
}

TEST(StyleValuePool, store_small_int_points) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::points(10));
pool.store(handle, StyleLength::points(10));

EXPECT_EQ(pool.getLength(handle), value::points(10));
EXPECT_EQ(pool.getLength(handle), StyleLength::points(10));
}

TEST(StyleValuePool, store_small_negative_int_points) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::points(-10));
pool.store(handle, StyleLength::points(-10));

EXPECT_EQ(pool.getLength(handle), value::points(-10));
EXPECT_EQ(pool.getLength(handle), StyleLength::points(-10));
}

TEST(StyleValuePool, store_small_int_percent) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::percent(10));
pool.store(handle, StyleLength::percent(10));

EXPECT_EQ(pool.getLength(handle), value::percent(10));
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10));
}

TEST(StyleValuePool, store_large_int_percent) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::percent(262144));
pool.store(handle, StyleLength::percent(262144));

EXPECT_EQ(pool.getLength(handle), value::percent(262144));
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144));
}

TEST(StyleValuePool, store_large_int_after_small_int) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::percent(10));
pool.store(handle, value::percent(262144));
pool.store(handle, StyleLength::percent(10));
pool.store(handle, StyleLength::percent(262144));

EXPECT_EQ(pool.getLength(handle), value::percent(262144));
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144));
}

TEST(StyleValuePool, store_small_int_after_large_int) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::percent(262144));
pool.store(handle, value::percent(10));
pool.store(handle, StyleLength::percent(262144));
pool.store(handle, StyleLength::percent(10));

EXPECT_EQ(pool.getLength(handle), value::percent(10));
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10));
}

TEST(StyleValuePool, store_small_int_number) {
Expand All @@ -97,35 +97,35 @@ TEST(StyleValuePool, store_undefined) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::undefined());
pool.store(handle, StyleLength::undefined());

EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined());
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
}

TEST(StyleValuePool, store_undefined_after_small_int) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::points(10));
pool.store(handle, value::undefined());
pool.store(handle, StyleLength::points(10));
pool.store(handle, StyleLength::undefined());

EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined());
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
}

TEST(StyleValuePool, store_undefined_after_large_int) {
StyleValuePool pool;
StyleValueHandle handle;

pool.store(handle, value::points(262144));
pool.store(handle, value::undefined());
pool.store(handle, StyleLength::points(262144));
pool.store(handle, StyleLength::undefined());

EXPECT_TRUE(handle.isUndefined());
EXPECT_FALSE(handle.isDefined());
EXPECT_EQ(pool.getLength(handle), value::undefined());
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
}

} // namespace facebook::yoga
57 changes: 29 additions & 28 deletions yoga/YGNodeStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {

void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, value::points(flexBasis));
node, StyleLength::points(flexBasis));
}

void YGNodeStyleSetFlexBasisPercent(
const YGNodeRef node,
const float flexBasisPercent) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, value::percent(flexBasisPercent));
node, StyleLength::percent(flexBasisPercent));
}

void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto());
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
node, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
Expand All @@ -197,17 +198,17 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {

void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::points(points));
node, scopedEnum(edge), StyleLength::points(points));
}

void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::percent(percent));
node, scopedEnum(edge), StyleLength::percent(percent));
}

void YGNodeStyleSetPositionAuto(YGNodeRef node, YGEdge edge) {
updateStyle<&Style::position, &Style::setPosition>(
node, scopedEnum(edge), value::ofAuto());
node, scopedEnum(edge), StyleLength::ofAuto());
}

YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {
Expand All @@ -216,17 +217,17 @@ YGValue YGNodeStyleGetPosition(YGNodeConstRef node, YGEdge edge) {

void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::points(points));
node, scopedEnum(edge), StyleLength::points(points));
}

void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::percent(percent));
node, scopedEnum(edge), StyleLength::percent(percent));
}

void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
updateStyle<&Style::margin, &Style::setMargin>(
node, scopedEnum(edge), value::ofAuto());
node, scopedEnum(edge), StyleLength::ofAuto());
}

YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {
Expand All @@ -235,12 +236,12 @@ YGValue YGNodeStyleGetMargin(YGNodeConstRef node, YGEdge edge) {

void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
updateStyle<&Style::padding, &Style::setPadding>(
node, scopedEnum(edge), value::points(points));
node, scopedEnum(edge), StyleLength::points(points));
}

void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
updateStyle<&Style::padding, &Style::setPadding>(
node, scopedEnum(edge), value::percent(percent));
node, scopedEnum(edge), StyleLength::percent(percent));
}

YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
Expand All @@ -252,7 +253,7 @@ void YGNodeStyleSetBorder(
const YGEdge edge,
const float border) {
updateStyle<&Style::border, &Style::setBorder>(
node, scopedEnum(edge), value::points(border));
node, scopedEnum(edge), StyleLength::points(border));
}

float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
Expand All @@ -269,12 +270,12 @@ void YGNodeStyleSetGap(
const YGGutter gutter,
const float gapLength) {
updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::points(gapLength));
node, scopedEnum(gutter), StyleLength::points(gapLength));
}

void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
updateStyle<&Style::gap, &Style::setGap>(
node, scopedEnum(gutter), value::percent(percent));
node, scopedEnum(gutter), StyleLength::percent(percent));
}

float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
Expand Down Expand Up @@ -307,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) {

void YGNodeStyleSetWidth(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::points(points));
node, Dimension::Width, StyleLength::points(points));
}

void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::percent(percent));
node, Dimension::Width, StyleLength::percent(percent));
}

void YGNodeStyleSetWidthAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Width, value::ofAuto());
node, Dimension::Width, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
Expand All @@ -326,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {

void YGNodeStyleSetHeight(YGNodeRef node, float points) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::points(points));
node, Dimension::Height, StyleLength::points(points));
}

void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::percent(percent));
node, Dimension::Height, StyleLength::percent(percent));
}

void YGNodeStyleSetHeightAuto(YGNodeRef node) {
updateStyle<&Style::dimension, &Style::setDimension>(
node, Dimension::Height, value::ofAuto());
node, Dimension::Height, StyleLength::ofAuto());
}

YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
Expand All @@ -345,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {

void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, value::points(minWidth));
node, Dimension::Width, StyleLength::points(minWidth));
}

void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Width, value::percent(minWidth));
node, Dimension::Width, StyleLength::percent(minWidth));
}

YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
Expand All @@ -359,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {

void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, value::points(minHeight));
node, Dimension::Height, StyleLength::points(minHeight));
}

void YGNodeStyleSetMinHeightPercent(
const YGNodeRef node,
const float minHeight) {
updateStyle<&Style::minDimension, &Style::setMinDimension>(
node, Dimension::Height, value::percent(minHeight));
node, Dimension::Height, StyleLength::percent(minHeight));
}

YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
Expand All @@ -375,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {

void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, value::points(maxWidth));
node, Dimension::Width, StyleLength::points(maxWidth));
}

void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Width, value::percent(maxWidth));
node, Dimension::Width, StyleLength::percent(maxWidth));
}

YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
Expand All @@ -389,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {

void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, value::points(maxHeight));
node, Dimension::Height, StyleLength::points(maxHeight));
}

void YGNodeStyleSetMaxHeightPercent(
const YGNodeRef node,
const float maxHeight) {
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
node, Dimension::Height, value::percent(maxHeight));
node, Dimension::Height, StyleLength::percent(maxHeight));
}

YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {
Expand Down
5 changes: 3 additions & 2 deletions yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,10 @@ Style::Length Node::processFlexBasis() const {
return flexBasis;
}
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
return config_->useWebDefaults() ? value::ofAuto() : value::points(0);
return config_->useWebDefaults() ? StyleLength::ofAuto()
: StyleLength::points(0);
}
return value::ofAuto();
return StyleLength::ofAuto();
}

FloatOptional Node::resolveFlexBasis(
Expand Down
2 changes: 1 addition & 1 deletion yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class YG_EXPORT Node : public ::YGNode {
std::vector<Node*> children_;
const Config* config_;
std::array<Style::Length, 2> processedDimensions_{
{value::undefined(), value::undefined()}};
{StyleLength::undefined(), StyleLength::undefined()}};
};

inline Node* resolveRef(const YGNodeRef ref) {
Expand Down
Loading

0 comments on commit d523c59

Please sign in to comment.