Fix NaN value with just justifyContent: 'center'
This commit is contained in:
@@ -485,6 +485,14 @@ describe('Layout', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should layout for center', function() {
|
||||||
|
testLayout({
|
||||||
|
style: {justifyContent: 'center'}
|
||||||
|
}, {
|
||||||
|
width: 0, height: 0, top: 0, left: 0,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should layout randomly', function() {
|
it('should layout randomly', function() {
|
||||||
function RNG(seed) {
|
function RNG(seed) {
|
||||||
this.state = seed;
|
this.state = seed;
|
||||||
@@ -501,6 +509,11 @@ describe('Layout', function() {
|
|||||||
node.style[attribute] = Math.floor(rng.nextFloat() * (max - min)) + min;
|
node.style[attribute] = Math.floor(rng.nextFloat() * (max - min)) + min;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function randEnum(node, chance, attribute, enumValues) {
|
||||||
|
if (rng.nextFloat() < chance) {
|
||||||
|
node.style[attribute] = enumValues[Math.floor(rng.nextFloat() * enumValues.length)];
|
||||||
|
}
|
||||||
|
}
|
||||||
function randChildren(node, chance) {
|
function randChildren(node, chance) {
|
||||||
while (rng.nextFloat() < chance) {
|
while (rng.nextFloat() < chance) {
|
||||||
if (!node.children) {
|
if (!node.children) {
|
||||||
@@ -518,6 +531,8 @@ describe('Layout', function() {
|
|||||||
randMinMax(node, 0.1, 'marginTop', -5, 20);
|
randMinMax(node, 0.1, 'marginTop', -5, 20);
|
||||||
randMinMax(node, 0.1, 'marginRight', -5, 20);
|
randMinMax(node, 0.1, 'marginRight', -5, 20);
|
||||||
randMinMax(node, 0.1, 'marginBottom', -5, 20);
|
randMinMax(node, 0.1, 'marginBottom', -5, 20);
|
||||||
|
randEnum(node, 0.1, 'flexDirection', ['row', 'column']);
|
||||||
|
randEnum(node, 0.1, 'justifyContent', ['flex-start', 'center', 'flex-end', 'space-between', 'space-around']);
|
||||||
randChildren(node, 0.2);
|
randChildren(node, 0.2);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
@@ -117,9 +117,10 @@ function computeLayout(node) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var remainingMainDim = node.layout[dim[mainAxis]] - mainContentDim;
|
|
||||||
var leadingMainDim = 0;
|
var leadingMainDim = 0;
|
||||||
var betweenMainDim = 0;
|
var betweenMainDim = 0;
|
||||||
|
if (node.layout[dim[mainAxis]] !== undefined) {
|
||||||
|
var remainingMainDim = node.layout[dim[mainAxis]] - mainContentDim;
|
||||||
if (flexibleChildrenCount) {
|
if (flexibleChildrenCount) {
|
||||||
var flexibleMainDim = remainingMainDim / flexibleChildrenCount;
|
var flexibleMainDim = remainingMainDim / flexibleChildrenCount;
|
||||||
children.forEach(function(child) {
|
children.forEach(function(child) {
|
||||||
@@ -143,6 +144,7 @@ function computeLayout(node) {
|
|||||||
leadingMainDim = betweenMainDim / 2;
|
leadingMainDim = betweenMainDim / 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var crossDim = 0;
|
var crossDim = 0;
|
||||||
var mainPos = leadingMainDim;
|
var mainPos = leadingMainDim;
|
||||||
|
Reference in New Issue
Block a user