fix edge case of flex: 1
This commit is contained in:
@@ -436,8 +436,8 @@ describe('Layout', function() {
|
||||
{style: {height: 100}}
|
||||
]}
|
||||
]},
|
||||
{width: 20, height: 120, top: 0, left: 0, children: [{
|
||||
width: 20, height: 120, top: 0, left: 0, children: [
|
||||
{width: 20, height: 120, top: 0, left: 0, children: [
|
||||
{width: 20, height: 120, top: 0, left: 0, children: [
|
||||
{width: 0, height: 0, top: 10, left: 10},
|
||||
{width: 0, height: 100, top: 20, left: 20}
|
||||
]}
|
||||
@@ -445,6 +445,17 @@ describe('Layout', function() {
|
||||
);
|
||||
});
|
||||
|
||||
it('should layout flex inside of an empty element', function() {
|
||||
testLayout(
|
||||
{style: {}, children: [
|
||||
{style: {flex: 1}},
|
||||
]},
|
||||
{width: 0, height: 0, top: 0, left: 0, children: [
|
||||
{width: 0, height: 0, top: 0, left: 0}
|
||||
]}
|
||||
);
|
||||
});
|
||||
|
||||
it('should layout randomly', function() {
|
||||
function RNG(seed) {
|
||||
this.state = seed;
|
||||
@@ -487,6 +498,7 @@ describe('Layout', function() {
|
||||
randEnum(node, 0.1, 'justifyContent', ['flex-start', 'center', 'flex-end', 'space-between', 'space-around']);
|
||||
randEnum(node, 0.1, 'alignItems', ['flex-start', 'center', 'flex-end']);
|
||||
randEnum(node, 0.1, 'alignSelf', ['flex-start', 'center', 'flex-end']);
|
||||
randEnum(node, 0.1, 'flex', ['none', 1]);
|
||||
randChildren(node, 0.2);
|
||||
return node;
|
||||
}
|
||||
|
@@ -66,6 +66,10 @@ function computeLayout(node) {
|
||||
return 'column';
|
||||
}
|
||||
|
||||
function getFlex(node) {
|
||||
return node.style.flex === 1;
|
||||
}
|
||||
|
||||
var axis = {
|
||||
left: 'horizontal',
|
||||
right: 'horizontal',
|
||||
@@ -109,7 +113,7 @@ function computeLayout(node) {
|
||||
var mainContentDim = 0;
|
||||
var flexibleChildrenCount = 0;
|
||||
children.forEach(function(child) {
|
||||
if (!child.style.flex) {
|
||||
if (node.layout[dim[mainAxis]] === undefined || !getFlex(child)) {
|
||||
layoutNode(child);
|
||||
mainContentDim += child.layout[dim[mainAxis]] +
|
||||
getMargin(leading[mainAxis], child) +
|
||||
@@ -126,7 +130,7 @@ function computeLayout(node) {
|
||||
if (flexibleChildrenCount) {
|
||||
var flexibleMainDim = remainingMainDim / flexibleChildrenCount;
|
||||
children.forEach(function(child) {
|
||||
if (child.style.flex) {
|
||||
if (getFlex(child)) {
|
||||
child.layout[dim[mainAxis]] = flexibleMainDim;
|
||||
layoutNode(child);
|
||||
}
|
||||
|
Reference in New Issue
Block a user