@@ -12,26 +12,28 @@ const FILTER_REPEATED_EVENTS_DELAY = 200
12
12
13
13
export default class DragRecognizer extends CoordinatesRecognizer < 'drag' > {
14
14
ingKey = 'dragging' as IngKey
15
- isTouch = false
16
15
wasTouch = false
17
16
18
17
constructor ( controller : Controller , args : any [ ] ) {
19
18
super ( 'drag' , controller , args )
20
19
}
21
20
21
+ private isEventTypeTouch = ( type ?: string ) => ! ! type && type . indexOf ( 'touch' ) === 0
22
+
22
23
private dragShouldStart = ( event : UseGestureEvent ) => {
23
24
const { touches } = getGenericEventData ( event )
24
-
25
+ const { _lastEventType } = this . state
25
26
/**
26
27
* This tries to filter out mouse events triggered by touch screens
27
28
* */
28
-
29
- this . isTouch = ! ! touches
30
-
31
29
// If the previous gesture was touch-based, and the current one is mouse based,
32
30
// this means that we might be dealing with mouse simulated events if they're close to
33
31
// each other. We're only doing this check when we're not using pointer events.
34
- if ( ! this . controller . config . pointer && this . wasTouch && ! this . isTouch ) {
32
+ if (
33
+ ! this . controller . config . pointer &&
34
+ this . isEventTypeTouch ( _lastEventType ) &&
35
+ ! this . isEventTypeTouch ( event . type )
36
+ ) {
35
37
const delay = Math . abs ( event . timeStamp - this . state . startTime )
36
38
if ( delay < FILTER_REPEATED_EVENTS_DELAY ) return false
37
39
}
@@ -50,9 +52,9 @@ export default class DragRecognizer extends CoordinatesRecognizer<'drag'> {
50
52
if ( currentTarget && pointerId ) currentTarget . releasePointerCapture ( pointerId )
51
53
}
52
54
53
- private setListeners = ( ) => {
55
+ private setListeners = ( isTouch : boolean ) => {
54
56
this . removeWindowListeners ( )
55
- const dragListeners : [ string , Fn ] [ ] = this . isTouch
57
+ const dragListeners : [ string , Fn ] [ ] = isTouch
56
58
? [
57
59
[ 'touchmove' , this . onDragChange ] ,
58
60
[ 'touchend' , this . onDragEnd ] ,
@@ -68,8 +70,8 @@ export default class DragRecognizer extends CoordinatesRecognizer<'drag'> {
68
70
onDragStart = ( event : UseGestureEvent ) : void => {
69
71
if ( ! this . dragShouldStart ( event ) ) return
70
72
// if pointers events
71
- else this . setListeners ( )
72
73
if ( this . controller . config . pointer ) this . setPointers ( event as PointerEvent )
74
+ else this . setListeners ( this . isEventTypeTouch ( event . type ) )
73
75
74
76
if ( this . config . delay > 0 ) {
75
77
this . state . _delayedEvent = true
@@ -178,8 +180,6 @@ export default class DragRecognizer extends CoordinatesRecognizer<'drag'> {
178
180
clean = ( ) : void => {
179
181
super . clean ( )
180
182
this . state . _delayedEvent = false
181
- this . wasTouch = this . isTouch
182
- this . isTouch = false
183
183
184
184
if ( this . controller . config . pointer ) this . removePointers ( )
185
185
}
0 commit comments