Skip to content

Commit

Permalink
Short-circuit _checkUp if tap callbacks were triggered by resolve.
Browse files Browse the repository at this point in the history
In some scenarios this was leading to double invocation of the tap
callbacks.
See detailed description in flutter#12470.
  • Loading branch information
Amir Hardon committed Oct 13, 2017
1 parent f5c6c5c commit fd91435
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/flutter/lib/src/gestures/tap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
if (event is PointerUpEvent) {
_finalPosition = event.position;
_checkUp();
} else if (event is PointerCancelEvent) {
_reset();
}
}

Expand Down Expand Up @@ -143,9 +145,16 @@ class TapGestureRecognizer extends PrimaryPointerGestureRecognizer {
void _checkUp() {
if (_wonArenaForPrimaryPointer && _finalPosition != null) {
resolve(GestureDisposition.accepted);
if (!_wonArenaForPrimaryPointer) {
// It is possible that resolve has just recursively called _checkUp (see #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 (onTapUp != null)
invokeCallback<Null>('onTapUp', () { onTapUp(new TapUpDetails(globalPosition: _finalPosition)); });
if (onTap != null)
if (onTap != null)
invokeCallback<Null>('onTap', onTap);
_reset();
}
Expand Down

0 comments on commit fd91435

Please sign in to comment.