Commit ef023286 authored by Hans Muller's avatar Hans Muller

Merge pull request #1045 from HansMuller/scroll-dismiss-corner-cases

Fix minor problems in _ScrollGestureRecognizer, Dismissable, lerpColor

Alternating scroll gestures would sometimes be ignored because _ScrollGestureRecognizer didn't always reset its _state when the pointer[s] went up.

A Dismissable dismiss triggered by a drag and then a fling could cause the next attempt to drag-dismiss to fail.

Fixed the definition of lerpColor().
parents 8c958f97 952e7358
...@@ -78,6 +78,7 @@ abstract class _ScrollGestureRecognizer<T extends dynamic> extends GestureRecogn ...@@ -78,6 +78,7 @@ abstract class _ScrollGestureRecognizer<T extends dynamic> extends GestureRecogn
void didStopTrackingLastPointer() { void didStopTrackingLastPointer() {
if (_state == ScrollState.possible) { if (_state == ScrollState.possible) {
resolve(GestureDisposition.rejected); resolve(GestureDisposition.rejected);
_state = ScrollState.ready;
return; return;
} }
bool wasAccepted = (_state == ScrollState.accepted); bool wasAccepted = (_state == ScrollState.accepted);
......
...@@ -18,7 +18,7 @@ final Interval _kCardDismissResizeInterval = new Interval(0.4, 1.0); ...@@ -18,7 +18,7 @@ final Interval _kCardDismissResizeInterval = new Interval(0.4, 1.0);
const double _kMinFlingVelocity = 700.0; const double _kMinFlingVelocity = 700.0;
const double _kMinFlingVelocityDelta = 400.0; const double _kMinFlingVelocityDelta = 400.0;
const double _kFlingVelocityScale = 1.0 / 300.0; const double _kFlingVelocityScale = 1.0 / 300.0;
const double _kDismissCardThreshold = 0.6; const double _kDismissCardThreshold = 0.4;
typedef void ResizedCallback(); typedef void ResizedCallback();
typedef void DismissedCallback(); typedef void DismissedCallback();
...@@ -140,11 +140,10 @@ class Dismissable extends StatefulComponent { ...@@ -140,11 +140,10 @@ class Dismissable extends StatefulComponent {
return EventDisposition.ignored; return EventDisposition.ignored;
_dragUnderway = false; _dragUnderway = false;
if (_isHorizontalFlingGesture(event)) { if (_fadePerformance.isCompleted) { // drag then fling
_dragX = event.velocityX.sign;
if (_fadePerformance.isCompleted)
_startResizePerformance(); _startResizePerformance();
else } else if (_isHorizontalFlingGesture(event)) {
_dragX = event.velocityX.sign;
_fadePerformance.fling(velocity: event.velocityX.abs() * _kFlingVelocityScale); _fadePerformance.fling(velocity: event.velocityX.abs() * _kFlingVelocityScale);
} else { } else {
_fadePerformance.reverse(); _fadePerformance.reverse();
......
...@@ -187,8 +187,7 @@ class GestureDetector extends StatefulComponent { ...@@ -187,8 +187,7 @@ class GestureDetector extends StatefulComponent {
} }
GestureRecognizer _ensureDisposed(GestureRecognizer recognizer) { GestureRecognizer _ensureDisposed(GestureRecognizer recognizer) {
if (recognizer != null) recognizer?.dispose();
recognizer.dispose();
return null; return null;
} }
......
...@@ -41,13 +41,13 @@ void main() { ...@@ -41,13 +41,13 @@ void main() {
expect(didEndScroll, isFalse); expect(didEndScroll, isFalse);
Point secondLocation = new Point(10.0, 9.0); Point secondLocation = new Point(10.0, 9.0);
tester.dispatchEvent(pointer.move(secondLocation), secondLocation); tester.dispatchEvent(pointer.move(secondLocation), firstLocation);
expect(didStartScroll, isFalse); expect(didStartScroll, isFalse);
expect(updatedScrollDelta, 1.0); expect(updatedScrollDelta, 1.0);
updatedScrollDelta = null; updatedScrollDelta = null;
expect(didEndScroll, isFalse); expect(didEndScroll, isFalse);
tester.dispatchEvent(pointer.up(), secondLocation); tester.dispatchEvent(pointer.up(), firstLocation);
expect(didStartScroll, isFalse); expect(didStartScroll, isFalse);
expect(updatedScrollDelta, isNull); expect(updatedScrollDelta, isNull);
expect(didEndScroll, isTrue); expect(didEndScroll, isTrue);
...@@ -55,4 +55,37 @@ void main() { ...@@ -55,4 +55,37 @@ void main() {
tester.pumpFrame(() => new Container()); tester.pumpFrame(() => new Container());
}); });
test('Match two scroll gestures in succession', () {
WidgetTester tester = new WidgetTester();
TestPointer pointer = new TestPointer(7);
int gestureCount = 0;
double dragDistance = 0.0;
Point downLocation = new Point(10.0, 10.0);
Point upLocation = new Point(10.0, 20.0);
Widget builder() {
return new GestureDetector(
onVerticalScrollUpdate: (double delta) { dragDistance += delta; },
onVerticalScrollEnd: () { gestureCount += 1; },
onHorizontalScrollUpdate: (_) { fail("gesture should not match"); },
onHorizontalScrollEnd: () { fail("gesture should not match"); },
child: new Container()
);
}
tester.pumpFrame(builder);
tester.dispatchEvent(pointer.down(downLocation), downLocation);
tester.dispatchEvent(pointer.move(upLocation), downLocation);
tester.dispatchEvent(pointer.up(), downLocation);
tester.dispatchEvent(pointer.down(downLocation), downLocation);
tester.dispatchEvent(pointer.move(upLocation), downLocation);
tester.dispatchEvent(pointer.up(), downLocation);
expect(gestureCount, 2);
expect(dragDistance, -20.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