Unverified Commit fbefd6b8 authored by Tong Mu's avatar Tong Mu Committed by GitHub

Simplify logic of TapGestureRecognizer (#30227)

Refactors the logic of TapGestureRecognizer, making the calling dependency unidirectional between resolve(accept) and checkUp.
parent 14aa57b1
......@@ -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)
......
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