Skip to content

Commit fbefd6b

Browse files
authored
Simplify logic of TapGestureRecognizer (flutter#30227)
Refactors the logic of TapGestureRecognizer, making the calling dependency unidirectional between resolve(accept) and checkUp.
1 parent 14aa57b commit fbefd6b

File tree

1 file changed

+5
-11
lines changed
  • packages/flutter/lib/src/gestures

1 file changed

+5
-11
lines changed

packages/flutter/lib/src/gestures/tap.dart

+5-11
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
172172
void handlePrimaryPointer(PointerEvent event) {
173173
if (event is PointerUpEvent) {
174174
_finalPosition = event.position;
175-
_checkUp();
175+
if (_wonArenaForPrimaryPointer) {
176+
resolve(GestureDisposition.accepted);
177+
_checkUp();
178+
}
176179
} else if (event is PointerCancelEvent) {
177180
if (_sentTapDown && onTapCancel != null) {
178181
invokeCallback<void>('onTapCancel', onTapCancel);
@@ -230,16 +233,7 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
230233
}
231234

232235
void _checkUp() {
233-
if (_wonArenaForPrimaryPointer && _finalPosition != null) {
234-
resolve(GestureDisposition.accepted);
235-
if (!_wonArenaForPrimaryPointer || _finalPosition == null) {
236-
// It is possible that resolve has just recursively called _checkUp
237-
// (see https://github.com/flutter/flutter/issues/12470).
238-
// In that case _wonArenaForPrimaryPointer will be false (as _checkUp
239-
// calls _reset) and we return here to avoid double invocation of the
240-
// tap callbacks.
241-
return;
242-
}
236+
if (_finalPosition != null) {
243237
if (onTapUp != null)
244238
invokeCallback<void>('onTapUp', () { onTapUp(TapUpDetails(globalPosition: _finalPosition)); });
245239
if (onTap != null)

0 commit comments

Comments
 (0)