Node::styleDefinesDimension() -> Node::hasDefiniteLength() (#1526)
Summary: X-link: https://github.com/facebook/react-native/pull/41995 Pull Request resolved: https://github.com/facebook/yoga/pull/1526 This function has made quite the journey from something that originally made more sense. This renames, refactors, and adds documentation for what it actually does. This should eventually make its way into `yoga::Style` once computed style is moved into that structure. bypass-github-export-checks Reviewed By: joevilches Differential Revision: D52105718 fbshipit-source-id: 6492224dd2e10cef3c5fc6a139323ad189a0925c
This commit is contained in:
committed by
Facebook GitHub Bot
parent
ca4ecc044d
commit
1f391dfc50
@@ -321,7 +321,7 @@ void layoutAbsoluteChild(
|
||||
auto marginColumn =
|
||||
child->getMarginForAxis(FlexDirection::Column, containingBlockWidth);
|
||||
|
||||
if (child->styleDefinesDimension(FlexDirection::Row, containingBlockWidth)) {
|
||||
if (child->hasDefiniteLength(Dimension::Width, containingBlockWidth)) {
|
||||
childWidth = child->getResolvedDimension(Dimension::Width)
|
||||
.resolve(containingBlockWidth)
|
||||
.unwrap() +
|
||||
@@ -348,8 +348,7 @@ void layoutAbsoluteChild(
|
||||
}
|
||||
}
|
||||
|
||||
if (child->styleDefinesDimension(
|
||||
FlexDirection::Column, containingBlockHeight)) {
|
||||
if (child->hasDefiniteLength(Dimension::Height, containingBlockHeight)) {
|
||||
childHeight = child->getResolvedDimension(Dimension::Height)
|
||||
.resolve(containingBlockHeight)
|
||||
.unwrap() +
|
||||
|
@@ -103,9 +103,9 @@ static void computeFlexBasisForChild(
|
||||
const FloatOptional resolvedFlexBasis =
|
||||
child->resolveFlexBasisPtr().resolve(mainAxisownerSize);
|
||||
const bool isRowStyleDimDefined =
|
||||
child->styleDefinesDimension(FlexDirection::Row, ownerWidth);
|
||||
child->hasDefiniteLength(Dimension::Width, ownerWidth);
|
||||
const bool isColumnStyleDimDefined =
|
||||
child->styleDefinesDimension(FlexDirection::Column, ownerHeight);
|
||||
child->hasDefiniteLength(Dimension::Height, ownerHeight);
|
||||
|
||||
if (resolvedFlexBasis.isDefined() && yoga::isDefined(mainAxisSize)) {
|
||||
if (child->getLayout().computedFlexBasis.isUndefined() ||
|
||||
@@ -676,8 +676,8 @@ static float distributeFreeSpaceSecondPass(
|
||||
childCrossSize += marginCross;
|
||||
} else if (
|
||||
!std::isnan(availableInnerCrossDim) &&
|
||||
!currentLineChild->styleDefinesDimension(
|
||||
crossAxis, availableInnerCrossDim) &&
|
||||
!currentLineChild->hasDefiniteLength(
|
||||
dimension(crossAxis), availableInnerCrossDim) &&
|
||||
sizingModeCrossDim == SizingMode::StretchFit &&
|
||||
!(isNodeFlexWrap && mainAxisOverflows) &&
|
||||
resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
|
||||
@@ -686,8 +686,8 @@ static float distributeFreeSpaceSecondPass(
|
||||
currentLineChild->marginTrailingValue(crossAxis).unit() != Unit::Auto) {
|
||||
childCrossSize = availableInnerCrossDim;
|
||||
childCrossSizingMode = SizingMode::StretchFit;
|
||||
} else if (!currentLineChild->styleDefinesDimension(
|
||||
crossAxis, availableInnerCrossDim)) {
|
||||
} else if (!currentLineChild->hasDefiniteLength(
|
||||
dimension(crossAxis), availableInnerCrossDim)) {
|
||||
childCrossSize = availableInnerCrossDim;
|
||||
childCrossSizingMode = yoga::isUndefined(childCrossSize)
|
||||
? SizingMode::MaxContent
|
||||
@@ -723,8 +723,9 @@ static float distributeFreeSpaceSecondPass(
|
||||
&childCrossSizingMode,
|
||||
&childCrossSize);
|
||||
|
||||
const bool requiresStretchLayout = !currentLineChild->styleDefinesDimension(
|
||||
crossAxis, availableInnerCrossDim) &&
|
||||
const bool requiresStretchLayout =
|
||||
!currentLineChild->hasDefiniteLength(
|
||||
dimension(crossAxis), availableInnerCrossDim) &&
|
||||
resolveChildAlignment(node, currentLineChild) == Align::Stretch &&
|
||||
currentLineChild->getFlexStartMarginValue(crossAxis).unit() !=
|
||||
Unit::Auto &&
|
||||
@@ -1622,8 +1623,8 @@ static void calculateLayoutImpl(
|
||||
child->marginTrailingValue(crossAxis).unit() != Unit::Auto) {
|
||||
// If the child defines a definite size for its cross axis, there's
|
||||
// no need to stretch.
|
||||
if (!child->styleDefinesDimension(
|
||||
crossAxis, availableInnerCrossDim)) {
|
||||
if (!child->hasDefiniteLength(
|
||||
dimension(crossAxis), availableInnerCrossDim)) {
|
||||
float childMainSize =
|
||||
child->getLayout().measuredDimension(dimension(mainAxis));
|
||||
const auto& childStyle = child->getStyle();
|
||||
@@ -1735,7 +1736,7 @@ static void calculateLayoutImpl(
|
||||
|
||||
const float unclampedCrossDim = sizingModeCrossDim == SizingMode::StretchFit
|
||||
? availableInnerCrossDim + paddingAndBorderAxisCross
|
||||
: node->styleDefinesDimension(crossAxis, crossAxisownerSize)
|
||||
: node->hasDefiniteLength(dimension(crossAxis), crossAxisownerSize)
|
||||
? node->getResolvedDimension(dimension(crossAxis))
|
||||
.resolve(crossAxisownerSize)
|
||||
.unwrap()
|
||||
@@ -1879,8 +1880,8 @@ static void calculateLayoutImpl(
|
||||
|
||||
// Remeasure child with the line height as it as been only
|
||||
// measured with the owners height yet.
|
||||
if (!child->styleDefinesDimension(
|
||||
crossAxis, availableInnerCrossDim)) {
|
||||
if (!child->hasDefiniteLength(
|
||||
dimension(crossAxis), availableInnerCrossDim)) {
|
||||
const float childWidth = isMainAxisRow
|
||||
? (child->getLayout().measuredDimension(
|
||||
Dimension::Width) +
|
||||
@@ -2427,7 +2428,7 @@ void calculateLayout(
|
||||
float width = YGUndefined;
|
||||
SizingMode widthSizingMode = SizingMode::MaxContent;
|
||||
const auto& style = node->getStyle();
|
||||
if (node->styleDefinesDimension(FlexDirection::Row, ownerWidth)) {
|
||||
if (node->hasDefiniteLength(Dimension::Width, ownerWidth)) {
|
||||
width =
|
||||
(node->getResolvedDimension(dimension(FlexDirection::Row))
|
||||
.resolve(ownerWidth)
|
||||
@@ -2447,7 +2448,7 @@ void calculateLayout(
|
||||
|
||||
float height = YGUndefined;
|
||||
SizingMode heightSizingMode = SizingMode::MaxContent;
|
||||
if (node->styleDefinesDimension(FlexDirection::Column, ownerHeight)) {
|
||||
if (node->hasDefiniteLength(Dimension::Height, ownerHeight)) {
|
||||
height =
|
||||
(node->getResolvedDimension(dimension(FlexDirection::Column))
|
||||
.resolve(ownerHeight)
|
||||
|
@@ -420,23 +420,6 @@ bool Node::isLayoutDimensionDefined(const FlexDirection axis) {
|
||||
return yoga::isDefined(value) && value >= 0.0f;
|
||||
}
|
||||
|
||||
bool Node::styleDefinesDimension(
|
||||
const FlexDirection axis,
|
||||
const float ownerSize) {
|
||||
auto resolvedDimension = getResolvedDimension(dimension(axis));
|
||||
if (!resolvedDimension.isDefined()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !(
|
||||
resolvedDimension.isAuto() ||
|
||||
(resolvedDimension.unit() == Unit::Point &&
|
||||
resolvedDimension.value().unwrap() < 0.0f) ||
|
||||
(resolvedDimension.unit() == Unit::Percent &&
|
||||
(resolvedDimension.value().unwrap() < 0.0f ||
|
||||
yoga::isUndefined(ownerSize))));
|
||||
}
|
||||
|
||||
// Setters
|
||||
|
||||
void Node::setMeasureFunc(YGMeasureFunc measureFunc) {
|
||||
|
@@ -130,7 +130,14 @@ class YG_EXPORT Node : public ::YGNode {
|
||||
|
||||
bool isLayoutDimensionDefined(const FlexDirection axis);
|
||||
|
||||
bool styleDefinesDimension(const FlexDirection axis, const float ownerSize);
|
||||
/**
|
||||
* Whether the node has a "definite length" along the given axis.
|
||||
* https://www.w3.org/TR/css-sizing-3/#definite
|
||||
*/
|
||||
inline bool hasDefiniteLength(Dimension dimension, float ownerSize) {
|
||||
auto usedValue = getResolvedDimension(dimension).resolve(ownerSize);
|
||||
return usedValue.isDefined() && usedValue.unwrap() >= 0.0f;
|
||||
}
|
||||
|
||||
bool hasErrata(Errata errata) const {
|
||||
return config_->hasErrata(errata);
|
||||
|
Reference in New Issue
Block a user