Commit 8254dce2 authored by Adam Barth's avatar Adam Barth

Dismissable doesn't resize from its full size (#3194)

Previously we'd snap to the size of the background widget before resizing to

zero. Now we force the background widget to match the size of the dimissable

widget at the time it was dismissed.



Fixes #3092
parent 84acea36
...@@ -76,7 +76,7 @@ class Dismissable extends StatefulWidget { ...@@ -76,7 +76,7 @@ class Dismissable extends StatefulWidget {
/// A widget that is stacked behind the child. If secondaryBackground is also /// A widget that is stacked behind the child. If secondaryBackground is also
/// specified then this widget only appears when the child has been dragged /// specified then this widget only appears when the child has been dragged
/// down or to the right. /// down or to the right.
final Widget background; final Widget background;
/// A widget that is stacked behind the child and is exposed when the child /// A widget that is stacked behind the child and is exposed when the child
/// has been dragged up or to the left. It may only be specified when background /// has been dragged up or to the left. It may only be specified when background
...@@ -119,6 +119,7 @@ class _DismissableState extends State<Dismissable> { ...@@ -119,6 +119,7 @@ class _DismissableState extends State<Dismissable> {
double _dragExtent = 0.0; double _dragExtent = 0.0;
bool _dragUnderway = false; bool _dragUnderway = false;
Size _sizePriorToCollapse;
@override @override
void dispose() { void dispose() {
...@@ -261,6 +262,7 @@ class _DismissableState extends State<Dismissable> { ...@@ -261,6 +262,7 @@ class _DismissableState extends State<Dismissable> {
assert(_moveController != null); assert(_moveController != null);
assert(_moveController.isCompleted); assert(_moveController.isCompleted);
assert(_resizeController == null); assert(_resizeController == null);
assert(_sizePriorToCollapse == null);
if (config.resizeDuration == null) { if (config.resizeDuration == null) {
if (config.onDismissed != null) if (config.onDismissed != null)
config.onDismissed(_dismissDirection); config.onDismissed(_dismissDirection);
...@@ -269,6 +271,8 @@ class _DismissableState extends State<Dismissable> { ...@@ -269,6 +271,8 @@ class _DismissableState extends State<Dismissable> {
..addListener(_handleResizeProgressChanged); ..addListener(_handleResizeProgressChanged);
_resizeController.forward(); _resizeController.forward();
setState(() { setState(() {
RenderBox box = context.findRenderObject();
_sizePriorToCollapse = box.size;
_resizeAnimation = new Tween<double>( _resizeAnimation = new Tween<double>(
begin: 1.0, begin: 1.0,
end: 0.0 end: 0.0
...@@ -315,8 +319,12 @@ class _DismissableState extends State<Dismissable> { ...@@ -315,8 +319,12 @@ class _DismissableState extends State<Dismissable> {
return new SizeTransition( return new SizeTransition(
sizeFactor: _resizeAnimation, sizeFactor: _resizeAnimation,
axis: _directionIsXAxis ? Axis.horizontal : Axis.vertical, axis: _directionIsXAxis ? Axis.vertical : Axis.horizontal,
child: background child: new SizedBox(
width: _sizePriorToCollapse.width,
height: _sizePriorToCollapse.height,
child: background
)
); );
} }
......
...@@ -12,6 +12,7 @@ Axis scrollDirection = Axis.vertical; ...@@ -12,6 +12,7 @@ Axis scrollDirection = Axis.vertical;
DismissDirection dismissDirection = DismissDirection.horizontal; DismissDirection dismissDirection = DismissDirection.horizontal;
DismissDirection reportedDismissDirection; DismissDirection reportedDismissDirection;
List<int> dismissedItems = <int>[]; List<int> dismissedItems = <int>[];
Widget background;
void handleOnResize(int item) { void handleOnResize(int item) {
expect(dismissedItems.contains(item), isFalse); expect(dismissedItems.contains(item), isFalse);
...@@ -29,6 +30,7 @@ Widget buildDismissableItem(int item) { ...@@ -29,6 +30,7 @@ Widget buildDismissableItem(int item) {
direction: dismissDirection, direction: dismissDirection,
onDismissed: (DismissDirection direction) { handleOnDismissed(direction, item); }, onDismissed: (DismissDirection direction) { handleOnDismissed(direction, item); },
onResize: () { handleOnResize(item); }, onResize: () { handleOnResize(item); },
background: background,
child: new Container( child: new Container(
width: itemExtent, width: itemExtent,
height: itemExtent, height: itemExtent,
...@@ -123,11 +125,15 @@ class Test1215DismissableWidget extends StatelessWidget { ...@@ -123,11 +125,15 @@ class Test1215DismissableWidget extends StatelessWidget {
} }
void main() { void main() {
setUp(() {
dismissedItems = <int>[];
background = null;
});
test('Horizontal drag triggers dismiss scrollDirection=vertical', () { test('Horizontal drag triggers dismiss scrollDirection=vertical', () {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.vertical; scrollDirection = Axis.vertical;
dismissDirection = DismissDirection.horizontal; dismissDirection = DismissDirection.horizontal;
dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
...@@ -148,7 +154,6 @@ void main() { ...@@ -148,7 +154,6 @@ void main() {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.horizontal; scrollDirection = Axis.horizontal;
dismissDirection = DismissDirection.vertical; dismissDirection = DismissDirection.vertical;
dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
...@@ -169,7 +174,6 @@ void main() { ...@@ -169,7 +174,6 @@ void main() {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.vertical; scrollDirection = Axis.vertical;
dismissDirection = DismissDirection.endToStart; dismissDirection = DismissDirection.endToStart;
dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
...@@ -190,7 +194,6 @@ void main() { ...@@ -190,7 +194,6 @@ void main() {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.vertical; scrollDirection = Axis.vertical;
dismissDirection = DismissDirection.startToEnd; dismissDirection = DismissDirection.startToEnd;
dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
...@@ -209,7 +212,6 @@ void main() { ...@@ -209,7 +212,6 @@ void main() {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.horizontal; scrollDirection = Axis.horizontal;
dismissDirection = DismissDirection.up; dismissDirection = DismissDirection.up;
dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
...@@ -228,7 +230,6 @@ void main() { ...@@ -228,7 +230,6 @@ void main() {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.horizontal; scrollDirection = Axis.horizontal;
dismissDirection = DismissDirection.down; dismissDirection = DismissDirection.down;
dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty); expect(dismissedItems, isEmpty);
...@@ -253,7 +254,6 @@ void main() { ...@@ -253,7 +254,6 @@ void main() {
testWidgets((WidgetTester tester) { testWidgets((WidgetTester tester) {
scrollDirection = Axis.horizontal; scrollDirection = Axis.horizontal;
dismissDirection = DismissDirection.down; dismissDirection = DismissDirection.down;
dismissedItems = <int>[];
tester.pumpWidget(widgetBuilder()); tester.pumpWidget(widgetBuilder());
Element itemElement = tester.findText('0'); Element itemElement = tester.findText('0');
...@@ -307,4 +307,24 @@ void main() { ...@@ -307,4 +307,24 @@ void main() {
expect(tester.findText('2'), isNull); expect(tester.findText('2'), isNull);
}); });
}); });
test('Dismissable starts from the full size when collapsing', () {
testWidgets((WidgetTester tester) {
scrollDirection = Axis.vertical;
dismissDirection = DismissDirection.horizontal;
background = new Text('background');
tester.pumpWidget(widgetBuilder());
expect(dismissedItems, isEmpty);
Element itemElement = tester.findText(0.toString());
expect(itemElement, isNotNull);
dismissElement(tester, itemElement, gestureDirection: DismissDirection.startToEnd);
tester.pump();
Element backgroundElement = tester.findText('background');
RenderBox backgroundBox = backgroundElement.findRenderObject();
expect(backgroundBox.size.height, equals(100.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