Commit 639f9d9b authored by Hans Muller's avatar Hans Muller

Finish converting Dismissable from Listener to GestureDetector

Dismissable now only depends on GestureDetector.

Added a unit test that verifies that issue #1068 has been fixed. It's commented out for now.

Cleaned up VelocityTracker.cc et al a little.
parent 63101e49
......@@ -24,9 +24,6 @@ typedef void GesturePanEndCallback(sky.Offset velocity);
typedef void _GesturePolymorphicUpdateCallback<T>(T scrollDelta);
// Fling velocities are logical pixels per second.
typedef void GestureFlingCallback(sky.Offset velocity);
int _eventTime(sky.PointerEvent event) => (event.timeStamp * 1000.0).toInt(); // microseconds
bool _isFlingGesture(sky.GestureVelocity velocity) {
......
......@@ -155,19 +155,9 @@ class Dismissable extends StatefulComponent {
_fadePerformance.progress = _dragExtent.abs() / (_size.width * _kDismissCardThreshold);
}
void _handleDragEnd(Offset velocity) {
if (!_isActive || _fadePerformance.isAnimating)
return;
_dragUnderway = false;
if (_fadePerformance.isCompleted)
_startResizePerformance();
else if (!_fadePerformance.isAnimating)
_fadePerformance.reverse();
}
bool _isFlingGesture(sky.GestureEvent event) {
double vx = event.velocityX;
double vy = event.velocityY;
bool _isFlingGesture(sky.Offset velocity) {
double vx = velocity.dx;
double vy = velocity.dy;
if (_directionIsYAxis) {
if (vy.abs() - vx.abs() < _kMinFlingVelocityDelta)
return false;
......@@ -194,22 +184,20 @@ class Dismissable extends StatefulComponent {
return false;
}
EventDisposition _handleFlingStart(sky.GestureEvent event) {
if (!_isActive)
return EventDisposition.ignored;
void _handleDragEnd(sky.Offset velocity) {
if (!_isActive || _fadePerformance.isAnimating)
return;
_dragUnderway = false;
if (_fadePerformance.isCompleted) { // drag then fling
if (_fadePerformance.isCompleted) {
_startResizePerformance();
} else if (_isFlingGesture(event)) {
double velocity = _directionIsYAxis ? event.velocityY : event.velocityX;
_dragExtent = velocity.sign;
_fadePerformance.fling(velocity: velocity.abs() * _kFlingVelocityScale);
} else if (_isFlingGesture(velocity)) {
double flingVelocity = _directionIsYAxis ? velocity.dy : velocity.dx;
_dragExtent = flingVelocity.sign;
_fadePerformance.fling(velocity: flingVelocity.abs() * _kFlingVelocityScale);
} else {
_fadePerformance.reverse();
}
return EventDisposition.processed;
}
void _handleSizeChanged(Size newSize) {
......@@ -242,19 +230,16 @@ class Dismissable extends StatefulComponent {
onVerticalDragStart: _directionIsYAxis ? _handleDragStart : null,
onVerticalDragUpdate: _directionIsYAxis ? _handleDragUpdate : null,
onVerticalDragEnd: _directionIsYAxis ? _handleDragEnd : null,
child: new Listener(
onGestureFlingStart: _handleFlingStart,
child: new SizeObserver(
callback: _handleSizeChanged,
child: new FadeTransition(
child: new SizeObserver(
callback: _handleSizeChanged,
child: new FadeTransition(
performance: _fadePerformance,
onCompleted: _handleFadeCompleted,
opacity: new AnimatedValue<double>(1.0, end: 0.0),
child: new SlideTransition(
performance: _fadePerformance,
onCompleted: _handleFadeCompleted,
opacity: new AnimatedValue<double>(1.0, end: 0.0),
child: new SlideTransition(
performance: _fadePerformance,
position: new AnimatedValue<Point>(Point.origin, end: _activeCardDragEndPoint),
child: child
)
position: new AnimatedValue<Point>(Point.origin, end: _activeCardDragEndPoint),
child: child
)
)
)
......
......@@ -204,4 +204,30 @@ void main() {
expect(tester.findText('0'), isNull);
expect(dismissedItems, equals([0]));
});
// This is a regression test for
// https://github.com/domokit/sky_engine/issues/1068
/*
test('Verify that drag-move events do not assert', () {
WidgetTester tester = new WidgetTester();
scrollDirection = ScrollDirection.horizontal;
dismissDirection = DismissDirection.down;
tester.pumpFrame(widgetBuilder);
Widget itemWidget = tester.findText('0');
TestPointer pointer = new TestPointer(5);
Point location = tester.getTopLeft(itemWidget);
Offset offset = new Offset(0.0, 5.0);
tester.dispatchEvent(pointer.down(location), location);
tester.dispatchEvent(pointer.move(location + offset), location);
tester.pumpFrame(widgetBuilder);
tester.dispatchEvent(pointer.move(location + (offset * 2.0)), location);
tester.pumpFrame(widgetBuilder);
tester.dispatchEvent(pointer.move(location + (offset * 3.0)), location);
tester.pumpFrame(widgetBuilder);
tester.dispatchEvent(pointer.move(location + (offset * 4.0)), location);
tester.pumpFrame(widgetBuilder);
});
*/
}
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