Skip to content

Commit 017c9f5

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
yoga::resolveValue -> Length::resolve (facebook#1520)
Summary: X-link: facebook/react-native#41939 This code originates as `YGValueResolve`, used to compute a YGValue to a length in points, using a reference for 100%. This moves it to `Style::Length`, so we can encapsulate parts of it (for style value functions), and make the API more cohesive now that we can do C++ style OOP with it. Changelog: [Internal] Reviewed By: joevilches Differential Revision: D51796973
1 parent a24d470 commit 017c9f5

File tree

6 files changed

+72
-114
lines changed

6 files changed

+72
-114
lines changed

yoga/algorithm/AbsoluteLayout.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <yoga/algorithm/Align.h>
1010
#include <yoga/algorithm/BoundAxis.h>
1111
#include <yoga/algorithm/CalculateLayout.h>
12-
#include <yoga/algorithm/ResolveValue.h>
1312

1413
namespace facebook::yoga {
1514

@@ -323,10 +322,9 @@ void layoutAbsoluteChild(
323322
child->getMarginForAxis(FlexDirection::Column, containingBlockWidth);
324323

325324
if (child->styleDefinesDimension(FlexDirection::Row, containingBlockWidth)) {
326-
childWidth =
327-
yoga::resolveValue(
328-
child->getResolvedDimension(Dimension::Width), containingBlockWidth)
329-
.unwrap() +
325+
childWidth = child->getResolvedDimension(Dimension::Width)
326+
.resolve(containingBlockWidth)
327+
.unwrap() +
330328
marginRow;
331329
} else {
332330
// If the child doesn't have a specified width, compute the width based on
@@ -352,9 +350,8 @@ void layoutAbsoluteChild(
352350

353351
if (child->styleDefinesDimension(
354352
FlexDirection::Column, containingBlockHeight)) {
355-
childHeight = yoga::resolveValue(
356-
child->getResolvedDimension(Dimension::Height),
357-
containingBlockHeight)
353+
childHeight = child->getResolvedDimension(Dimension::Height)
354+
.resolve(containingBlockHeight)
358355
.unwrap() +
359356
marginColumn;
360357
} else {

yoga/algorithm/BoundAxis.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#pragma once
99

1010
#include <yoga/algorithm/FlexDirection.h>
11-
#include <yoga/algorithm/ResolveValue.h>
1211
#include <yoga/enums/Dimension.h>
1312
#include <yoga/enums/FlexDirection.h>
1413
#include <yoga/node/Node.h>
@@ -36,15 +35,11 @@ inline FloatOptional boundAxisWithinMinAndMax(
3635
FloatOptional max;
3736

3837
if (isColumn(axis)) {
39-
min = yoga::resolveValue(
40-
node->getStyle().minDimension(Dimension::Height), axisSize);
41-
max = yoga::resolveValue(
42-
node->getStyle().maxDimension(Dimension::Height), axisSize);
38+
min = node->getStyle().minDimension(Dimension::Height).resolve(axisSize);
39+
max = node->getStyle().maxDimension(Dimension::Height).resolve(axisSize);
4340
} else if (isRow(axis)) {
44-
min = yoga::resolveValue(
45-
node->getStyle().minDimension(Dimension::Width), axisSize);
46-
max = yoga::resolveValue(
47-
node->getStyle().maxDimension(Dimension::Width), axisSize);
41+
min = node->getStyle().minDimension(Dimension::Width).resolve(axisSize);
42+
max = node->getStyle().maxDimension(Dimension::Width).resolve(axisSize);
4843
}
4944

5045
if (max >= FloatOptional{0} && value > max) {

yoga/algorithm/CalculateLayout.cpp

+39-55
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <yoga/algorithm/FlexDirection.h>
2323
#include <yoga/algorithm/FlexLine.h>
2424
#include <yoga/algorithm/PixelGrid.h>
25-
#include <yoga/algorithm/ResolveValue.h>
2625
#include <yoga/algorithm/SizingMode.h>
2726
#include <yoga/debug/AssertFatal.h>
2827
#include <yoga/debug/Log.h>
@@ -52,15 +51,14 @@ bool calculateLayoutInternal(
5251
const uint32_t generationCount);
5352

5453
static void constrainMaxSizeForMode(
55-
const yoga::Node* const node,
56-
const enum FlexDirection axis,
57-
const float ownerAxisSize,
58-
const float ownerWidth,
59-
SizingMode* mode,
60-
float* size) {
54+
const yoga::Node* node,
55+
FlexDirection axis,
56+
float ownerAxisSize,
57+
float ownerWidth,
58+
/*in_out*/ SizingMode* mode,
59+
/*in_out*/ float* size) {
6160
const FloatOptional maxSize =
62-
yoga::resolveValue(
63-
node->getStyle().maxDimension(dimension(axis)), ownerAxisSize) +
61+
node->getStyle().maxDimension(dimension(axis)).resolve(ownerAxisSize) +
6462
FloatOptional(node->getMarginForAxis(axis, ownerWidth));
6563
switch (*mode) {
6664
case SizingMode::StretchFit:
@@ -103,7 +101,7 @@ static void computeFlexBasisForChild(
103101
SizingMode childHeightSizingMode;
104102

105103
const FloatOptional resolvedFlexBasis =
106-
yoga::resolveValue(child->resolveFlexBasisPtr(), mainAxisownerSize);
104+
child->resolveFlexBasisPtr().resolve(mainAxisownerSize);
107105
const bool isRowStyleDimDefined =
108106
child->styleDefinesDimension(FlexDirection::Row, ownerWidth);
109107
const bool isColumnStyleDimDefined =
@@ -125,16 +123,14 @@ static void computeFlexBasisForChild(
125123
paddingAndBorderForAxis(child, FlexDirection::Row, ownerWidth));
126124

127125
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
128-
yoga::resolveValue(
129-
child->getResolvedDimension(Dimension::Width), ownerWidth),
126+
child->getResolvedDimension(Dimension::Width).resolve(ownerWidth),
130127
paddingAndBorder));
131128
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
132129
// The height is definite, so use that as the flex basis.
133130
const FloatOptional paddingAndBorder = FloatOptional(
134131
paddingAndBorderForAxis(child, FlexDirection::Column, ownerWidth));
135132
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
136-
yoga::resolveValue(
137-
child->getResolvedDimension(Dimension::Height), ownerHeight),
133+
child->getResolvedDimension(Dimension::Height).resolve(ownerHeight),
138134
paddingAndBorder));
139135
} else {
140136
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
@@ -149,18 +145,16 @@ static void computeFlexBasisForChild(
149145
child->getMarginForAxis(FlexDirection::Column, ownerWidth);
150146

151147
if (isRowStyleDimDefined) {
152-
childWidth =
153-
yoga::resolveValue(
154-
child->getResolvedDimension(Dimension::Width), ownerWidth)
155-
.unwrap() +
148+
childWidth = child->getResolvedDimension(Dimension::Width)
149+
.resolve(ownerWidth)
150+
.unwrap() +
156151
marginRow;
157152
childWidthSizingMode = SizingMode::StretchFit;
158153
}
159154
if (isColumnStyleDimDefined) {
160-
childHeight =
161-
yoga::resolveValue(
162-
child->getResolvedDimension(Dimension::Height), ownerHeight)
163-
.unwrap() +
155+
childHeight = child->getResolvedDimension(Dimension::Height)
156+
.resolve(ownerHeight)
157+
.unwrap() +
164158
marginColumn;
165159
childHeightSizingMode = SizingMode::StretchFit;
166160
}
@@ -477,13 +471,13 @@ static float calculateAvailableInnerDimension(
477471
// We want to make sure our available height does not violate min and max
478472
// constraints
479473
const FloatOptional minDimensionOptional =
480-
yoga::resolveValue(node->getStyle().minDimension(dimension), ownerDim);
474+
node->getStyle().minDimension(dimension).resolve(ownerDim);
481475
const float minInnerDim = minDimensionOptional.isUndefined()
482476
? 0.0f
483477
: minDimensionOptional.unwrap() - paddingAndBorder;
484478

485479
const FloatOptional maxDimensionOptional =
486-
yoga::resolveValue(node->getStyle().maxDimension(dimension), ownerDim);
480+
node->getStyle().maxDimension(dimension).resolve(ownerDim);
487481

488482
const float maxInnerDim = maxDimensionOptional.isUndefined()
489483
? FLT_MAX
@@ -700,9 +694,8 @@ static float distributeFreeSpaceSecondPass(
700694
: SizingMode::FitContent;
701695
} else {
702696
childCrossSize =
703-
yoga::resolveValue(
704-
currentLineChild->getResolvedDimension(dimension(crossAxis)),
705-
availableInnerCrossDim)
697+
currentLineChild->getResolvedDimension(dimension(crossAxis))
698+
.resolve(availableInnerCrossDim)
706699
.unwrap() +
707700
marginCross;
708701
const bool isLoosePercentageMeasurement =
@@ -954,8 +947,8 @@ static void justifyMainAxis(
954947
if (sizingModeMainDim == SizingMode::FitContent &&
955948
flexLine.layout.remainingFreeSpace > 0) {
956949
if (style.minDimension(dimension(mainAxis)).isDefined() &&
957-
yoga::resolveValue(
958-
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
950+
style.minDimension(dimension(mainAxis))
951+
.resolve(mainAxisownerSize)
959952
.isDefined()) {
960953
// This condition makes sure that if the size of main dimension(after
961954
// considering child nodes main dim, leading and trailing padding etc)
@@ -964,10 +957,9 @@ static void justifyMainAxis(
964957

965958
// `minAvailableMainDim` denotes minimum available space in which child
966959
// can be laid out, it will exclude space consumed by padding and border.
967-
const float minAvailableMainDim =
968-
yoga::resolveValue(
969-
style.minDimension(dimension(mainAxis)), mainAxisownerSize)
970-
.unwrap() -
960+
const float minAvailableMainDim = style.minDimension(dimension(mainAxis))
961+
.resolve(mainAxisownerSize)
962+
.unwrap() -
971963
leadingPaddingAndBorderMain - trailingPaddingAndBorderMain;
972964
const float occupiedSpaceByChildNodes =
973965
availableInnerMainDim - flexLine.layout.remainingFreeSpace;
@@ -1446,20 +1438,16 @@ static void calculateLayoutImpl(
14461438
if (sizingModeMainDim != SizingMode::StretchFit) {
14471439
const auto& style = node->getStyle();
14481440
const float minInnerWidth =
1449-
yoga::resolveValue(style.minDimension(Dimension::Width), ownerWidth)
1450-
.unwrap() -
1441+
style.minDimension(Dimension::Width).resolve(ownerWidth).unwrap() -
14511442
paddingAndBorderAxisRow;
14521443
const float maxInnerWidth =
1453-
yoga::resolveValue(style.maxDimension(Dimension::Width), ownerWidth)
1454-
.unwrap() -
1444+
style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap() -
14551445
paddingAndBorderAxisRow;
14561446
const float minInnerHeight =
1457-
yoga::resolveValue(style.minDimension(Dimension::Height), ownerHeight)
1458-
.unwrap() -
1447+
style.minDimension(Dimension::Height).resolve(ownerHeight).unwrap() -
14591448
paddingAndBorderAxisColumn;
14601449
const float maxInnerHeight =
1461-
yoga::resolveValue(style.maxDimension(Dimension::Height), ownerHeight)
1462-
.unwrap() -
1450+
style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap() -
14631451
paddingAndBorderAxisColumn;
14641452

14651453
const float minInnerMainDim =
@@ -2431,17 +2419,15 @@ void calculateLayout(
24312419
const auto& style = node->getStyle();
24322420
if (node->styleDefinesDimension(FlexDirection::Row, ownerWidth)) {
24332421
width =
2434-
(yoga::resolveValue(
2435-
node->getResolvedDimension(dimension(FlexDirection::Row)),
2436-
ownerWidth)
2422+
(node->getResolvedDimension(dimension(FlexDirection::Row))
2423+
.resolve(ownerWidth)
24372424
.unwrap() +
24382425
node->getMarginForAxis(FlexDirection::Row, ownerWidth));
24392426
widthSizingMode = SizingMode::StretchFit;
2440-
} else if (yoga::resolveValue(
2441-
style.maxDimension(Dimension::Width), ownerWidth)
2427+
} else if (style.maxDimension(Dimension::Width)
2428+
.resolve(ownerWidth)
24422429
.isDefined()) {
2443-
width = yoga::resolveValue(style.maxDimension(Dimension::Width), ownerWidth)
2444-
.unwrap();
2430+
width = style.maxDimension(Dimension::Width).resolve(ownerWidth).unwrap();
24452431
widthSizingMode = SizingMode::FitContent;
24462432
} else {
24472433
width = ownerWidth;
@@ -2453,18 +2439,16 @@ void calculateLayout(
24532439
SizingMode heightSizingMode = SizingMode::MaxContent;
24542440
if (node->styleDefinesDimension(FlexDirection::Column, ownerHeight)) {
24552441
height =
2456-
(yoga::resolveValue(
2457-
node->getResolvedDimension(dimension(FlexDirection::Column)),
2458-
ownerHeight)
2442+
(node->getResolvedDimension(dimension(FlexDirection::Column))
2443+
.resolve(ownerHeight)
24592444
.unwrap() +
24602445
node->getMarginForAxis(FlexDirection::Column, ownerWidth));
24612446
heightSizingMode = SizingMode::StretchFit;
2462-
} else if (yoga::resolveValue(
2463-
style.maxDimension(Dimension::Height), ownerHeight)
2447+
} else if (style.maxDimension(Dimension::Height)
2448+
.resolve(ownerHeight)
24642449
.isDefined()) {
24652450
height =
2466-
yoga::resolveValue(style.maxDimension(Dimension::Height), ownerHeight)
2467-
.unwrap();
2451+
style.maxDimension(Dimension::Height).resolve(ownerHeight).unwrap();
24682452
heightSizingMode = SizingMode::FitContent;
24692453
} else {
24702454
height = ownerHeight;

yoga/algorithm/ResolveValue.h

-28
This file was deleted.

0 commit comments

Comments
 (0)