Skip to content

Commit 6e226cd

Browse files
rozelefacebook-github-bot
authored andcommitted
Fix issue with flexShrink (facebook#53758)
Summary: X-link: facebook/yoga#1855 In cases where the remaining space for flex shrink is negative, we can get into a state where the `totalFlexShrinkScaledFactors` get's infintesimally small, but likely should just be floored to zero. This manifests in issues where flexShrink nodes are suddenly given way too much space, and generally only manifests in an issue if these flexShrink nodes have self-measuring children (such as text). Checking if the value is approximately zero appears to fix bugs for flexShrink. Reviewed By: andrewdacenko Differential Revision: D82313674
1 parent 6f48270 commit 6e226cd

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,8 @@ static float distributeFreeSpaceSecondPass(
661661
float childSize = YGUndefined;
662662

663663
if (yoga::isDefined(flexLine.layout.totalFlexShrinkScaledFactors) &&
664-
flexLine.layout.totalFlexShrinkScaledFactors == 0) {
664+
yoga::inexactEquals(
665+
flexLine.layout.totalFlexShrinkScaledFactors, 0.0f)) {
665666
childSize = childFlexBasis + flexShrinkScaledFactor;
666667
} else {
667668
childSize = childFlexBasis +
@@ -1533,9 +1534,9 @@ static void calculateLayoutImpl(
15331534

15341535
if (!useLegacyStretchBehaviour &&
15351536
((yoga::isDefined(flexLine.layout.totalFlexGrowFactors) &&
1536-
flexLine.layout.totalFlexGrowFactors == 0) ||
1537+
yoga::inexactEquals(flexLine.layout.totalFlexGrowFactors, 0.0f)) ||
15371538
(yoga::isDefined(node->resolveFlexGrow()) &&
1538-
node->resolveFlexGrow() == 0))) {
1539+
yoga::inexactEquals(node->resolveFlexGrow(), 0.0f)))) {
15391540
// If we don't have any children to flex or we can't flex the node
15401541
// itself, space we've used is all space we need. Root node also
15411542
// should be shrunk to minimum

0 commit comments

Comments
 (0)