Skip to content

Commit

Permalink
Let flex basis support content box (#46740)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #46740

X-link: facebook/yoga#1713

The flex basis length applies to the value of `box-sizing` per the spec: https://drafts.csswg.org/css-flexbox-1/#flex-basis-property

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63424590

fbshipit-source-id: f73bffd30cc7b673453a55089ecc880819d3d788
  • Loading branch information
joevilches authored and facebook-github-bot committed Oct 1, 2024
1 parent 3535298 commit d06a9b3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void computeFlexBasisForChild(
SizingMode childHeightSizingMode;

const FloatOptional resolvedFlexBasis =
child->resolveFlexBasisPtr().resolve(mainAxisownerSize);
child->resolveFlexBasis(direction, mainAxis, mainAxisownerSize);
const bool isRowStyleDimDefined =
child->hasDefiniteLength(Dimension::Width, ownerWidth);
const bool isColumnStyleDimDefined =
Expand Down
22 changes: 21 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstddef>
#include <iostream>

#include <yoga/algorithm/FlexDirection.h>
#include <yoga/debug/AssertFatal.h>
#include <yoga/debug/Log.h>
#include <yoga/node/Node.h>
Expand Down Expand Up @@ -281,7 +282,7 @@ void Node::setPosition(
crossAxisTrailingEdge);
}

Style::Length Node::resolveFlexBasisPtr() const {
Style::Length Node::processFlexBasis() const {
Style::Length flexBasis = style_.flexBasis();
if (flexBasis.unit() != Unit::Auto && flexBasis.unit() != Unit::Undefined) {
return flexBasis;
Expand All @@ -292,6 +293,25 @@ Style::Length Node::resolveFlexBasisPtr() const {
return value::ofAuto();
}

FloatOptional Node::resolveFlexBasis(
Direction direction,
FlexDirection flexDirection,
float referenceLength) const {
FloatOptional value = processFlexBasis().resolve(referenceLength);
if (style_.boxSizing() == BoxSizing::BorderBox) {
return value;
}

Dimension dim = dimension(flexDirection);
FloatOptional dimensionPaddingAndBorder =
FloatOptional{style_.computePaddingAndBorderForDimension(
direction, dim, referenceLength)};

return value +
(dimensionPaddingAndBorder.isDefined() ? dimensionPaddingAndBorder
: FloatOptional{0.0});
}

void Node::processDimensions() {
for (auto dim : {Dimension::Width, Dimension::Height}) {
if (style_.maxDimension(dim).isDefined() &&
Expand Down
6 changes: 5 additions & 1 deletion packages/react-native/ReactCommon/yoga/yoga/node/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,11 @@ class YG_EXPORT Node : public ::YGNode {
void setPosition(Direction direction, float ownerWidth, float ownerHeight);

// Other methods
Style::Length resolveFlexBasisPtr() const;
Style::Length processFlexBasis() const;
FloatOptional resolveFlexBasis(
Direction direction,
FlexDirection flexDirection,
float referenceLength) const;
void processDimensions();
Direction resolveDirection(Direction ownerDirection);
void clearChildren();
Expand Down

0 comments on commit d06a9b3

Please sign in to comment.