Unverified Commit 2db0c25f authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Dismissible RTL (#13137)

Fix the dismissible demo in the gallery (make it actuall update when you pick something from its menu; give it a better affordance for resetting once you've dismissed everything).

Improve some docs.

Fix various flinging bugs with dismissible. Add tests for those cases.

Add a feature to flutter_test to support a drag-then-fling gesture (used by the flinging tests).
parent e6119282
...@@ -60,6 +60,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> { ...@@ -60,6 +60,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
} }
void handleDemoAction(LeaveBehindDemoAction action) { void handleDemoAction(LeaveBehindDemoAction action) {
setState(() {
switch (action) { switch (action) {
case LeaveBehindDemoAction.reset: case LeaveBehindDemoAction.reset:
initListItems(); initListItems();
...@@ -74,6 +75,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> { ...@@ -74,6 +75,7 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
_dismissDirection = DismissDirection.startToEnd; _dismissDirection = DismissDirection.startToEnd;
break; break;
} }
});
} }
void handleUndo(LeaveBehindItem item) { void handleUndo(LeaveBehindItem item) {
...@@ -161,9 +163,16 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> { ...@@ -161,9 +163,16 @@ class LeaveBehindDemoState extends State<LeaveBehindDemo> {
) )
] ]
), ),
body: new ListView( body: leaveBehindItems.isEmpty
children: leaveBehindItems.map(buildItem).toList() ? new Center(
child: new RaisedButton(
onPressed: () => handleDemoAction(LeaveBehindDemoAction.reset),
child: const Text('Reset the list'),
),
) )
: new ListView(
children: leaveBehindItems.map(buildItem).toList()
),
); );
} }
} }
...@@ -299,11 +299,28 @@ class WidgetController { ...@@ -299,11 +299,28 @@ class WidgetController {
/// ///
/// A fling is essentially a drag that ends at a particular speed. If you /// A fling is essentially a drag that ends at a particular speed. If you
/// just want to drag and end without a fling, use [drag]. /// just want to drag and end without a fling, use [drag].
///
/// The `initialOffset` argument, if non-zero, causes the pointer to first
/// apply that offset, then pump a delay of `initialOffsetDelay`. This can be
/// used to simulate a drag followed by a fling, including dragging in the
/// opposite direction of the fling (e.g. dragging 200 pixels to the right,
/// then fling to the left over 200 pixels, ending at the exact point that the
/// drag started).
Future<Null> fling(Finder finder, Offset offset, double speed, { Future<Null> fling(Finder finder, Offset offset, double speed, {
int pointer, int pointer,
Duration frameInterval: const Duration(milliseconds: 16), Duration frameInterval: const Duration(milliseconds: 16),
Offset initialOffset: Offset.zero,
Duration initialOffsetDelay: const Duration(seconds: 1),
}) { }) {
return flingFrom(getCenter(finder), offset, speed, pointer: pointer, frameInterval: frameInterval); return flingFrom(
getCenter(finder),
offset,
speed,
pointer: pointer,
frameInterval: frameInterval,
initialOffset: initialOffset,
initialOffsetDelay: initialOffsetDelay,
);
} }
/// Attempts a fling gesture starting from the given location, moving the /// Attempts a fling gesture starting from the given location, moving the
...@@ -324,7 +341,19 @@ class WidgetController { ...@@ -324,7 +341,19 @@ class WidgetController {
/// ///
/// A fling is essentially a drag that ends at a particular speed. If you /// A fling is essentially a drag that ends at a particular speed. If you
/// just want to drag and end without a fling, use [dragFrom]. /// just want to drag and end without a fling, use [dragFrom].
Future<Null> flingFrom(Offset startLocation, Offset offset, double speed, { int pointer, Duration frameInterval: const Duration(milliseconds: 16) }) { ///
/// The `initialOffset` argument, if non-zero, causes the pointer to first
/// apply that offset, then pump a delay of `initialOffsetDelay`. This can be
/// used to simulate a drag followed by a fling, including dragging in the
/// opposite direction of the fling (e.g. dragging 200 pixels to the right,
/// then fling to the left over 200 pixels, ending at the exact point that the
/// drag started).
Future<Null> flingFrom(Offset startLocation, Offset offset, double speed, {
int pointer,
Duration frameInterval: const Duration(milliseconds: 16),
Offset initialOffset: Offset.zero,
Duration initialOffsetDelay: const Duration(seconds: 1),
}) {
assert(offset.distance > 0.0); assert(offset.distance > 0.0);
assert(speed > 0.0); // speed is pixels/second assert(speed > 0.0); // speed is pixels/second
return TestAsyncUtils.guard(() async { return TestAsyncUtils.guard(() async {
...@@ -335,8 +364,13 @@ class WidgetController { ...@@ -335,8 +364,13 @@ class WidgetController {
double timeStamp = 0.0; double timeStamp = 0.0;
double lastTimeStamp = timeStamp; double lastTimeStamp = timeStamp;
await sendEventToBinding(testPointer.down(startLocation, timeStamp: new Duration(milliseconds: timeStamp.round())), result); await sendEventToBinding(testPointer.down(startLocation, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
if (initialOffset.distance > 0.0) {
await sendEventToBinding(testPointer.move(startLocation + initialOffset, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
timeStamp += initialOffsetDelay.inMilliseconds;
await pump(initialOffsetDelay);
}
for (int i = 0; i <= kMoveCount; i += 1) { for (int i = 0; i <= kMoveCount; i += 1) {
final Offset location = startLocation + Offset.lerp(Offset.zero, offset, i / kMoveCount); final Offset location = startLocation + initialOffset + Offset.lerp(Offset.zero, offset, i / kMoveCount);
await sendEventToBinding(testPointer.move(location, timeStamp: new Duration(milliseconds: timeStamp.round())), result); await sendEventToBinding(testPointer.move(location, timeStamp: new Duration(milliseconds: timeStamp.round())), result);
timeStamp += timeStampDelta; timeStamp += timeStampDelta;
if (timeStamp - lastTimeStamp > frameInterval.inMilliseconds) { if (timeStamp - lastTimeStamp > frameInterval.inMilliseconds) {
......
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