Commit a0528423 authored by Hans Muller's avatar Hans Muller

Adds FlexJustifyContent.collapse

parent a0c8a4c6
......@@ -46,6 +46,8 @@ enum FlexJustifyContent {
spaceBetween,
/// Place the free space evenly between the children as well as before and after the first and last child
spaceAround,
/// Do not expand to fill the free space. None of the children may specify a flex factor.
collapse,
}
/// How the children should be placed along the cross axis in a flex layout
......@@ -337,7 +339,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
int totalChildren = 0;
assert(constraints != null);
final double mainSize = (_direction == FlexDirection.horizontal) ? constraints.constrainWidth() : constraints.constrainHeight();
final bool canFlex = mainSize < double.INFINITY;
final bool canFlex = mainSize < double.INFINITY && justifyContent != FlexJustifyContent.collapse;
double crossSize = 0.0; // This is determined as we lay out the children
double freeSpace = canFlex ? mainSize : 0.0;
RenderBox child = firstChild;
......@@ -478,6 +480,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
}
switch (_justifyContent) {
case FlexJustifyContent.start:
case FlexJustifyContent.collapse:
leadingSpace = 0.0;
betweenSpace = 0.0;
break;
......
......@@ -42,4 +42,66 @@ void main() {
expect(didReceiveTap, isTrue);
});
});
test('Row, Column and FlexJustifyContent.collapse', () {
final Key flexKey = new Key('flexKey');
// Row without justifyContent: FlexJustifyContent.collapse
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Center(
child: new Row([
new Container(width: 10.0, height: 100.0),
new Container(width: 30.0, height: 100.0)
],
key: flexKey
)
));
Size flexSize = tester.findElementByKey(flexKey).renderObject.size;
expect(flexSize.width, equals(800.0));
expect(flexSize.height, equals(100.0));
// Row with justifyContent: FlexJustifyContent.collapse
tester.pumpWidget(new Center(
child: new Row([
new Container(width: 10.0, height: 100.0),
new Container(width: 30.0, height: 100.0)
],
key: flexKey,
justifyContent: FlexJustifyContent.collapse
)
));
flexSize = tester.findElementByKey(flexKey).renderObject.size;
expect(flexSize.width, equals(40.0));
expect(flexSize.height, equals(100.0));
});
// Column without justifyContent: FlexJustifyContent.collapse
testWidgets((WidgetTester tester) {
tester.pumpWidget(new Center(
child: new Column([
new Container(width: 100.0, height: 100.0),
new Container(width: 100.0, height: 150.0)
],
key: flexKey
)
));
Size flexSize = tester.findElementByKey(flexKey).renderObject.size;
expect(flexSize.width, equals(100.0));
expect(flexSize.height, equals(600.0));
// Column with justifyContent: FlexJustifyContent.collapse
tester.pumpWidget(new Center(
child: new Column([
new Container(width: 100.0, height: 100.0),
new Container(width: 100.0, height: 150.0)
],
key: flexKey,
justifyContent: FlexJustifyContent.collapse
)
));
flexSize = tester.findElementByKey(flexKey).renderObject.size;
expect(flexSize.width, equals(100.0));
expect(flexSize.height, equals(250.0));
});
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment