Fix bug in LongPressGestureRecognizer (#81340)

It was incorrectly resetting state when it received a
non-allowed pointer but had already accepted a gesture.

https://github.com/flutter/flutter/issues/81339
This commit is contained in:
Todd Volkert 2021-04-28 09:11:13 -07:00 committed by GitHub
parent 8ddfc80c7f
commit 4e7c052b63
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -463,6 +463,13 @@ abstract class PrimaryPointerGestureRecognizer extends OneSequenceGestureRecogni
}
}
@override
void handleNonAllowedPointer(PointerDownEvent event) {
if (!_gestureAccepted) {
super.handleNonAllowedPointer(event);
}
}
@override
void handleEvent(PointerEvent event) {
assert(state != GestureRecognizerState.ready);

View File

@ -288,6 +288,29 @@ void main() {
longPress.dispose();
});
testGesture('non-allowed pointer does not inadvertently reset the recognizer', (GestureTester tester) {
longPress = LongPressGestureRecognizer(kind: PointerDeviceKind.touch)..onLongPress = () {};
// Accept a long-press gesture
longPress.addPointer(down);
tester.closeArena(5);
tester.route(down);
tester.async.elapse(const Duration(milliseconds: 500));
// Add a non-allowed pointer (doesn't match the kind filter)
longPress.addPointer(const PointerDownEvent(
pointer: 101,
kind: PointerDeviceKind.mouse,
position: Offset(10, 10),
));
// Moving the primary pointer should result in a normal event
tester.route(const PointerMoveEvent(
pointer: 5,
position: Offset(15, 15),
));
});
});
group('long press drag', () {