Simplify logic of TapGestureRecognizer (#30227)

Refactors the logic of TapGestureRecognizer, making the calling dependency unidirectional between resolve(accept) and checkUp.
This commit is contained in:
Tong Mu 2019-04-01 10:58:30 -07:00 committed by GitHub
parent 14aa57b18d
commit fbefd6b816
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -172,7 +172,10 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
void handlePrimaryPointer(PointerEvent event) {
if (event is PointerUpEvent) {
_finalPosition = event.position;
_checkUp();
if (_wonArenaForPrimaryPointer) {
resolve(GestureDisposition.accepted);
_checkUp();
}
} else if (event is PointerCancelEvent) {
if (_sentTapDown && onTapCancel != null) {
invokeCallback<void>('onTapCancel', onTapCancel);
@ -230,16 +233,7 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
}
void _checkUp() {
if (_wonArenaForPrimaryPointer && _finalPosition != null) {
resolve(GestureDisposition.accepted);
if (!_wonArenaForPrimaryPointer || _finalPosition == null) {
// It is possible that resolve has just recursively called _checkUp
// (see https://github.com/flutter/flutter/issues/12470).
// In that case _wonArenaForPrimaryPointer will be false (as _checkUp
// calls _reset) and we return here to avoid double invocation of the
// tap callbacks.
return;
}
if (_finalPosition != null) {
if (onTapUp != null)
invokeCallback<void>('onTapUp', () { onTapUp(TapUpDetails(globalPosition: _finalPosition)); });
if (onTap != null)