From a36820d15e4611ab81df9652215f1b57ecd93b5c Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 12 Jun 2014 11:52:07 -0700 Subject: [PATCH] better handling for padding in a top/bottom or left/right configuration --- src/Layout.js | 25 +++++++++++++++++-------- src/__tests__/Layout-test.js | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/Layout.js b/src/Layout.js index 0663ac9d..4e6fa628 100755 --- a/src/Layout.js +++ b/src/Layout.js @@ -490,12 +490,13 @@ var computeLayout = (function() { getPaddingAndBorderAxis(node, mainAxis) ); } else { - child.layout[dim[mainAxis]] = fmaxf(0, + child.layout[dim[mainAxis]] = fmaxf( + getPaddingAndBorderAxis(child, mainAxis), node.layout[dim[mainAxis]] - child.layout[pos[mainAxis]] - getMargin(child, trailing[mainAxis]) - getPosition(child, trailing[mainAxis]) - ) + getPaddingAndBorderAxis(child, mainAxis); + ); } } } @@ -528,12 +529,20 @@ var computeLayout = (function() { getPosition(child, trailing[crossAxis]); } if (leadingPos && trailingPos) { - child.layout[dim[crossAxis]] = fmaxf(0, - node.layout[dim[crossAxis]] - - child.layout[pos[crossAxis]] - - getMargin(child, trailing[crossAxis]) - - getPosition(child, trailing[crossAxis]) - ); + if (isDimDefined(child, crossAxis)) { + child.layout[dim[crossAxis]] = fmaxf( + child.style[dim[crossAxis]], + getPaddingAndBorderAxis(node, crossAxis) + ); + } else { + child.layout[dim[crossAxis]] = fmaxf( + getPaddingAndBorderAxis(child, crossAxis), + node.layout[dim[crossAxis]] - + child.layout[pos[crossAxis]] - + getMargin(child, trailing[crossAxis]) - + getPosition(child, trailing[crossAxis]) + ); + } } } else { var/*float*/ leadingCrossDim = getPaddingAndBorder(node, leading[crossAxis]); diff --git a/src/__tests__/Layout-test.js b/src/__tests__/Layout-test.js index 9bba5031..0c24441f 100755 --- a/src/__tests__/Layout-test.js +++ b/src/__tests__/Layout-test.js @@ -983,6 +983,28 @@ describe('Layout', function() { ); }); + it('should layout with position absolute left, right and width', function() { + testLayout( + {style: {}, children: [ + {style: {left: 5, right: -1, width: 300, position: 'absolute'}} + ]}, + {width: 0, height: 0, top: 0, left: 0, children: [ + {width: 300, height: 0, top: 0, left: 5} + ]} + ); + }); + + it('should layout with position absolute top, bottom and min padding', function() { + testLayout( + {style: {}, children: [ + {style: {top: -5, bottom: -5, paddingTop: 5, position: 'absolute'}} + ]}, + {width: 0, height: 0, top: 0, left: 0, children: [ + {width: 0, height: 10, top: -5, left: 0} + ]} + ); + }); + xit('should layout text with alignItems: stretch', function() { testLayout( {style: {width: 80, padding: 7, alignItems: 'stretch', measure: text('loooooooooong with space')}},