From b11c04ed0f659b14135006759587fbc6eaa39fe3 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Mon, 21 Apr 2014 18:40:00 -0700 Subject: [PATCH] cross axis left and padding --- src/Layout.js | 6 +++++- src/__tests__/Layout-test.js | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Layout.js b/src/Layout.js index fd59daeb..b9b5c648 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -285,7 +285,11 @@ var computeLayout = (function() { } child.layout[pos[crossAxis]] += leadingCrossDim; } else { - child.layout[pos[crossAxis]] += getPadding(node, leading[crossAxis]); + if (isPosDefined(child, leading[crossAxis])) { + child.layout[pos[crossAxis]] = getPosition(child, leading[crossAxis]); + } else { + child.layout[pos[crossAxis]] += getPadding(node, leading[crossAxis]); + } } } diff --git a/src/__tests__/Layout-test.js b/src/__tests__/Layout-test.js index 49944954..1e7a7b63 100755 --- a/src/__tests__/Layout-test.js +++ b/src/__tests__/Layout-test.js @@ -559,6 +559,17 @@ describe('Layout', function() { ); }); + it('should layout node with padding and child position absolute, left', function() { + testLayout( + {style: {padding: 20}, children: [ + {style: {left: 5, position: 'absolute'}} + ]}, + {width: 40, height: 40, top: 0, left: 0, children: [ + {width: 0, height: 0, top: 20, left: 5} + ]} + ); + }); + it('should layout randomly', function() { function RNG(seed) { this.state = seed; @@ -602,8 +613,8 @@ describe('Layout', function() { var node = {style: {}}; randMinMax(node, 0.1, 'width', 0, 1000); randMinMax(node, 0.1, 'height', 0, 1000); - randMinMax(node, 0.1, 'top', -10, 10); - randMinMax(node, 0.1, 'left', -10, 10); + randMinMax(node, 0.5, 'top', -10, 10); + randMinMax(node, 0.5, 'left', -10, 10); randMinMax(node, 0.1, 'right', -10, 10); randMinMax(node, 0.1, 'bottom', -10, 10); randSpacing(node, 0.1, 'margin', 0, 20); @@ -613,7 +624,7 @@ describe('Layout', function() { 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]); - randEnum(node, 0.1, 'position', ['relative', 'absolute']); + randEnum(node, 0.5, 'position', ['relative', 'absolute']); randChildren(node, 0.2); return node; }