Rename Node.h's getResolvedDimension to getProcessedDimension (#1705)
Summary: X-link: https://github.com/facebook/react-native/pull/46649 Pull Request resolved: https://github.com/facebook/yoga/pull/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 `contentBox` which would resolve the length for you, so I think this should be renamed. Also deleted unused `getResolvedDimensions` Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D63407730 fbshipit-source-id: e855c17d9c99817be308b7263fcb5d43559ede14
This commit is contained in:
committed by
Facebook GitHub Bot
parent
22b018c957
commit
b02caa8e06
@@ -324,7 +324,7 @@ void layoutAbsoluteChild(
|
|||||||
FlexDirection::Column, containingBlockWidth);
|
FlexDirection::Column, containingBlockWidth);
|
||||||
|
|
||||||
if (child->hasDefiniteLength(Dimension::Width, containingBlockWidth)) {
|
if (child->hasDefiniteLength(Dimension::Width, containingBlockWidth)) {
|
||||||
childWidth = child->getResolvedDimension(Dimension::Width)
|
childWidth = child->getProcessedDimension(Dimension::Width)
|
||||||
.resolve(containingBlockWidth)
|
.resolve(containingBlockWidth)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginRow;
|
marginRow;
|
||||||
@@ -359,7 +359,7 @@ void layoutAbsoluteChild(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (child->hasDefiniteLength(Dimension::Height, containingBlockHeight)) {
|
if (child->hasDefiniteLength(Dimension::Height, containingBlockHeight)) {
|
||||||
childHeight = child->getResolvedDimension(Dimension::Height)
|
childHeight = child->getProcessedDimension(Dimension::Height)
|
||||||
.resolve(containingBlockHeight)
|
.resolve(containingBlockHeight)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginColumn;
|
marginColumn;
|
||||||
|
@@ -110,7 +110,7 @@ static void computeFlexBasisForChild(
|
|||||||
child, FlexDirection::Row, direction, ownerWidth));
|
child, FlexDirection::Row, direction, ownerWidth));
|
||||||
|
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
child->getResolvedDimension(Dimension::Width).resolve(ownerWidth),
|
child->getProcessedDimension(Dimension::Width).resolve(ownerWidth),
|
||||||
paddingAndBorder));
|
paddingAndBorder));
|
||||||
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
} else if (!isMainAxisRow && isColumnStyleDimDefined) {
|
||||||
// The height is definite, so use that as the flex basis.
|
// The height is definite, so use that as the flex basis.
|
||||||
@@ -118,7 +118,7 @@ static void computeFlexBasisForChild(
|
|||||||
FloatOptional(paddingAndBorderForAxis(
|
FloatOptional(paddingAndBorderForAxis(
|
||||||
child, FlexDirection::Column, direction, ownerWidth));
|
child, FlexDirection::Column, direction, ownerWidth));
|
||||||
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
child->setLayoutComputedFlexBasis(yoga::maxOrDefined(
|
||||||
child->getResolvedDimension(Dimension::Height).resolve(ownerHeight),
|
child->getProcessedDimension(Dimension::Height).resolve(ownerHeight),
|
||||||
paddingAndBorder));
|
paddingAndBorder));
|
||||||
} else {
|
} else {
|
||||||
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
// Compute the flex basis and hypothetical main size (i.e. the clamped flex
|
||||||
@@ -132,14 +132,14 @@ static void computeFlexBasisForChild(
|
|||||||
child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth);
|
child->style().computeMarginForAxis(FlexDirection::Column, ownerWidth);
|
||||||
|
|
||||||
if (isRowStyleDimDefined) {
|
if (isRowStyleDimDefined) {
|
||||||
childWidth = child->getResolvedDimension(Dimension::Width)
|
childWidth = child->getProcessedDimension(Dimension::Width)
|
||||||
.resolve(ownerWidth)
|
.resolve(ownerWidth)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginRow;
|
marginRow;
|
||||||
childWidthSizingMode = SizingMode::StretchFit;
|
childWidthSizingMode = SizingMode::StretchFit;
|
||||||
}
|
}
|
||||||
if (isColumnStyleDimDefined) {
|
if (isColumnStyleDimDefined) {
|
||||||
childHeight = child->getResolvedDimension(Dimension::Height)
|
childHeight = child->getProcessedDimension(Dimension::Height)
|
||||||
.resolve(ownerHeight)
|
.resolve(ownerHeight)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginColumn;
|
marginColumn;
|
||||||
@@ -536,7 +536,7 @@ static float computeFlexBasisForChildren(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (auto child : children) {
|
for (auto child : children) {
|
||||||
child->resolveDimension();
|
child->processDimensions();
|
||||||
if (child->style().display() == Display::None) {
|
if (child->style().display() == Display::None) {
|
||||||
zeroOutLayoutRecursively(child);
|
zeroOutLayoutRecursively(child);
|
||||||
child->setHasNewLayout(true);
|
child->setHasNewLayout(true);
|
||||||
@@ -709,13 +709,13 @@ static float distributeFreeSpaceSecondPass(
|
|||||||
: SizingMode::FitContent;
|
: SizingMode::FitContent;
|
||||||
} else {
|
} else {
|
||||||
childCrossSize =
|
childCrossSize =
|
||||||
currentLineChild->getResolvedDimension(dimension(crossAxis))
|
currentLineChild->getProcessedDimension(dimension(crossAxis))
|
||||||
.resolve(availableInnerCrossDim)
|
.resolve(availableInnerCrossDim)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
marginCross;
|
marginCross;
|
||||||
const bool isLoosePercentageMeasurement =
|
const bool isLoosePercentageMeasurement =
|
||||||
currentLineChild->getResolvedDimension(dimension(crossAxis)).unit() ==
|
currentLineChild->getProcessedDimension(dimension(crossAxis))
|
||||||
Unit::Percent &&
|
.unit() == Unit::Percent &&
|
||||||
sizingModeCrossDim != SizingMode::StretchFit;
|
sizingModeCrossDim != SizingMode::StretchFit;
|
||||||
childCrossSizingMode =
|
childCrossSizingMode =
|
||||||
yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
|
yoga::isUndefined(childCrossSize) || isLoosePercentageMeasurement
|
||||||
@@ -1781,7 +1781,7 @@ static void calculateLayoutImpl(
|
|||||||
const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
|
const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
|
||||||
? availableInnerCrossDim + paddingAndBorderAxisCross
|
? availableInnerCrossDim + paddingAndBorderAxisCross
|
||||||
: node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize)
|
: node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize)
|
||||||
? node->getResolvedDimension(dimension(crossAxis))
|
? node->getProcessedDimension(dimension(crossAxis))
|
||||||
.resolve(crossAxisownerSize)
|
.resolve(crossAxisownerSize)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
: totalLineCrossDim + paddingAndBorderAxisCross;
|
: totalLineCrossDim + paddingAndBorderAxisCross;
|
||||||
@@ -2354,13 +2354,13 @@ void calculateLayout(
|
|||||||
// visit all dirty nodes at least once. Subsequent visits will be skipped if
|
// visit all dirty nodes at least once. Subsequent visits will be skipped if
|
||||||
// the input parameters don't change.
|
// the input parameters don't change.
|
||||||
gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed);
|
gCurrentGenerationCount.fetch_add(1, std::memory_order_relaxed);
|
||||||
node->resolveDimension();
|
node->processDimensions();
|
||||||
float width = YGUndefined;
|
float width = YGUndefined;
|
||||||
SizingMode widthSizingMode = SizingMode::MaxContent;
|
SizingMode widthSizingMode = SizingMode::MaxContent;
|
||||||
const auto& style = node->style();
|
const auto& style = node->style();
|
||||||
if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) {
|
if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) {
|
||||||
width =
|
width =
|
||||||
(node->getResolvedDimension(dimension(FlexDirection::Row))
|
(node->getProcessedDimension(dimension(FlexDirection::Row))
|
||||||
.resolve(ownerWidth)
|
.resolve(ownerWidth)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth));
|
node->style().computeMarginForAxis(FlexDirection::Row, ownerWidth));
|
||||||
@@ -2380,7 +2380,7 @@ void calculateLayout(
|
|||||||
SizingMode heightSizingMode = SizingMode::MaxContent;
|
SizingMode heightSizingMode = SizingMode::MaxContent;
|
||||||
if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) {
|
if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) {
|
||||||
height =
|
height =
|
||||||
(node->getResolvedDimension(dimension(FlexDirection::Column))
|
(node->getProcessedDimension(dimension(FlexDirection::Column))
|
||||||
.resolve(ownerHeight)
|
.resolve(ownerHeight)
|
||||||
.unwrap() +
|
.unwrap() +
|
||||||
node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth));
|
node->style().computeMarginForAxis(FlexDirection::Column, ownerWidth));
|
||||||
|
@@ -43,7 +43,7 @@ Node::Node(Node&& node) noexcept
|
|||||||
owner_(node.owner_),
|
owner_(node.owner_),
|
||||||
children_(std::move(node.children_)),
|
children_(std::move(node.children_)),
|
||||||
config_(node.config_),
|
config_(node.config_),
|
||||||
resolvedDimensions_(node.resolvedDimensions_) {
|
processedDimensions_(node.processedDimensions_) {
|
||||||
for (auto c : children_) {
|
for (auto c : children_) {
|
||||||
c->setOwner(this);
|
c->setOwner(this);
|
||||||
}
|
}
|
||||||
@@ -292,14 +292,14 @@ Style::Length Node::resolveFlexBasisPtr() const {
|
|||||||
return value::ofAuto();
|
return value::ofAuto();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::resolveDimension() {
|
void Node::processDimensions() {
|
||||||
for (auto dim : {Dimension::Width, Dimension::Height}) {
|
for (auto dim : {Dimension::Width, Dimension::Height}) {
|
||||||
if (style_.maxDimension(dim).isDefined() &&
|
if (style_.maxDimension(dim).isDefined() &&
|
||||||
yoga::inexactEquals(
|
yoga::inexactEquals(
|
||||||
style_.maxDimension(dim), style_.minDimension(dim))) {
|
style_.maxDimension(dim), style_.minDimension(dim))) {
|
||||||
resolvedDimensions_[yoga::to_underlying(dim)] = style_.maxDimension(dim);
|
processedDimensions_[yoga::to_underlying(dim)] = style_.maxDimension(dim);
|
||||||
} else {
|
} else {
|
||||||
resolvedDimensions_[yoga::to_underlying(dim)] = style_.dimension(dim);
|
processedDimensions_[yoga::to_underlying(dim)] = style_.dimension(dim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -86,7 +86,7 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
* https://www.w3.org/TR/css-sizing-3/#definite
|
* https://www.w3.org/TR/css-sizing-3/#definite
|
||||||
*/
|
*/
|
||||||
inline bool hasDefiniteLength(Dimension dimension, float ownerSize) {
|
inline bool hasDefiniteLength(Dimension dimension, float ownerSize) {
|
||||||
auto usedValue = getResolvedDimension(dimension).resolve(ownerSize);
|
auto usedValue = getProcessedDimension(dimension).resolve(ownerSize);
|
||||||
return usedValue.isDefined() && usedValue.unwrap() >= 0.0f;
|
return usedValue.isDefined() && usedValue.unwrap() >= 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,12 +152,8 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
return isDirty_;
|
return isDirty_;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<Style::Length, 2> getResolvedDimensions() const {
|
Style::Length getProcessedDimension(Dimension dimension) const {
|
||||||
return resolvedDimensions_;
|
return processedDimensions_[static_cast<size_t>(dimension)];
|
||||||
}
|
|
||||||
|
|
||||||
Style::Length getResolvedDimension(Dimension dimension) const {
|
|
||||||
return resolvedDimensions_[static_cast<size_t>(dimension)];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
@@ -233,7 +229,7 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
|
|
||||||
// Other methods
|
// Other methods
|
||||||
Style::Length resolveFlexBasisPtr() const;
|
Style::Length resolveFlexBasisPtr() const;
|
||||||
void resolveDimension();
|
void processDimensions();
|
||||||
Direction resolveDirection(Direction ownerDirection);
|
Direction resolveDirection(Direction ownerDirection);
|
||||||
void clearChildren();
|
void clearChildren();
|
||||||
/// Replaces the occurrences of oldChild with newChild
|
/// Replaces the occurrences of oldChild with newChild
|
||||||
@@ -280,7 +276,7 @@ class YG_EXPORT Node : public ::YGNode {
|
|||||||
Node* owner_ = nullptr;
|
Node* owner_ = nullptr;
|
||||||
std::vector<Node*> children_;
|
std::vector<Node*> children_;
|
||||||
const Config* config_;
|
const Config* config_;
|
||||||
std::array<Style::Length, 2> resolvedDimensions_{
|
std::array<Style::Length, 2> processedDimensions_{
|
||||||
{value::undefined(), value::undefined()}};
|
{value::undefined(), value::undefined()}};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user