Skip to content

Commit dc1f0a6

Browse files
joevilchesfacebook-github-bot
authored andcommitted
Let flex basis support content box (#1713)
Summary: X-link: facebook/react-native#46740 Pull Request resolved: #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
1 parent bc23694 commit dc1f0a6

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

yoga/algorithm/CalculateLayout.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ static void computeFlexBasisForChild(
8888
SizingMode childHeightSizingMode;
8989

9090
const FloatOptional resolvedFlexBasis =
91-
child->resolveFlexBasisPtr().resolve(mainAxisownerSize);
91+
child->resolveFlexBasis(direction, mainAxis, mainAxisownerSize);
9292
const bool isRowStyleDimDefined =
9393
child->hasDefiniteLength(Dimension::Width, ownerWidth);
9494
const bool isColumnStyleDimDefined =

yoga/node/Node.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <cstddef>
1010
#include <iostream>
1111

12+
#include <yoga/algorithm/FlexDirection.h>
1213
#include <yoga/debug/AssertFatal.h>
1314
#include <yoga/debug/Log.h>
1415
#include <yoga/node/Node.h>
@@ -281,7 +282,7 @@ void Node::setPosition(
281282
crossAxisTrailingEdge);
282283
}
283284

284-
Style::Length Node::resolveFlexBasisPtr() const {
285+
Style::Length Node::processFlexBasis() const {
285286
Style::Length flexBasis = style_.flexBasis();
286287
if (flexBasis.unit() != Unit::Auto && flexBasis.unit() != Unit::Undefined) {
287288
return flexBasis;
@@ -292,6 +293,25 @@ Style::Length Node::resolveFlexBasisPtr() const {
292293
return value::ofAuto();
293294
}
294295

296+
FloatOptional Node::resolveFlexBasis(
297+
Direction direction,
298+
FlexDirection flexDirection,
299+
float referenceLength) const {
300+
FloatOptional value = processFlexBasis().resolve(referenceLength);
301+
if (style_.boxSizing() == BoxSizing::BorderBox) {
302+
return value;
303+
}
304+
305+
Dimension dim = dimension(flexDirection);
306+
FloatOptional dimensionPaddingAndBorder =
307+
FloatOptional{style_.computePaddingAndBorderForDimension(
308+
direction, dim, referenceLength)};
309+
310+
return value +
311+
(dimensionPaddingAndBorder.isDefined() ? dimensionPaddingAndBorder
312+
: FloatOptional{0.0});
313+
}
314+
295315
void Node::processDimensions() {
296316
for (auto dim : {Dimension::Width, Dimension::Height}) {
297317
if (style_.maxDimension(dim).isDefined() &&

yoga/node/Node.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,11 @@ class YG_EXPORT Node : public ::YGNode {
247247
void setPosition(Direction direction, float ownerWidth, float ownerHeight);
248248

249249
// Other methods
250-
Style::Length resolveFlexBasisPtr() const;
250+
Style::Length processFlexBasis() const;
251+
FloatOptional resolveFlexBasis(
252+
Direction direction,
253+
FlexDirection flexDirection,
254+
float referenceLength) const;
251255
void processDimensions();
252256
Direction resolveDirection(Direction ownerDirection);
253257
void clearChildren();

0 commit comments

Comments
 (0)