space-around with padding

This commit is contained in:
Christopher Chedeau
2014-04-16 16:12:24 -07:00
parent 2471dbe49a
commit 7f40bf084b
2 changed files with 20 additions and 3 deletions

View File

@@ -533,7 +533,6 @@ describe('Layout', function() {
{style: {margin: 16}}
]}
]},
{width: 32, height: 32, top: 0, left: 0, children: [
{width: 32, height: 32, top: 0, left: 0, children: [
{width: 0, height: 0, top: 16, left: 16}
@@ -542,13 +541,24 @@ describe('Layout', function() {
);
});
it('should layout node with top', function() {
it('should layout node with top and left', function() {
testLayout(
{style: {top: 5, left: 5}},
{width: 0, height: 0, top: 5, left: 5}
);
});
it('should layout node with height, padding and space-around', function() {
testLayout(
{style : {height: 10, paddingTop: 5, justifyContent: 'space-around'}, children: [
{style: {}}
]},
{width: 0, height: 10, top: 0, left: 0, children: [
{width: 0, height: 0, top: 7.5, left: 0}
]}
);
});
it('should layout randomly', function() {
function RNG(seed) {
this.state = seed;
@@ -589,6 +599,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', 0, 10);
randMinMax(node, 0.1, 'left', 0, 10);
randSpacing(node, 0.1, 'margin', 0, 20);
randSpacing(node, 0.1, 'padding', 0, 20);
randEnum(node, 0.1, 'flexDirection', ['row', 'column']);

View File

@@ -145,7 +145,11 @@ function computeLayout(node) {
var leadingMainDim = 0;
var betweenMainDim = 0;
if (node.layout[dim[mainAxis]] !== undefined) {
var remainingMainDim = node.layout[dim[mainAxis]] - mainContentDim;
var remainingMainDim = node.layout[dim[mainAxis]] -
getPadding(node, leading[mainAxis]) -
getPadding(node, trailing[mainAxis]) -
mainContentDim;
if (flexibleChildrenCount) {
var flexibleMainDim = remainingMainDim / flexibleChildrenCount;
children.forEach(function(child) {
@@ -201,6 +205,7 @@ function computeLayout(node) {
getDimWithMargin(child, crossAxis) -
getPadding(node, leading[crossAxis]) -
getPadding(node, trailing[crossAxis]);
var leadingCrossDim = getPadding(node, leading[crossAxis]);
if (alignItem === 'flex-start') {
// Do nothing