Skip to content

Commit 2437d26

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Sunset the value namespace (#1720)
Summary: Pull Request resolved: #1720 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 fbshipit-source-id: cd953bae8e9f68574463eafc49c33c2e85ac1856
1 parent 820a4d5 commit 2437d26

File tree

7 files changed

+65
-95
lines changed

7 files changed

+65
-95
lines changed

tests/StyleTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,30 @@ namespace facebook::yoga {
1212

1313
TEST(Style, computed_padding_is_floored) {
1414
yoga::Style style;
15-
style.setPadding(Edge::All, value::points(-1.0f));
15+
style.setPadding(Edge::All, StyleLength::points(-1.0f));
1616
auto paddingStart = style.computeInlineStartPadding(
1717
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
1818
ASSERT_EQ(paddingStart, 0.0f);
1919
}
2020

2121
TEST(Style, computed_border_is_floored) {
2222
yoga::Style style;
23-
style.setBorder(Edge::All, value::points(-1.0f));
23+
style.setBorder(Edge::All, StyleLength::points(-1.0f));
2424
auto borderStart =
2525
style.computeInlineStartBorder(FlexDirection::Row, Direction::LTR);
2626
ASSERT_EQ(borderStart, 0.0f);
2727
}
2828

2929
TEST(Style, computed_gap_is_floored) {
3030
yoga::Style style;
31-
style.setGap(Gutter::Column, value::points(-1.0f));
31+
style.setGap(Gutter::Column, StyleLength::points(-1.0f));
3232
auto gapBetweenColumns = style.computeGapForAxis(FlexDirection::Row, 0.0);
3333
ASSERT_EQ(gapBetweenColumns, 0.0f);
3434
}
3535

3636
TEST(Style, computed_margin_is_not_floored) {
3737
yoga::Style style;
38-
style.setMargin(Edge::All, value::points(-1.0f));
38+
style.setMargin(Edge::All, StyleLength::points(-1.0f));
3939
auto marginStart = style.computeInlineStartMargin(
4040
FlexDirection::Row, Direction::LTR, 0.0f /*widthSize*/);
4141
ASSERT_EQ(marginStart, -1.0f);

tests/StyleValuePoolTest.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ TEST(StyleValuePool, undefined_at_init) {
1616

1717
EXPECT_TRUE(handle.isUndefined());
1818
EXPECT_FALSE(handle.isDefined());
19-
EXPECT_EQ(pool.getLength(handle), value::undefined());
19+
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
2020
EXPECT_EQ(pool.getNumber(handle), FloatOptional{});
2121
}
2222

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

2727
EXPECT_TRUE(handle.isAuto());
28-
EXPECT_EQ(pool.getLength(handle), value::ofAuto());
28+
EXPECT_EQ(pool.getLength(handle), StyleLength::ofAuto());
2929
}
3030

3131
TEST(StyleValuePool, store_small_int_points) {
3232
StyleValuePool pool;
3333
StyleValueHandle handle;
3434

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

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

4040
TEST(StyleValuePool, store_small_negative_int_points) {
4141
StyleValuePool pool;
4242
StyleValueHandle handle;
4343

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

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

4949
TEST(StyleValuePool, store_small_int_percent) {
5050
StyleValuePool pool;
5151
StyleValueHandle handle;
5252

53-
pool.store(handle, value::percent(10));
53+
pool.store(handle, StyleLength::percent(10));
5454

55-
EXPECT_EQ(pool.getLength(handle), value::percent(10));
55+
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10));
5656
}
5757

5858
TEST(StyleValuePool, store_large_int_percent) {
5959
StyleValuePool pool;
6060
StyleValueHandle handle;
6161

62-
pool.store(handle, value::percent(262144));
62+
pool.store(handle, StyleLength::percent(262144));
6363

64-
EXPECT_EQ(pool.getLength(handle), value::percent(262144));
64+
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144));
6565
}
6666

6767
TEST(StyleValuePool, store_large_int_after_small_int) {
6868
StyleValuePool pool;
6969
StyleValueHandle handle;
7070

71-
pool.store(handle, value::percent(10));
72-
pool.store(handle, value::percent(262144));
71+
pool.store(handle, StyleLength::percent(10));
72+
pool.store(handle, StyleLength::percent(262144));
7373

74-
EXPECT_EQ(pool.getLength(handle), value::percent(262144));
74+
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(262144));
7575
}
7676

