Skip to content

Commit c7e218d

Browse files
rozelefacebook-github-bot
authored andcommitted
Fix issue with flexShrink (#1855)
Summary: X-link: facebook/react-native#53758 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 6617be1 commit c7e218d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

yoga/algorithm/CalculateLayout.cpp

Lines changed: 5 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,10 @@ static void calculateLayoutImpl(
15331534

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

0 commit comments

Comments
 (0)