Skip to content

Commit

Permalink
Rename Node.h's getResolvedDimension to getDimensionLength
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/yoga#1705

To get the height and width we call a function currently named `getResolvedDimension`. This returns a `Style::Length`, which in most cases we "resolve" immediately by calling `resolve`. This is a bit confusing that you need to `resolve` something that is already `resolved`.

I plan on adding a new function soon for `contextBox` which would resolve the length for you, so I think this should be renamed.

Also deleted unused `getResolvedDimensions`

Changelog: [Internal]

Differential Revision: D63407730
  • Loading branch information
joevilches authored and facebook-github-bot committed Sep 25, 2024
1 parent 62de1cd commit e86b3e7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ void layoutAbsoluteChild(
FlexDirection::Column, containingBlockWidth);

if (child->hasDefiniteLength(Dimension::Width, containingBlockWidth)) {
childWidth = child->getResolvedDimension(Dimension::Width)
childWidth = child->getDimensionLength(Dimension::Width)
.resolve(containingBlockWidth)
.unwrap() +
marginRow;
Expand Down Expand Up @@ -359,7 +359,7 @@ void layoutAbsoluteChild(
}

if (child->hasDefiniteLength(Dimension::Height, containingBlockHeight)) {
childHeight = child->getResolvedDimension(Dimension::Height)
childHeight = child->getDimensionLength(Dimension::Height)
.resolve(containingBlockHeight)
.unwrap() +
marginColumn;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ static void computeFlexBasisForChild(
child, FlexDirection::Row, direction, ownerWidth));

child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
child->getResolvedDimension(Dimension::Width).resolve(ownerWidth),
child->getDimensionLength(Dimension::Width).resolve(ownerWidth),
paddingAndBorder));
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
// The height is definite, so use that as the flex basis.
const FloatOptional paddingAndBorder =
FloatOptional(paddingAndBorderForAxis(
child, FlexDirection::Column, direction, ownerWidth));
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
child->getResolvedDimension(Dimension::Height).resolve(ownerHeight),
child->getDimensionLength(Dimension::Height).resolve(ownerHeight),
paddingAndBorder));
} else {
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
Expand All @@ -132,14 +132,14 @@ static void computeFlexBasisForChild(
child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth);

if (isRowStyleDimDefined) {
childWidth = child->getResolvedDimension(Dimension::Width)
childWidth = child->getDimensionLength(Dimension::Width)
.resolve(ownerWidth)
.unwrap() +
marginRow;
childWidthSizingMode = SizingMode::StretchFit;
}
if (isColumnStyleDimDefined) {
childHeight = child->getResolvedDimension(Dimension::Height)
childHeight = child->getDimensionLength(Dimension::Height)
.resolve(ownerHeight)
.unwrap() +
marginColumn;
Expand Down Expand Up @@ -709,12 +709,12 @@ static float distributeFreeSpaceSecondPass(
: SizingMode::FitContent;
} else {
childCrossSize =
currentLineChild->getResolvedDimension(dimension(crossAxis))
currentLineChild->getDimensionLength(dimension(crossAxis))
.resolve(availableInnerCrossDim)
.unwrap() +
marginCross;
const bool isLoosePercentageMeasurement =
currentLineChild->getResolvedDimension(dimension(crossAxis)).unit() ==
currentLineChild->getDimensionLength(dimension(crossAxis)).unit() ==
Unit::Percent &&
sizingModeCrossDim != SizingMode::StretchFit;
childCrossSizingMode =
Expand Down Expand Up @@ -1781,7 +1781,7 @@ static void calculateLayoutImpl(
const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
? availableInnerCrossDim + paddingAndBorderAxisCross
: node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize)
? node->getResolvedDimension(dimension(crossAxis))
? node->getDimensionLength(dimension(crossAxis))
.resolve(crossAxisownerSize)
.unwrap()
: totalLineCrossDim + paddingAndBorderAxisCross;
Expand Down Expand Up @@ -2360,7 +2360,7 @@ void calculateLayout(
const auto& style = node->style();
if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) {
width =
(node->getResolvedDimension(dimension(FlexDirection::Row))
(node->getDimensionLength(dimension(FlexDirection::Row))
.resolve(ownerWidth)
.unwrap() +
node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth));
Expand All @@ -2380,7 +2380,7 @@ void calculateLayout(
SizingMode heightSizingMode = SizingMode::MaxContent;
if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) {
height =
(node->getResolvedDimension(dimension(FlexDirection::Column))
(node->getDimensionLength(dimension(FlexDirection::Column))
.resolve(ownerHeight)
.unwrap() +
node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth));
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Node::Node(Node&& node) noexcept
owner_(node.owner_),
children_(std::move(node.children_)),
config_(node.config_),
resolvedDimensions_(node.resolvedDimensions_) {
dimensionLengths_(node.dimensionLengths_) {
for (auto c : children_) {
c->setOwner(this);
}
Expand Down Expand Up @@ -297,9 +297,9 @@ void Node::resolveDimension() {
if (style_.maxDimension(dim).isDefined() &&
yoga::inexactEquals(
style_.maxDimension(dim), style_.minDimension(dim))) {
resolvedDimensions_[yoga::to_underlying(dim)] = style_.maxDimension(dim);
dimensionLengths_[yoga::to_underlying(dim)] = style_.maxDimension(dim);
} else {
resolvedDimensions_[yoga::to_underlying(dim)] = style_.dimension(dim);
dimensionLengths_[yoga::to_underlying(dim)] = style_.dimension(dim);
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions packages/react-native/ReactCommon/yoga/yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class YG_EXPORT Node : public ::YGNode {
* https://www.w3.org/TR/css-sizing-3/#definite
*/
inline bool hasDefiniteLength(Dimension dimension, float ownerSize) {
auto usedValue = getResolvedDimension(dimension).resolve(ownerSize);
auto usedValue = getDimensionLength(dimension).resolve(ownerSize);
return usedValue.isDefined() && usedValue.unwrap() >= 0.0f;
}

Expand Down Expand Up @@ -152,12 +152,8 @@ class YG_EXPORT Node : public ::YGNode {
return isDirty_;
}

std::array<Style::Length, 2> getResolvedDimensions() const {
return resolvedDimensions_;
}

Style::Length getResolvedDimension(Dimension dimension) const {
return resolvedDimensions_[static_cast<size_t>(dimension)];
Style::Length getDimensionLength(Dimension dimension) const {
return dimensionLengths_[static_cast<size_t>(dimension)];
}

// Setters
Expand Down Expand Up @@ -280,7 +276,7 @@ class YG_EXPORT Node : public ::YGNode {
Node* owner_ = nullptr;
std::vector<Node*> children_;
const Config* config_;
std::array<Style::Length, 2> resolvedDimensions_{
std::array<Style::Length, 2> dimensionLengths_{
{value::undefined(), value::undefined()}};
};

Expand Down

0 comments on commit e86b3e7

Please sign in to comment.