diff --git a/spec/LayoutSpec.js b/spec/LayoutSpec.js index 0971e41a..b3422c6a 100755 --- a/spec/LayoutSpec.js +++ b/spec/LayoutSpec.js @@ -472,6 +472,13 @@ describe('Layout', function() { ); }); + it('should layout node with padding', function() { + testLayout( + {style: {padding: 5}}, + {width: 10, height: 10, top: 0, left: 0} + ); + }); + it('should layout randomly', function() { function RNG(seed) { this.state = seed; diff --git a/src/Layout.js b/src/Layout.js index f9eaec81..e4254548 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -36,7 +36,7 @@ function computeLayout(node) { } if (type in node.style) { - return node.style.margin; + return node.style[type]; } return 0; @@ -164,8 +164,8 @@ function computeLayout(node) { } } - var crossDim = 0; - var mainPos = leadingMainDim; + var crossDim = getPadding(leading[crossAxis], node); + var mainPos = getPadding(leading[mainAxis], node) + leadingMainDim; children.forEach(function(child) { child.layout[pos[mainAxis]] += mainPos; mainPos += getDimWithMargin(child, mainAxis) + betweenMainDim; @@ -177,6 +177,8 @@ function computeLayout(node) { } } }); + mainPos += getPadding(trailing[mainAxis], node); + crossDim += getPadding(trailing[crossAxis], node); if (node.layout[dim[mainAxis]] === undefined && !mainDimInStyle) { node.layout[dim[mainAxis]] = Math.max(mainPos, 0);