Skip to content

Commit aa65e92

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Fix handling of negative flex gap (#39596)
Summary: Pull Request resolved: #39596 X-link: react/yoga#1405 I noticed that we weren't clamping negative flex gap values to zero. This fixes that bug. Reviewed By: rshest Differential Revision: D49530494 fbshipit-source-id: 069db7312f72a085c5c4b01ead7bc66a353a07e5
1 parent df492cc commit aa65e92

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

‎packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ static void justifyMainAxis(
12151215
node->getLeadingPaddingAndBorder(mainAxis, ownerWidth).unwrap();
12161216
const float trailingPaddingAndBorderMain =
12171217
node->getTrailingPaddingAndBorder(mainAxis, ownerWidth).unwrap();
1218-
const float gap = node->getGapForAxis(mainAxis, ownerWidth).unwrap();
1218+
const float gap = node->getGapForAxis(mainAxis, ownerWidth);
12191219
// If we are using "at most" rules in the main axis, make sure that
12201220
// remainingFreeSpace is 0 when min main dimension is not given
12211221
if (measureModeMainDim == MeasureMode::AtMost &&
@@ -1666,8 +1666,7 @@ static void calculateLayoutImpl(
16661666
generationCount);
16671667

16681668
if (childCount > 1) {
1669-
totalMainDim +=
1670-
node->getGapForAxis(mainAxis, availableInnerCrossDim).unwrap() *
1669+
totalMainDim += node->getGapForAxis(mainAxis, availableInnerCrossDim) *
16711670
static_cast<float>(childCount - 1);
16721671
}
16731672

@@ -1692,7 +1691,7 @@ static void calculateLayoutImpl(
16921691
float totalLineCrossDim = 0;
16931692

16941693
const float crossAxisGap =
1695-
node->getGapForAxis(crossAxis, availableInnerCrossDim).unwrap();
1694+
node->getGapForAxis(crossAxis, availableInnerCrossDim);
16961695

16971696
// Max main dimension of all the lines.
16981697
float maxLineMainDim = 0;

‎packages/react-native/ReactCommon/yoga/yoga/algorithm/FlexLine.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ FlexLine calculateFlexLine(
3333
const FlexDirection mainAxis = resolveDirection(
3434
node->getStyle().flexDirection(), node->resolveDirection(ownerDirection));
3535
const bool isNodeFlexWrap = node->getStyle().flexWrap() != Wrap::NoWrap;
36-
const float gap = node->getGapForAxis(mainAxis, availableInnerWidth).unwrap();
36+
const float gap = node->getGapForAxis(mainAxis, availableInnerWidth);
3737

3838
// Add items to the current line until it's full or we run out of items.
3939
for (; endOfLineIndex < node->getChildren().size(); endOfLineIndex++) {

‎packages/react-native/ReactCommon/yoga/yoga/node/Node.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,13 @@ FloatOptional Node::getMarginForAxis(
202202
return getLeadingMargin(axis, widthSize) + getTrailingMargin(axis, widthSize);
203203
}
204204

205-
FloatOptional Node::getGapForAxis(
206-
const FlexDirection axis,
207-
const float widthSize) const {
205+
float Node::getGapForAxis(const FlexDirection axis, const float widthSize)
206+
const {
208207
auto gap = isRow(axis)
209-
? computeColumnGap(style_.gap(), CompactValue::ofZero())
210-
: computeRowGap(style_.gap(), CompactValue::ofZero());
211-
return yoga::resolveValue(gap, widthSize);
208+
? computeColumnGap(style_.gap(), CompactValue::ofUndefined())
209+
: computeRowGap(style_.gap(), CompactValue::ofUndefined());
210+
auto resolvedGap = yoga::resolveValue(gap, widthSize);
211+
return maxOrDefined(resolvedGap.unwrap(), 0);
212212
}
213213

214214
YGSize Node::measure(

‎packages/react-native/ReactCommon/yoga/yoga/node/Node.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,7 @@ class YG_EXPORT Node : public ::YGNode {
231231
FloatOptional getMarginForAxis(
232232
const FlexDirection axis,
233233
const float widthSize) const;
234-
FloatOptional getGapForAxis(const FlexDirection axis, const float widthSize)
235-
const;
234+
float getGapForAxis(const FlexDirection axis, const float widthSize) const;
236235
// Setters
237236

238237
void setContext(void* context) {

0 commit comments

Comments
 (0)