From 930c4dc700649b81ecefbec66302b442ab122bbd Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 15 Apr 2014 17:53:38 -0700 Subject: [PATCH] fix stretch with margin --- spec/LayoutSpec.js | 15 +++++++++++++-- src/Layout.js | 4 +++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spec/LayoutSpec.js b/spec/LayoutSpec.js index 86973e25..18cc9ee7 100755 --- a/spec/LayoutSpec.js +++ b/spec/LayoutSpec.js @@ -456,6 +456,17 @@ describe('Layout', function() { ); }); + it('should layout alignItems stretch and margin', function() { + testLayout( + {style: {alignItems: 'stretch'}, children: [ + {style: {marginLeft: 10}} + ]}, + {width: 10, height: 0, top: 0, left: 0, children: [ + {width: 0, height: 0, top: 0, left: 10} + ]} + ); + }); + it('should layout randomly', function() { function RNG(seed) { this.state = seed; @@ -496,8 +507,8 @@ describe('Layout', function() { randMinMax(node, 0.1, 'marginBottom', 0, 20); randEnum(node, 0.1, 'flexDirection', ['row', 'column']); randEnum(node, 0.1, 'justifyContent', ['flex-start', 'center', 'flex-end', 'space-between', 'space-around']); - randEnum(node, 0.1, 'alignItems', ['flex-start', 'center', 'flex-end']); - randEnum(node, 0.1, 'alignSelf', ['flex-start', 'center', 'flex-end']); + randEnum(node, 0.1, 'alignItems', ['flex-start', 'center', 'flex-end', 'stretch']); + randEnum(node, 0.1, 'alignSelf', ['flex-start', 'center', 'flex-end', 'stretch']); randEnum(node, 0.1, 'flex', ['none', 1]); randChildren(node, 0.2); return node; diff --git a/src/Layout.js b/src/Layout.js index ea5e567b..c7a148eb 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -189,7 +189,9 @@ function computeLayout(node) { } else if (alignItem === 'flex-end') { leadingCrossDim = remainingCrossDim; } else if (alignItem === 'stretch') { - child.layout[dim[crossAxis]] = getDimWithMargin(node, crossAxis); + child.layout[dim[crossAxis]] = node.layout[dim[crossAxis]] - + getMargin(leading[crossAxis], child) - + getMargin(trailing[crossAxis], child); } child.layout[pos[crossAxis]] += leadingCrossDim; });