handle negative margin and min padding correctly

This commit is contained in:
Christopher Chedeau
2014-04-22 17:33:08 -07:00
parent 01ccc098c9
commit 3dbd168938
2 changed files with 14 additions and 6 deletions

View File

@@ -135,7 +135,6 @@ var computeLayout = (function() {
return !isUndefined(node.style[pos]); return !isUndefined(node.style[pos]);
} }
function getPosition(node, pos) { function getPosition(node, pos) {
if (pos in node.style) { if (pos in node.style) {
return node.style[pos]; return node.style[pos];
@@ -293,15 +292,15 @@ var computeLayout = (function() {
} }
} }
} }
mainPos += getPaddingAndBorder(node, trailing[mainAxis]); mainPos += getPaddingAndBorder(node, trailing[mainAxis]);
crossDim += getPaddingAndBorder(node, leading[crossAxis]) + crossDim += getPaddingAndBorderAxis(node, crossAxis);
getPaddingAndBorder(node, trailing[crossAxis]);
if (isUndefined(node.layout[dim[mainAxis]]) && !mainDimInStyle) { if (isUndefined(node.layout[dim[mainAxis]]) && !mainDimInStyle) {
node.layout[dim[mainAxis]] = mainPos > 0 ? mainPos : 0; node.layout[dim[mainAxis]] = fmaxf(mainPos, getPaddingAndBorderAxis(node, mainAxis));
} }
if (isUndefined(node.layout[dim[crossAxis]])) { if (isUndefined(node.layout[dim[crossAxis]])) {
node.layout[dim[crossAxis]] = crossDim > 0 ? crossDim : 0; node.layout[dim[crossAxis]] = fmaxf(crossDim, getPaddingAndBorderAxis(node, crossAxis));
} }
for (var/*int*/ i = 0; i < node.children.length; ++i) { for (var/*int*/ i = 0; i < node.children.length; ++i) {

View File

@@ -733,7 +733,16 @@ describe('Layout', function() {
); );
}); });
it('should handle negative margin and min padding correctly', function() {
testLayout(
{style: {borderRightWidth: 1, flexDirection: 'row'}, children: [
{style: {marginRight: -8}}
]},
{width: 1, height: 0, top: 0, left: 0, children: [
{width: 0, height: 0, top: 0, left: 0}
]}
)
});