From 0699a30980ef08a87d51cd67e9d452c9aba427ed Mon Sep 17 00:00:00 2001 From: Emil Sjolander Date: Tue, 18 Oct 2016 09:19:22 -0700 Subject: [PATCH] Fix flex-shrink when shrinking to zero size Reviewed By: gkassabli Differential Revision: D4036345 fbshipit-source-id: f6848d7a316a694426f761d5e51d972bd379d90e --- React/CSSLayout/CSSLayout.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/React/CSSLayout/CSSLayout.c b/React/CSSLayout/CSSLayout.c index f28e0f5df8a..3d2e2717230 100644 --- a/React/CSSLayout/CSSLayout.c +++ b/React/CSSLayout/CSSLayout.c @@ -1550,14 +1550,20 @@ static void layoutNodeImpl(const CSSNodeRef node, if (remainingFreeSpace < 0) { flexShrinkScaledFactor = -currentRelativeChild->style.flexShrink * childFlexBasis; - // Is this child able to shrink? if (flexShrinkScaledFactor != 0) { - updatedMainSize = boundAxis(currentRelativeChild, - mainAxis, - childFlexBasis + - remainingFreeSpace / totalFlexShrinkScaledFactors * - flexShrinkScaledFactor); + float childSize; + + if (totalFlexShrinkScaledFactors == 0) { + childSize = childFlexBasis + flexShrinkScaledFactor; + } else { + childSize = + childFlexBasis + + (remainingFreeSpace / totalFlexShrinkScaledFactors) * + flexShrinkScaledFactor; + } + + updatedMainSize = boundAxis(currentRelativeChild, mainAxis, childSize); } } else if (remainingFreeSpace > 0) { flexGrowFactor = currentRelativeChild->style.flexGrow;