7777
TEST(StyleValuePool, store_small_int_after_large_int) {
7878
StyleValuePool pool;
7979
StyleValueHandle handle;
8080

81-
pool.store(handle, value::percent(262144));
82-
pool.store(handle, value::percent(10));
81+
pool.store(handle, StyleLength::percent(262144));
82+
pool.store(handle, StyleLength::percent(10));
8383

84-
EXPECT_EQ(pool.getLength(handle), value::percent(10));
84+
EXPECT_EQ(pool.getLength(handle), StyleLength::percent(10));
8585
}
8686

8787
TEST(StyleValuePool, store_small_int_number) {
@@ -97,35 +97,35 @@ TEST(StyleValuePool, store_undefined) {
9797
StyleValuePool pool;
9898
StyleValueHandle handle;
9999

100-
pool.store(handle, value::undefined());
100+
pool.store(handle, StyleLength::undefined());
101101

102102
EXPECT_TRUE(handle.isUndefined());
103103
EXPECT_FALSE(handle.isDefined());
104-
EXPECT_EQ(pool.getLength(handle), value::undefined());
104+
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
105105
}
106106

107107
TEST(StyleValuePool, store_undefined_after_small_int) {
108108
StyleValuePool pool;
109109
StyleValueHandle handle;
110110

111-
pool.store(handle, value::points(10));
112-
pool.store(handle, value::undefined());
111+
pool.store(handle, StyleLength::points(10));
112+
pool.store(handle, StyleLength::undefined());
113113

114114
EXPECT_TRUE(handle.isUndefined());
115115
EXPECT_FALSE(handle.isDefined());
116-
EXPECT_EQ(pool.getLength(handle), value::undefined());
116+
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
117117
}
118118

119119
TEST(StyleValuePool, store_undefined_after_large_int) {
120120
StyleValuePool pool;
121121
StyleValueHandle handle;
122122

123-
pool.store(handle, value::points(262144));
124-
pool.store(handle, value::undefined());
123+
pool.store(handle, StyleLength::points(262144));
124+
pool.store(handle, StyleLength::undefined());
125125

126126
EXPECT_TRUE(handle.isUndefined());
127127
EXPECT_FALSE(handle.isDefined());
128-
EXPECT_EQ(pool.getLength(handle), value::undefined());
128+
EXPECT_EQ(pool.getLength(handle), StyleLength::undefined());
129129
}
130130

131131
} // namespace facebook::yoga

yoga/YGNodeStyle.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,19 @@ float YGNodeStyleGetFlexShrink(const YGNodeConstRef nodeRef) {
177177

178178
void YGNodeStyleSetFlexBasis(const YGNodeRef node, const float flexBasis) {
179179
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
180-
node, value::points(flexBasis));
180+
node, StyleLength::points(flexBasis));
181181
}
182182

183183
void YGNodeStyleSetFlexBasisPercent(
184184
const YGNodeRef node,
185185
const float flexBasisPercent) {
186186
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
187-
node, value::percent(flexBasisPercent));
187+
node, StyleLength::percent(flexBasisPercent));
188188
}
189189

190190
void YGNodeStyleSetFlexBasisAuto(const YGNodeRef node) {
191-
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(node, value::ofAuto());
191+
updateStyle<&Style::flexBasis, &Style::setFlexBasis>(
192+
node, StyleLength::ofAuto());
192193
}
193194

194195
YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
@@ -197,17 +198,17 @@ YGValue YGNodeStyleGetFlexBasis(const YGNodeConstRef node) {
197198

198199
void YGNodeStyleSetPosition(YGNodeRef node, YGEdge edge, float points) {
199200
updateStyle<&Style::position, &Style::setPosition>(
200-
node, scopedEnum(edge), value::points(points));
201+
node, scopedEnum(edge), StyleLength::points(points));
201202
}
202203

203204
void YGNodeStyleSetPositionPercent(YGNodeRef node, YGEdge edge, float percent) {
204205
updateStyle<&Style::position, &Style::setPosition>(
205-
node, scopedEnum(edge), value::percent(percent));
206+
node, scopedEnum(edge), StyleLength::percent(percent));
206207
}
207208

208209
void YGNodeStyleSetPositionAuto(YGNodeRef node, YGEdge edge) {
209210
updateStyle<&Style::position, &Style::setPosition>(
210-
node, scopedEnum(edge), value::ofAuto());
211+
node, scopedEnum(edge), StyleLength::ofAuto());
211212
}
212213

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

217218
void YGNodeStyleSetMargin(YGNodeRef node, YGEdge edge, float points) {
218219
updateStyle<&Style::margin, &Style::setMargin>(
219-
node, scopedEnum(edge), value::points(points));
220+
node, scopedEnum(edge), StyleLength::points(points));
220221
}
221222

