Unverified Commit cd0f15a7 authored by Renzo Olivares's avatar Renzo Olivares Committed by GitHub

Add support for double tap and drag for text selection (#109573)

* Replace PanGestureRecognizer in TextSelection with TapAndDragGestureRecognizer

* add tracking of _DragState to new tap_and_drag recognizer and remove some legacy double tap code from text_selection.dart and add logs"

* add dragTapCount, a tap count that is persistent for an entire drag and is set to null on drag end vs the regular tap count which is reset on a timer

* basic double tap to drag functionality and add a local dragTapCount in text_selection.dart to use with the timer callback

* Add offsetFromOrigin and localOffsetFromOrigin to DragUpdateDetails similar to LongPressMoveUpdateDetails, eliminates the need to hold the state of lastDragStartDetails

* make a generic baselongpressgesturerecognizer

* Revert "make a generic baselongpressgesturerecognizer"

This reverts commit aad8f7433bd01e4cd016d527af832c3b1f15fac5.

* rename tap_and_drag to selection_recognizers

* add mixin for consecutivetap

* tap and long press gesture recognizer

* Revert "Revert "make a generic baselongpressgesturerecognizer""

This reverts commit 181350c36718f644eada3e45c1b7b5939f90a340.

* Revert "Revert "Revert "make a generic baselongpressgesturerecognizer"""

This reverts commit 4d69775967858dfd66dd9429e1713da598908a85.

* Add support for secondary button clicks on drag gesture recognizer and separate drag end and tap up callback

* get test running

* rename tapCount to consecutiveTapCount

* dispose timer properly

* add some comments to tests

* Add comments

* Make ConsecutiveTapMixin private and move logic to increment tap count into mixin

* stop tracking pointer when gesture is rejected and detect drags on touch devices

* onCancel for TapAndDrag

* have the TapAndDragGestureRecognizer handle tap downs and tap ups on touch and mouse devices

* add drag to move cursor for android and iOS, and pointer device kind to DragUpdateDetails

* get tests running

* refactor TapAndDragGestureRecognizer moving some logic into _check methods

* Handle cancel properly on TapAndDragGestureRecognizer, having both onTapCancel and onDragCancel, also fix tests

* Fix test mouse drag selects and cannot drag cursor, save _initialPosition based on dragStartBehavior (either on tapDown or dragStart)

* determine if drag has a sufficient global distance to accept and fix some cancel behavior, making _checkCancel clearer

* give up pointer on drag end

* properly stop tracking pointer, fixes test for right click on Apple and non-apple platforms

* clean up some comments from last commit

* remove drag on touch for now

* fix Can select text by dragging with a mouse due to dragStart only being fired on the first PointerMoveEvent, the previous pan gesture recognizer would fire both dragStart and dragUpdate

* Revert "fix Can select text by dragging with a mouse due to dragStart only being fired on the first PointerMoveEvent, the previous pan gesture recognizer would fire both dragStart and dragUpdate"

This reverts commit 124dc79bc3389672c76d7c014ce04edab297abc6.

* correctly use _initialPosition for checkStart and call _checkUpdate after _checkStart if localDelta is not zero

* updates

* fix double tap chains

* Add docs

* Address analyzer

* more analyzer, only issues left are with print statements

* add deadlineTimer to fix conflict with ForcePressGestureRecognizer

* Revert "add deadlineTimer to fix conflict with ForcePressGestureRecognizer"

This reverts commit 3b29ddfff4cde4845edd481ecefb789fea2a0781.

* remove unecessary changes to tests

* secondaryButton should not drag

* Revert "Revert "add deadlineTimer to fix conflict with ForcePressGestureRecognizer""

This reverts commit 0a008f029f5796acd48c17c1897c0b700d5ef3a7.

* updates

* Revert "updates"

This reverts commit 4803b8443a2b67f0b8d29e9a01f712dfcb0f588c.

* Revert "Revert "Revert "add deadlineTimer to fix conflict with ForcePressGestureRecognizer"""

This reverts commit 79251a7af88d5dbb1460a960afc77e65dea18bff.

* fix shift + tap + drag tests, this was happening because a double tap + drag was being registered and not a single tap, added a duration to pumpAndSettle to fix this

* remove TapAndLongPressGestureRecognizer

* fix cupertino text field tests related to shift + tap + drag

* deadline timer try 2

* more logs

* Should reset taps when tap cancel is called, and should wait until gesture is accepted to initiate a drag

* should clear _down and _up when gesture is rejected

* remove erroneous log

* fix selectable text double tap chains test

* dont restart timer until tap up

* reset consecutiveTapCount on drag end

* fix selectableText test

* fix material text field tests

* reject TapAndDragGestureRecognizer when it is neither a tap nor a drag

* remove prints

* clean up

* shift aware

* clean up

* fix cupertino test

* fix text field focus tests

* Add 100ms delay to cupertino test, to prevent a double tap

* clean up test comments

* add comment to test

* uncomment test

* remove longpress changes

* Fix drag on mobile

* remove debug

* Fix drag to move cursor on iOS

* left over from drag fix

* add tests for drag on touch devices

* add test for double tap + drag mouse devices

* add tests

* Fix bug where initialPosition was used before it was set

* Address some review comments and fix issue where if double tap was held too long then long press gesture recognizer would take over

* remove _isDoubleTap flag since it is no longer needed due to previous commit

* Add docs for onTapCancel and onDragCancel

* analyzer fixes

* Do not test selection handles on macOS, since macOS does not support touch

* Add assert for dragStartBehavior

* add double tap + drag tests to cupertino

* use kDoubleTapTimeout instead of const Duration(milliseconds: 300) for readability

* analyzer issues

* update docs

* update more docs

* address comments

* more doc updates

* fix docs

* unused import

* fix docs

* Add more tests

* Add more tests and reject a tap up if we have exceeded the tap tolerance

* updates

* Address comments

* fix test naming

* update documentation

* move selection_recognizers to selection_gestures

* fix analyzer

* fix analyzer

* keysPressedOnDown instead of isShiftPressed

* update docs

* update docs

* Add drag update throttle to TapAndDragGestureRecognizer

* update comments

* missed from merge

* Replace _ConsecutiveTapMixin with _TapStatusTrackerMixin

* updates

* correctly cancel tap when when past tap tolerance with new implementation

* Should call tap and drag cancel if we are giving up a pointer without succesfully tracking a PointerUpEvent

* comments

* move pastTapTolerance to tap tracker

* move pastTapTolerance to tap tracker

* clean up check for nulls and remove use of consecutiveTapCountWhileDragging

* move call to super.acceptGesture to top

* remove print

* clean up

* Fix tests where both PanGestureRecognizer and TapAndDragGestureRecognizer lost

* clean up

* _GestureState -> _DragState

* more docs clean up

* more clean up

* Add onSecondaryTapCancel

* Add docs

* more docs

* Fix broken isPointerAllowed when attempting a right click drag - the _initialButtons is never reset

* revert debug flag

* make primaryPointer private

* Add support for upper count limit in TapAndDragGestureRecognizer, the tap counter should not be allowed to grow infinitely unless that is desired

* fix analyzer

* Use new TapDrag details objects and callbacks

* clean up docs

* clean up and add test for upperLimit

* Add docs for TapAndDragGestureRecognizer and remove some ambiguity of onStart onUpdate and onEnd parameters

* Address review comments

* analyzer fixes

* Call cancel before rejecting the gesture so we can still access _initialButtons

* Recognizer should reject any pointer differing from the original

* Revert "Recognizer should reject any pointer differing from the original"

This reverts commit afd9807480bd11e119bdd2b7d520631511973bab.

* Address reviewer comments

* Correct cancel behavior

* Fix consecutive tap + drag because _dragStart state was not being set when consecutive tap is greater than one

* Add more tests

* Add documentation on behavior with TapGestureRecognizer and DragGestureRecognizer

* more docs

* more docs

* remove comments

* updates

* fix multiple pointer behavior

* only handle the primary pointer

* Clean up dangerous assumptions in gesture details objects

* forgot from rebase

* update docs

* updates

* Clean up some redundant code

* remove whitespace

* fix tests as a result of #115849

* update test docs

* Fix same test from last commit for material variants

* More clean up of redundant code and update docs

* Clean up didStopTrackingLastPointer and untie TapAndDragGestureRecognizer cancel behavior from TapStatusTrackerMixin.currentUp state

* untie pastTapTolerance

* updates

* Add slopTolerance

* update docs

* Have secondary tap handled by TapGestureRecognizer

* update docs

* fix analyzer and address comments

* Add more docs

* Update cancel behavior tol not call on tap cancel when a drag has been accepted

* Change cancel behavior to only cancel if the tap down callback has been sent and merge tapcancel and dragcancel

* update docs;

* Rename selection_gestures to tap_and_drag_gestures

* Address some reviewer comments

* make deadline and slopTolerance private

* updates

* updates

* Address review comments

* remove _initialButtons

* fix docs

* trackTrap -> trackTap

* fix analyzer

* Add test to verify that tap up is called when recognizer accepts before handleEvent is called

* implement Diagnosticable for Details objects;

* sentTapDown == wonArenaForPrimaryPointer, so the implementation now only uses sentTapDown

* Count user tap up immediately and do not wait to win the arena

* Do not need to call super from TapAndDragGestureRecognizer.acceptGesture anymore because mixin implementation is gone

* Do not start selection drag on Android, iOS, and Fuchshsia touch devices if renderEditable does not have focus, this fixes many scubas

* Address reviewer comments

* fix test

* TapAndDragGestureRecognizer should wait for other recognizer to lose before winning the arena

* Address review comments

* Dont check for drag if the start was already found

* Only check for a drag if it has not already been found"

* fix from rebase
Co-authored-by: 's avatarRenzo Olivares <roliv@google.com>
parent 014b8f73
...@@ -102,7 +102,7 @@ class _CupertinoTextFieldSelectionGestureDetectorBuilder extends TextSelectionGe ...@@ -102,7 +102,7 @@ class _CupertinoTextFieldSelectionGestureDetectorBuilder extends TextSelectionGe
final _CupertinoTextFieldState _state; final _CupertinoTextFieldState _state;
@override @override
void onSingleTapUp(TapUpDetails details) { void onSingleTapUp(TapDragUpDetails details) {
// Because TextSelectionGestureDetector listens to taps that happen on // Because TextSelectionGestureDetector listens to taps that happen on
// widgets in front of it, tapping the clear button will also trigger // widgets in front of it, tapping the clear button will also trigger
// this handler. If the clear button widget recognizes the up event, // this handler. If the clear button widget recognizes the up event,
...@@ -120,7 +120,7 @@ class _CupertinoTextFieldSelectionGestureDetectorBuilder extends TextSelectionGe ...@@ -120,7 +120,7 @@ class _CupertinoTextFieldSelectionGestureDetectorBuilder extends TextSelectionGe
} }
@override @override
void onDragSelectionEnd(DragEndDetails details) { void onDragSelectionEnd(TapDragEndDetails details) {
_state._requestKeyboard(); _state._requestKeyboard();
} }
} }
......
...@@ -109,10 +109,12 @@ class DragStartDetails { ...@@ -109,10 +109,12 @@ class DragStartDetails {
String toString() => '${objectRuntimeType(this, 'DragStartDetails')}($globalPosition)'; String toString() => '${objectRuntimeType(this, 'DragStartDetails')}($globalPosition)';
} }
/// {@template flutter.gestures.dragdetails.GestureDragStartCallback}
/// Signature for when a pointer has contacted the screen and has begun to move. /// Signature for when a pointer has contacted the screen and has begun to move.
/// ///
/// The `details` object provides the position of the touch when it first /// The `details` object provides the position of the touch when it first
/// touched the surface. /// touched the surface.
/// {@endtemplate}
/// ///
/// See [DragGestureRecognizer.onStart]. /// See [DragGestureRecognizer.onStart].
typedef GestureDragStartCallback = void Function(DragStartDetails details); typedef GestureDragStartCallback = void Function(DragStartDetails details);
...@@ -126,7 +128,7 @@ typedef GestureDragStartCallback = void Function(DragStartDetails details); ...@@ -126,7 +128,7 @@ typedef GestureDragStartCallback = void Function(DragStartDetails details);
/// * [DragStartDetails], the details for [GestureDragStartCallback]. /// * [DragStartDetails], the details for [GestureDragStartCallback].
/// * [DragEndDetails], the details for [GestureDragEndCallback]. /// * [DragEndDetails], the details for [GestureDragEndCallback].
class DragUpdateDetails { class DragUpdateDetails {
/// Creates details for a [DragUpdateDetails]. /// Creates details for a [GestureDragUpdateCallback].
/// ///
/// The [delta] argument must not be null. /// The [delta] argument must not be null.
/// ///
...@@ -195,11 +197,13 @@ class DragUpdateDetails { ...@@ -195,11 +197,13 @@ class DragUpdateDetails {
String toString() => '${objectRuntimeType(this, 'DragUpdateDetails')}($delta)'; String toString() => '${objectRuntimeType(this, 'DragUpdateDetails')}($delta)';
} }
/// {@template flutter.gestures.dragdetails.GestureDragUpdateCallback}
/// Signature for when a pointer that is in contact with the screen and moving /// Signature for when a pointer that is in contact with the screen and moving
/// has moved again. /// has moved again.
/// ///
/// The `details` object provides the position of the touch and the distance it /// The `details` object provides the position of the touch and the distance it
/// has traveled since the last update. /// has traveled since the last update.
/// {@endtemplate}
/// ///
/// See [DragGestureRecognizer.onUpdate]. /// See [DragGestureRecognizer.onUpdate].
typedef GestureDragUpdateCallback = void Function(DragUpdateDetails details); typedef GestureDragUpdateCallback = void Function(DragUpdateDetails details);
......
...@@ -26,11 +26,13 @@ enum _DragState { ...@@ -26,11 +26,13 @@ enum _DragState {
accepted, accepted,
} }
/// {@template flutter.gestures.monodrag.GestureDragEndCallback}
/// Signature for when a pointer that was previously in contact with the screen /// Signature for when a pointer that was previously in contact with the screen
/// and moving is no longer in contact with the screen. /// and moving is no longer in contact with the screen.
/// ///
/// The velocity at which the pointer was moving when it stopped contacting /// The velocity at which the pointer was moving when it stopped contacting
/// the screen is available in the `details`. /// the screen is available in the `details`.
/// {@endtemplate}
/// ///
/// Used by [DragGestureRecognizer.onEnd]. /// Used by [DragGestureRecognizer.onEnd].
typedef GestureDragEndCallback = void Function(DragEndDetails details); typedef GestureDragEndCallback = void Function(DragEndDetails details);
...@@ -124,8 +126,10 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -124,8 +126,10 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
/// * [DragDownDetails], which is passed as an argument to this callback. /// * [DragDownDetails], which is passed as an argument to this callback.
GestureDragDownCallback? onDown; GestureDragDownCallback? onDown;
/// {@template flutter.gestures.monodrag.DragGestureRecognizer.onStart}
/// A pointer has contacted the screen with a primary button and has begun to /// A pointer has contacted the screen with a primary button and has begun to
/// move. /// move.
/// {@endtemplate}
/// ///
/// The position of the pointer is provided in the callback's `details` /// The position of the pointer is provided in the callback's `details`
/// argument, which is a [DragStartDetails] object. The [dragStartBehavior] /// argument, which is a [DragStartDetails] object. The [dragStartBehavior]
...@@ -137,8 +141,10 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -137,8 +141,10 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
/// * [DragStartDetails], which is passed as an argument to this callback. /// * [DragStartDetails], which is passed as an argument to this callback.
GestureDragStartCallback? onStart; GestureDragStartCallback? onStart;
/// {@template flutter.gestures.monodrag.DragGestureRecognizer.onUpdate}
/// A pointer that is in contact with the screen with a primary button and /// A pointer that is in contact with the screen with a primary button and
/// moving has moved again. /// moving has moved again.
/// {@endtemplate}
/// ///
/// The distance traveled by the pointer since the last update is provided in /// The distance traveled by the pointer since the last update is provided in
/// the callback's `details` argument, which is a [DragUpdateDetails] object. /// the callback's `details` argument, which is a [DragUpdateDetails] object.
...@@ -149,9 +155,11 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer { ...@@ -149,9 +155,11 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
/// * [DragUpdateDetails], which is passed as an argument to this callback. /// * [DragUpdateDetails], which is passed as an argument to this callback.
GestureDragUpdateCallback? onUpdate; GestureDragUpdateCallback? onUpdate;
/// {@template flutter.gestures.monodrag.DragGestureRecognizer.onEnd}
/// A pointer that was previously in contact with the screen with a primary /// A pointer that was previously in contact with the screen with a primary
/// button and moving is no longer in contact with the screen and was moving /// button and moving is no longer in contact with the screen and was moving
/// at a specific velocity when it stopped contacting the screen. /// at a specific velocity when it stopped contacting the screen.
/// {@endtemplate}
/// ///
/// The velocity is provided in the callback's `details` argument, which is a /// The velocity is provided in the callback's `details` argument, which is a
/// [DragEndDetails] object. /// [DragEndDetails] object.
......
...@@ -45,11 +45,13 @@ class TapDownDetails { ...@@ -45,11 +45,13 @@ class TapDownDetails {
final Offset localPosition; final Offset localPosition;
} }
/// {@template flutter.gestures.tap.GestureTapDownCallback}
/// Signature for when a pointer that might cause a tap has contacted the /// Signature for when a pointer that might cause a tap has contacted the
/// screen. /// screen.
/// ///
/// The position at which the pointer contacted the screen is available in the /// The position at which the pointer contacted the screen is available in the
/// `details`. /// `details`.
/// {@endtemplate}
/// ///
/// See also: /// See also:
/// ///
...@@ -82,11 +84,13 @@ class TapUpDetails { ...@@ -82,11 +84,13 @@ class TapUpDetails {
final PointerDeviceKind kind; final PointerDeviceKind kind;
} }
/// {@template flutter.gestures.tap.GestureTapUpCallback}
/// Signature for when a pointer that will trigger a tap has stopped contacting /// Signature for when a pointer that will trigger a tap has stopped contacting
/// the screen. /// the screen.
/// ///
/// The position at which the pointer stopped contacting the screen is available /// The position at which the pointer stopped contacting the screen is available
/// in the `details`. /// in the `details`.
/// {@endtemplate}
/// ///
/// See also: /// See also:
/// ///
...@@ -360,8 +364,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer { ...@@ -360,8 +364,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// {@macro flutter.gestures.GestureRecognizer.supportedDevices} /// {@macro flutter.gestures.GestureRecognizer.supportedDevices}
TapGestureRecognizer({ super.debugOwner, super.supportedDevices }); TapGestureRecognizer({ super.debugOwner, super.supportedDevices });
/// {@template flutter.gestures.tap.TapGestureRecognizer.onTapDown}
/// A pointer has contacted the screen at a particular location with a primary /// A pointer has contacted the screen at a particular location with a primary
/// button, which might be the start of a tap. /// button, which might be the start of a tap.
/// {@endtemplate}
/// ///
/// This triggers after the down event, once a short timeout ([deadline]) has /// This triggers after the down event, once a short timeout ([deadline]) has
/// elapsed, or once the gestures has won the arena, whichever comes first. /// elapsed, or once the gestures has won the arena, whichever comes first.
...@@ -378,8 +384,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer { ...@@ -378,8 +384,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [GestureDetector.onTapDown], which exposes this callback. /// * [GestureDetector.onTapDown], which exposes this callback.
GestureTapDownCallback? onTapDown; GestureTapDownCallback? onTapDown;
/// {@template flutter.gestures.tap.TapGestureRecognizer.onTapUp}
/// A pointer has stopped contacting the screen at a particular location, /// A pointer has stopped contacting the screen at a particular location,
/// which is recognized as a tap of a primary button. /// which is recognized as a tap of a primary button.
/// {@endtemplate}
/// ///
/// This triggers on the up event, if the recognizer wins the arena with it /// This triggers on the up event, if the recognizer wins the arena with it
/// or has previously won, immediately followed by [onTap]. /// or has previously won, immediately followed by [onTap].
...@@ -411,8 +419,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer { ...@@ -411,8 +419,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [GestureDetector.onTap], which exposes this callback. /// * [GestureDetector.onTap], which exposes this callback.
GestureTapCallback? onTap; GestureTapCallback? onTap;
/// {@template flutter.gestures.tap.TapGestureRecognizer.onTapCancel}
/// A pointer that previously triggered [onTapDown] will not end up causing /// A pointer that previously triggered [onTapDown] will not end up causing
/// a tap. /// a tap.
/// {@endtemplate}
/// ///
/// This triggers once the gesture loses the arena if [onTapDown] has /// This triggers once the gesture loses the arena if [onTapDown] has
/// previously been triggered. /// previously been triggered.
...@@ -428,8 +438,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer { ...@@ -428,8 +438,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [GestureDetector.onTapCancel], which exposes this callback. /// * [GestureDetector.onTapCancel], which exposes this callback.
GestureTapCancelCallback? onTapCancel; GestureTapCancelCallback? onTapCancel;
/// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTap}
/// A pointer has stopped contacting the screen, which is recognized as a tap /// A pointer has stopped contacting the screen, which is recognized as a tap
/// of a secondary button. /// of a secondary button.
/// {@endtemplate}
/// ///
/// This triggers on the up event, if the recognizer wins the arena with it or /// This triggers on the up event, if the recognizer wins the arena with it or
/// has previously won, immediately following [onSecondaryTapUp]. /// has previously won, immediately following [onSecondaryTapUp].
...@@ -444,8 +456,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer { ...@@ -444,8 +456,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [GestureDetector.onSecondaryTap], which exposes this callback. /// * [GestureDetector.onSecondaryTap], which exposes this callback.
GestureTapCallback? onSecondaryTap; GestureTapCallback? onSecondaryTap;
/// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTapDown}
/// A pointer has contacted the screen at a particular location with a /// A pointer has contacted the screen at a particular location with a
/// secondary button, which might be the start of a secondary tap. /// secondary button, which might be the start of a secondary tap.
/// {@endtemplate}
/// ///
/// This triggers after the down event, once a short timeout ([deadline]) has /// This triggers after the down event, once a short timeout ([deadline]) has
/// elapsed, or once the gestures has won the arena, whichever comes first. /// elapsed, or once the gestures has won the arena, whichever comes first.
...@@ -462,8 +476,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer { ...@@ -462,8 +476,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [GestureDetector.onSecondaryTapDown], which exposes this callback. /// * [GestureDetector.onSecondaryTapDown], which exposes this callback.
GestureTapDownCallback? onSecondaryTapDown; GestureTapDownCallback? onSecondaryTapDown;
/// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTapUp}
/// A pointer has stopped contacting the screen at a particular location, /// A pointer has stopped contacting the screen at a particular location,
/// which is recognized as a tap of a secondary button. /// which is recognized as a tap of a secondary button.
/// {@endtemplate}
/// ///
/// This triggers on the up event if the recognizer wins the arena with it /// This triggers on the up event if the recognizer wins the arena with it
/// or has previously won. /// or has previously won.
...@@ -482,8 +498,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer { ...@@ -482,8 +498,10 @@ class TapGestureRecognizer extends BaseTapGestureRecognizer {
/// * [GestureDetector.onSecondaryTapUp], which exposes this callback. /// * [GestureDetector.onSecondaryTapUp], which exposes this callback.
GestureTapUpCallback? onSecondaryTapUp; GestureTapUpCallback? onSecondaryTapUp;
/// {@template flutter.gestures.tap.TapGestureRecognizer.onSecondaryTapCancel}
/// A pointer that previously triggered [onSecondaryTapDown] will not end up /// A pointer that previously triggered [onSecondaryTapDown] will not end up
/// causing a tap. /// causing a tap.
/// {@endtemplate}
/// ///
/// This triggers once the gesture loses the arena if [onSecondaryTapDown] /// This triggers once the gesture loses the arena if [onSecondaryTapDown]
/// has previously been triggered. /// has previously been triggered.
......
...@@ -85,7 +85,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestur ...@@ -85,7 +85,7 @@ class _SelectableTextSelectionGestureDetectorBuilder extends TextSelectionGestur
} }
@override @override
void onSingleTapUp(TapUpDetails details) { void onSingleTapUp(TapDragUpDetails details) {
editableText.hideToolbar(); editableText.hideToolbar();
if (delegate.selectionEnabled) { if (delegate.selectionEnabled) {
switch (Theme.of(_state.context).platform) { switch (Theme.of(_state.context).platform) {
......
...@@ -65,7 +65,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete ...@@ -65,7 +65,7 @@ class _TextFieldSelectionGestureDetectorBuilder extends TextSelectionGestureDete
} }
@override @override
void onSingleTapUp(TapUpDetails details) { void onSingleTapUp(TapDragUpDetails details) {
super.onSingleTapUp(details); super.onSingleTapUp(details);
_state._requestKeyboard(); _state._requestKeyboard();
_state.widget.onTap?.call(); _state.widget.onTap?.call();
......
This diff is collapsed.
...@@ -135,6 +135,7 @@ export 'src/widgets/spacer.dart'; ...@@ -135,6 +135,7 @@ export 'src/widgets/spacer.dart';
export 'src/widgets/spell_check.dart'; export 'src/widgets/spell_check.dart';
export 'src/widgets/status_transitions.dart'; export 'src/widgets/status_transitions.dart';
export 'src/widgets/table.dart'; export 'src/widgets/table.dart';
export 'src/widgets/tap_and_drag_gestures.dart';
export 'src/widgets/tap_region.dart'; export 'src/widgets/tap_region.dart';
export 'src/widgets/text.dart'; export 'src/widgets/text.dart';
export 'src/widgets/text_editing_intents.dart'; export 'src/widgets/text_editing_intents.dart';
......
...@@ -313,7 +313,6 @@ void main() { ...@@ -313,7 +313,6 @@ void main() {
tester.route(down1); tester.route(down1);
expect(tapsRecognized, 0); expect(tapsRecognized, 0);
tester.route(up2); tester.route(up2);
expect(tapsRecognized, 0); expect(tapsRecognized, 0);
GestureBinding.instance.gestureArena.sweep(2); GestureBinding.instance.gestureArena.sweep(2);
......
...@@ -196,7 +196,7 @@ void main() { ...@@ -196,7 +196,7 @@ void main() {
final TestGesture gesture = await tester.startGesture(textFieldStart, kind: PointerDeviceKind.mouse); final TestGesture gesture = await tester.startGesture(textFieldStart, kind: PointerDeviceKind.mouse);
await tester.pump(const Duration(seconds: 2)); await tester.pump(const Duration(seconds: 2));
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle(kDoubleTapTimeout);
final FlutterError error = tester.takeException() as FlutterError; final FlutterError error = tester.takeException() as FlutterError;
expect( expect(
...@@ -3907,6 +3907,7 @@ void main() { ...@@ -3907,6 +3907,7 @@ void main() {
expect(find.byType(CupertinoButton), findsNWidgets(1)); expect(find.byType(CupertinoButton), findsNWidgets(1));
// Double tap selecting the same word somewhere else is fine. // Double tap selecting the same word somewhere else is fine.
await tester.pumpAndSettle(kDoubleTapTimeout);
await tester.tapAt(selectableTextStart + const Offset(10.0, 5.0)); await tester.tapAt(selectableTextStart + const Offset(10.0, 5.0));
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
// First tap moved the cursor. // First tap moved the cursor.
...@@ -3928,6 +3929,7 @@ void main() { ...@@ -3928,6 +3929,7 @@ void main() {
editableTextState.hideToolbar(); editableTextState.hideToolbar();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
await tester.pumpAndSettle(kDoubleTapTimeout);
await tester.tapAt(selectableTextStart + const Offset(150.0, 5.0)); await tester.tapAt(selectableTextStart + const Offset(150.0, 5.0));
await tester.pump(const Duration(milliseconds: 50)); await tester.pump(const Duration(milliseconds: 50));
// First tap moved the cursor. // First tap moved the cursor.
......
This diff is collapsed.
...@@ -25,16 +25,16 @@ void main() { ...@@ -25,16 +25,16 @@ void main() {
late int dragEndCount; late int dragEndCount;
const Offset forcePressOffset = Offset(400.0, 50.0); const Offset forcePressOffset = Offset(400.0, 50.0);
void handleTapDown(TapDownDetails details) { tapCount++; } void handleTapDown(TapDragDownDetails details) { tapCount++; }
void handleSingleTapUp(TapUpDetails details) { singleTapUpCount++; } void handleSingleTapUp(TapDragUpDetails details) { singleTapUpCount++; }
void handleSingleTapCancel() { singleTapCancelCount++; } void handleSingleTapCancel() { singleTapCancelCount++; }
void handleSingleLongTapStart(LongPressStartDetails details) { singleLongTapStartCount++; } void handleSingleLongTapStart(LongPressStartDetails details) { singleLongTapStartCount++; }
void handleDoubleTapDown(TapDownDetails details) { doubleTapDownCount++; } void handleDoubleTapDown(TapDragDownDetails details) { doubleTapDownCount++; }
void handleForcePressStart(ForcePressDetails details) { forcePressStartCount++; } void handleForcePressStart(ForcePressDetails details) { forcePressStartCount++; }
void handleForcePressEnd(ForcePressDetails details) { forcePressEndCount++; } void handleForcePressEnd(ForcePressDetails details) { forcePressEndCount++; }
void handleDragSelectionStart(DragStartDetails details) { dragStartCount++; } void handleDragSelectionStart(TapDragStartDetails details) { dragStartCount++; }
void handleDragSelectionUpdate(DragStartDetails _, DragUpdateDetails details) { dragUpdateCount++; } void handleDragSelectionUpdate(TapDragUpdateDetails details) { dragUpdateCount++; }
void handleDragSelectionEnd(DragEndDetails details) { dragEndCount++; } void handleDragSelectionEnd(TapDragEndDetails details) { dragEndCount++; }
setUp(() { setUp(() {
tapCount = 0; tapCount = 0;
...@@ -173,7 +173,12 @@ void main() { ...@@ -173,7 +173,12 @@ void main() {
await gesture.moveBy(const Offset(100, 100)); await gesture.moveBy(const Offset(100, 100));
await tester.pump(); await tester.pump();
expect(singleTapUpCount, 0); expect(singleTapUpCount, 0);
expect(tapCount, 0); // Before the move to TapAndDragGestureRecognizer the tapCount was 0 because the
// TapGestureRecognizer rejected itself when the initial pointer moved past a certain
// threshold. With TapAndDragGestureRecognizer, we have two thresholds, a normal tap
// threshold, and a drag threshold, so it is possible for the tap count to increase
// even though the original pointer has moved beyond the tap threshold.
expect(tapCount, 1);
expect(singleTapCancelCount, 0); expect(singleTapCancelCount, 0);
expect(doubleTapDownCount, 0); expect(doubleTapDownCount, 0);
expect(singleLongTapStartCount, 0); expect(singleLongTapStartCount, 0);
...@@ -181,7 +186,7 @@ void main() { ...@@ -181,7 +186,7 @@ void main() {
await gesture.up(); await gesture.up();
// Nothing else happens on up. // Nothing else happens on up.
expect(singleTapUpCount, 0); expect(singleTapUpCount, 0);
expect(tapCount, 0); expect(tapCount, 1);
expect(singleTapCancelCount, 0); expect(singleTapCancelCount, 0);
expect(doubleTapDownCount, 0); expect(doubleTapDownCount, 0);
expect(singleLongTapStartCount, 0); expect(singleLongTapStartCount, 0);
...@@ -195,7 +200,7 @@ void main() { ...@@ -195,7 +200,7 @@ void main() {
await tester.pump(); await tester.pump();
expect(singleTapUpCount, 0); expect(singleTapUpCount, 0);
expect(tapCount, 1); expect(tapCount, 1);
expect(singleTapCancelCount, 1); expect(singleTapCancelCount, 0);
expect(doubleTapDownCount, 0); expect(doubleTapDownCount, 0);
expect(singleLongTapStartCount, 0); expect(singleLongTapStartCount, 0);
}); });
...@@ -370,7 +375,7 @@ void main() { ...@@ -370,7 +375,7 @@ void main() {
expect(singleLongTapStartCount, 0); expect(singleLongTapStartCount, 0);
}); });
testWidgets('a touch drag is not recognized for text selection', (WidgetTester tester) async { testWidgets('a touch drag is recognized for text selection', (WidgetTester tester) async {
await pumpGestureDetector(tester); await pumpGestureDetector(tester);
final int pointerValue = tester.nextPointer; final int pointerValue = tester.nextPointer;
...@@ -384,11 +389,12 @@ void main() { ...@@ -384,11 +389,12 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(tapCount, 0); expect(tapCount, 1);
expect(singleTapUpCount, 0); expect(singleTapUpCount, 0);
expect(dragStartCount, 0); expect(singleTapCancelCount, 0);
expect(dragUpdateCount, 0); expect(dragStartCount, 1);
expect(dragEndCount, 0); expect(dragUpdateCount, 1);
expect(dragEndCount, 1);
}); });
testWidgets('a mouse drag is recognized for text selection', (WidgetTester tester) async { testWidgets('a mouse drag is recognized for text selection', (WidgetTester tester) async {
...@@ -406,8 +412,11 @@ void main() { ...@@ -406,8 +412,11 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
expect(tapCount, 0); // The tap and drag gesture recognizer will detect the tap down, but not the tap up.
expect(tapCount, 1);
expect(singleTapCancelCount, 0);
expect(singleTapUpCount, 0); expect(singleTapUpCount, 0);
expect(dragStartCount, 1); expect(dragStartCount, 1);
expect(dragUpdateCount, 1); expect(dragUpdateCount, 1);
expect(dragEndCount, 1); expect(dragEndCount, 1);
...@@ -428,6 +437,11 @@ void main() { ...@@ -428,6 +437,11 @@ void main() {
await gesture.up(); await gesture.up();
await tester.pumpAndSettle(); await tester.pumpAndSettle();
// The tap and drag gesture recognizer will detect the tap down, but not the tap up.
expect(tapCount, 1);
expect(singleTapCancelCount, 0);
expect(singleTapUpCount, 0);
expect(dragStartCount, 1); expect(dragStartCount, 1);
expect(dragUpdateCount, 1); expect(dragUpdateCount, 1);
expect(dragEndCount, 1); expect(dragEndCount, 1);
...@@ -746,12 +760,18 @@ void main() { ...@@ -746,12 +760,18 @@ void main() {
final Offset position = textOffsetToPosition(tester, 4); final Offset position = textOffsetToPosition(tester, 4);
await tester.tapAt(position); await tester.tapAt(position);
await tester.pump(); // Don't do a double tap drag.
await tester.pump(const Duration(milliseconds: 300));
expect(controller.selection.isCollapsed, isTrue); expect(controller.selection.isCollapsed, isTrue);
expect(controller.selection.baseOffset, 4); expect(controller.selection.baseOffset, 4);
final TestGesture gesture = await tester.startGesture(position, kind: PointerDeviceKind.mouse); final TestGesture gesture = await tester.startGesture(position, kind: PointerDeviceKind.mouse);
// Checking that double-tap was not registered.
expect(controller.selection.isCollapsed, isTrue);
expect(controller.selection.baseOffset, 4);
addTearDown(gesture.removePointer); addTearDown(gesture.removePointer);
await tester.pump(); await tester.pump();
await gesture.moveTo(textOffsetToPosition(tester, 7)); await gesture.moveTo(textOffsetToPosition(tester, 7));
......
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