From fa2f7080e2de1355b725fea768ae7f1f53b31665 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 22 Apr 2014 13:32:45 -0700 Subject: [PATCH] fix reduce from being called on every single test. stretch now won't go below the padding --- src/Layout.js | 9 ++++++--- src/__tests__/Layout-test.js | 14 ++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/Layout.js b/src/Layout.js index a930ee6c..363ca17e 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -322,9 +322,12 @@ var computeLayout = (function() { leadingCrossDim += remainingCrossDim; } else if (alignItem === CSS_ALIGN_STRETCH) { if (!isDimDefined(child, crossAxis)) { - child.layout[dim[crossAxis]] = node.layout[dim[crossAxis]] - - getPaddingAndBorderAxis(node, crossAxis) - - getMarginAxis(child, crossAxis); + child.layout[dim[crossAxis]] = fmaxf( + node.layout[dim[crossAxis]] - + getPaddingAndBorderAxis(node, crossAxis) - + getMarginAxis(child, crossAxis), + getPaddingAndBorderAxis(child, crossAxis) + ); } } child.layout[pos[crossAxis]] += leadingCrossDim; diff --git a/src/__tests__/Layout-test.js b/src/__tests__/Layout-test.js index db7497b8..13582e3f 100755 --- a/src/__tests__/Layout-test.js +++ b/src/__tests__/Layout-test.js @@ -711,6 +711,16 @@ describe('Layout', function() { ) }); + it('should correctly take into account min padding for stretch', function() { + testLayout( + {style: {width: 50}, children: [ + {style: {marginLeft: 20, padding: 20, alignSelf: 'stretch'}} + ]}, + {width: 50, height: 40, top: 0, left: 0, children: [ + {width: 40, height: 40, top: 0, left: 20} + ]} + ); + }); @@ -774,10 +784,10 @@ describe('Layout', function() { return node; } - for (var i = 0; i < 100; ++i) { + for (var i = 0; i < 1000; ++i) { var node = generateRandomNode(); - if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout)) { + if (JSON.stringify(computeLayout(node)) !== JSON.stringify(computeDOMLayout(node))) { node = reduceTest(node); }