Skip to content

Commit

Permalink
[React Native] Fix infinite loop in css-layout
Browse files Browse the repository at this point in the history
Summary:
Manual pick of facebook/yoga@9001a3d2 since we're still lagging behind the upstream. Fixes facebook#1378.
  • Loading branch information
sophiebits committed Aug 19, 2015
1 parent d9bd445 commit 5a2d200
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions React/Layout/Layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
// <Loop A> Layout non flexible children and count children by type

// mainContentDim is accumulation of the dimensions and margin of all the
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand Down

0 comments on commit 5a2d200

Please sign in to comment.