mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
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:
parent
14aa57b18d
commit
fbefd6b816
@ -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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user