222223
void YGNodeStyleSetMarginPercent(YGNodeRef node, YGEdge edge, float percent) {
223224
updateStyle<&Style::margin, &Style::setMargin>(
224-
node, scopedEnum(edge), value::percent(percent));
225+
node, scopedEnum(edge), StyleLength::percent(percent));
225226
}
226227

227228
void YGNodeStyleSetMarginAuto(YGNodeRef node, YGEdge edge) {
228229
updateStyle<&Style::margin, &Style::setMargin>(
229-
node, scopedEnum(edge), value::ofAuto());
230+
node, scopedEnum(edge), StyleLength::ofAuto());
230231
}
231232

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

236237
void YGNodeStyleSetPadding(YGNodeRef node, YGEdge edge, float points) {
237238
updateStyle<&Style::padding, &Style::setPadding>(
238-
node, scopedEnum(edge), value::points(points));
239+
node, scopedEnum(edge), StyleLength::points(points));
239240
}
240241

241242
void YGNodeStyleSetPaddingPercent(YGNodeRef node, YGEdge edge, float percent) {
242243
updateStyle<&Style::padding, &Style::setPadding>(
243-
node, scopedEnum(edge), value::percent(percent));
244+
node, scopedEnum(edge), StyleLength::percent(percent));
244245
}
245246

246247
YGValue YGNodeStyleGetPadding(YGNodeConstRef node, YGEdge edge) {
@@ -252,7 +253,7 @@ void YGNodeStyleSetBorder(
252253
const YGEdge edge,
253254
const float border) {
254255
updateStyle<&Style::border, &Style::setBorder>(
255-
node, scopedEnum(edge), value::points(border));
256+
node, scopedEnum(edge), StyleLength::points(border));
256257
}
257258

258259
float YGNodeStyleGetBorder(const YGNodeConstRef node, const YGEdge edge) {
@@ -269,12 +270,12 @@ void YGNodeStyleSetGap(
269270
const YGGutter gutter,
270271
const float gapLength) {
271272
updateStyle<&Style::gap, &Style::setGap>(
272-
node, scopedEnum(gutter), value::points(gapLength));
273+
node, scopedEnum(gutter), StyleLength::points(gapLength));
273274
}
274275

275276
void YGNodeStyleSetGapPercent(YGNodeRef node, YGGutter gutter, float percent) {
276277
updateStyle<&Style::gap, &Style::setGap>(
277-
node, scopedEnum(gutter), value::percent(percent));
278+
node, scopedEnum(gutter), StyleLength::percent(percent));
278279
}
279280

280281
float YGNodeStyleGetGap(const YGNodeConstRef node, const YGGutter gutter) {
@@ -307,17 +308,17 @@ YGBoxSizing YGNodeStyleGetBoxSizing(const YGNodeConstRef node) {
307308

308309
void YGNodeStyleSetWidth(YGNodeRef node, float points) {
309310
updateStyle<&Style::dimension, &Style::setDimension>(
310-
node, Dimension::Width, value::points(points));
311+
node, Dimension::Width, StyleLength::points(points));
311312
}
312313

313314
void YGNodeStyleSetWidthPercent(YGNodeRef node, float percent) {
314315
updateStyle<&Style::dimension, &Style::setDimension>(
315-
node, Dimension::Width, value::percent(percent));
316+
node, Dimension::Width, StyleLength::percent(percent));
316317
}
317318

318319
void YGNodeStyleSetWidthAuto(YGNodeRef node) {
319320
updateStyle<&Style::dimension, &Style::setDimension>(
320-
node, Dimension::Width, value::ofAuto());
321+
node, Dimension::Width, StyleLength::ofAuto());
321322
}
322323

323324
YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
@@ -326,17 +327,17 @@ YGValue YGNodeStyleGetWidth(YGNodeConstRef node) {
326327

327328
void YGNodeStyleSetHeight(YGNodeRef node, float points) {
328329
updateStyle<&Style::dimension, &Style::setDimension>(
329-
node, Dimension::Height, value::points(points));
330+
node, Dimension::Height, StyleLength::points(points));
330331
}
331332

332333
void YGNodeStyleSetHeightPercent(YGNodeRef node, float percent) {
333334
updateStyle<&Style::dimension, &Style::setDimension>(
334-
node, Dimension::Height, value::percent(percent));
335+
node, Dimension::Height, StyleLength::percent(percent));
335336
}
336337

