From 5a2d2007a4fcffa072a4bc3764622ac1baf30910 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Wed, 19 Aug 2015 15:36:36 -0700 Subject: [PATCH] [React Native] Fix infinite loop in css-layout Summary: Manual pick of https://github.com/facebook/css-layout/commit/9001a3d2 since we're still lagging behind the upstream. Fixes #1378. --- React/Layout/Layout.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/React/Layout/Layout.c b/React/Layout/Layout.c index fb50d1fdceee1c..11ca898eef1c4c 100644 --- a/React/Layout/Layout.c +++ b/React/Layout/Layout.c @@ -448,11 +448,12 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) { // We want to execute the next two loops one per line with flex-wrap int startLine = 0; int endLine = 0; - int nextLine = 0; + // int nextOffset = 0; + int alreadyComputedNextLayout = 0; // We aggregate the total dimensions of the container in those two variables float linesCrossDim = 0; float linesMainDim = 0; - while (endLine != node->children_count) { + while (endLine < node->children_count) { // Layout non flexible children and count children by type // mainContentDim is accumulation of the dimensions and margin of all the @@ -496,7 +497,7 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) { } // This is the main recursive call. We layout non flexible children. - if (nextLine == 0) { + if (alreadyComputedNextLayout == 0) { layoutNode(child, maxWidth); } @@ -512,12 +513,15 @@ static void layoutNodeImpl(css_node_t *node, float parentMaxWidth) { // The element we are about to add would make us go to the next line if (isFlexWrap(node) && !isUndefined(node->layout.dimensions[dim[mainAxis]]) && - mainContentDim + nextContentDim > definedMainDim) { + mainContentDim + nextContentDim > definedMainDim && + // If there's only one element, then it's bigger than the content + // and needs its own line + i != startLine) { nonFlexibleChildrenCount--; - nextLine = i + 1; + alreadyComputedNextLayout = 1; break; } - nextLine = 0; + alreadyComputedNextLayout = 0; mainContentDim += nextContentDim; endLine = i + 1; }