From fbefd6b816a846936dbba847ce85dc1ed55e3faa Mon Sep 17 00:00:00 2001 From: Tong Mu Date: Mon, 1 Apr 2019 10:58:30 -0700 Subject: [PATCH] Simplify logic of TapGestureRecognizer (#30227) Refactors the logic of TapGestureRecognizer, making the calling dependency unidirectional between resolve(accept) and checkUp. --- packages/flutter/lib/src/gestures/tap.dart | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/flutter/lib/src/gestures/tap.dart b/packages/flutter/lib/src/gestures/tap.dart index 82123507d84..d5672255ad2 100644 --- a/packages/flutter/lib/src/gestures/tap.dart +++ b/packages/flutter/lib/src/gestures/tap.dart @@ -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('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('onTapUp', () { onTapUp(TapUpDetails(globalPosition: _finalPosition)); }); if (onTap != null)