337338
void YGNodeStyleSetHeightAuto(YGNodeRef node) {
338339
updateStyle<&Style::dimension, &Style::setDimension>(
339-
node, Dimension::Height, value::ofAuto());
340+
node, Dimension::Height, StyleLength::ofAuto());
340341
}
341342

342343
YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
@@ -345,12 +346,12 @@ YGValue YGNodeStyleGetHeight(YGNodeConstRef node) {
345346

346347
void YGNodeStyleSetMinWidth(const YGNodeRef node, const float minWidth) {
347348
updateStyle<&Style::minDimension, &Style::setMinDimension>(
348-
node, Dimension::Width, value::points(minWidth));
349+
node, Dimension::Width, StyleLength::points(minWidth));
349350
}
350351

351352
void YGNodeStyleSetMinWidthPercent(const YGNodeRef node, const float minWidth) {
352353
updateStyle<&Style::minDimension, &Style::setMinDimension>(
353-
node, Dimension::Width, value::percent(minWidth));
354+
node, Dimension::Width, StyleLength::percent(minWidth));
354355
}
355356

356357
YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
@@ -359,14 +360,14 @@ YGValue YGNodeStyleGetMinWidth(const YGNodeConstRef node) {
359360

360361
void YGNodeStyleSetMinHeight(const YGNodeRef node, const float minHeight) {
361362
updateStyle<&Style::minDimension, &Style::setMinDimension>(
362-
node, Dimension::Height, value::points(minHeight));
363+
node, Dimension::Height, StyleLength::points(minHeight));
363364
}
364365

365366
void YGNodeStyleSetMinHeightPercent(
366367
const YGNodeRef node,
367368
const float minHeight) {
368369
updateStyle<&Style::minDimension, &Style::setMinDimension>(
369-
node, Dimension::Height, value::percent(minHeight));
370+
node, Dimension::Height, StyleLength::percent(minHeight));
370371
}
371372

372373
YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
@@ -375,12 +376,12 @@ YGValue YGNodeStyleGetMinHeight(const YGNodeConstRef node) {
375376

376377
void YGNodeStyleSetMaxWidth(const YGNodeRef node, const float maxWidth) {
377378
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
378-
node, Dimension::Width, value::points(maxWidth));
379+
node, Dimension::Width, StyleLength::points(maxWidth));
379380
}
380381

381382
void YGNodeStyleSetMaxWidthPercent(const YGNodeRef node, const float maxWidth) {
382383
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
383-
node, Dimension::Width, value::percent(maxWidth));
384+
node, Dimension::Width, StyleLength::percent(maxWidth));
384385
}
385386

386387
YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
@@ -389,14 +390,14 @@ YGValue YGNodeStyleGetMaxWidth(const YGNodeConstRef node) {
389390

390391
void YGNodeStyleSetMaxHeight(const YGNodeRef node, const float maxHeight) {
391392
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
392-
node, Dimension::Height, value::points(maxHeight));
393+
node, Dimension::Height, StyleLength::points(maxHeight));
393394
}
394395

395396
void YGNodeStyleSetMaxHeightPercent(
396397
const YGNodeRef node,
397398
const float maxHeight) {
398399
updateStyle<&Style::maxDimension, &Style::setMaxDimension>(
399-
node, Dimension::Height, value::percent(maxHeight));
400+
node, Dimension::Height, StyleLength::percent(maxHeight));
400401
}
401402

402403
YGValue YGNodeStyleGetMaxHeight(const YGNodeConstRef node) {

yoga/node/Node.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,10 @@ Style::Length Node::processFlexBasis() const {
288288
return flexBasis;
289289
}
290290
if (style_.flex().isDefined() && style_.flex().unwrap() > 0.0f) {
291-
return config_->useWebDefaults() ? value::ofAuto() : value::points(0);
291+
return config_->useWebDefaults() ? StyleLength::ofAuto()
292+
: StyleLength::points(0);
292293
}
293-
return value::ofAuto();
294+
return StyleLength::ofAuto();
294295
}
295296

296297
FloatOptional Node::resolveFlexBasis(

yoga/node/Node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ class YG_EXPORT Node : public ::YGNode {
302302
std::vector<Node*> children_;
303303
const Config* config_;
304304
std::array<Style::Length, 2> processedDimensions_{
305-
{value::undefined(), value::undefined()}};
305+
{StyleLength::undefined(), StyleLength::undefined()}};
306306
};
307307

308308
inline Node* resolveRef(const YGNodeRef ref) {

0 commit comments

Comments
 (0)