1
- import supportsPassive from '../../_util/supportsPassive' ;
2
1
import type { Ref } from 'vue' ;
3
- import { watch , onMounted } from 'vue' ;
2
+ import { onBeforeUnmount , watch , onMounted } from 'vue' ;
4
3
5
4
const SMOOTH_PTG = 14 / 15 ;
6
-
7
5
export default function useMobileTouchMove (
8
6
inVirtual : Ref < boolean > ,
9
7
listRef : Ref < HTMLDivElement | undefined > ,
@@ -19,15 +17,7 @@ export default function useMobileTouchMove(
19
17
20
18
const cleanUpEvents = ( ) => {
21
19
if ( element ) {
22
- element . removeEventListener (
23
- 'touchmove' ,
24
- onTouchMove ,
25
- supportsPassive
26
- ? ( {
27
- passive : false ,
28
- } as EventListenerOptions )
29
- : false ,
30
- ) ;
20
+ element . removeEventListener ( 'touchmove' , onTouchMove ) ;
31
21
element . removeEventListener ( 'touchend' , onTouchEnd ) ;
32
22
}
33
23
} ;
@@ -68,47 +58,28 @@ export default function useMobileTouchMove(
68
58
touchY = Math . ceil ( e . touches [ 0 ] . pageY ) ;
69
59
70
60
element = e . target as HTMLElement ;
71
- element ! . addEventListener (
72
- 'touchmove' ,
73
- onTouchMove ,
74
- supportsPassive
75
- ? ( {
76
- passive : false ,
77
- } as EventListenerOptions )
78
- : false ,
79
- ) ;
61
+ element ! . addEventListener ( 'touchmove' , onTouchMove , { passive : false } ) ;
80
62
element ! . addEventListener ( 'touchend' , onTouchEnd ) ;
81
63
}
82
64
} ;
65
+ const noop = ( ) => { } ;
83
66
84
67
onMounted ( ( ) => {
68
+ document . addEventListener ( 'touchmove' , noop , { passive : false } ) ;
85
69
watch (
86
70
inVirtual ,
87
71
val => {
88
- listRef . value . removeEventListener (
89
- 'touchstart' ,
90
- onTouchStart ,
91
- supportsPassive
92
- ? ( {
93
- passive : false ,
94
- } as EventListenerOptions )
95
- : false ,
96
- ) ;
72
+ listRef . value . removeEventListener ( 'touchstart' , onTouchStart ) ;
97
73
cleanUpEvents ( ) ;
98
74
clearInterval ( interval ) ;
99
75
if ( val ) {
100
- listRef . value . addEventListener (
101
- 'touchstart' ,
102
- onTouchStart ,
103
- supportsPassive
104
- ? ( {
105
- passive : false ,
106
- } as EventListenerOptions )
107
- : false ,
108
- ) ;
76
+ listRef . value . addEventListener ( 'touchstart' , onTouchStart , { passive : false } ) ;
109
77
}
110
78
} ,
111
79
{ immediate : true } ,
112
80
) ;
113
81
} ) ;
82
+ onBeforeUnmount ( ( ) => {
83
+ document . removeEventListener ( 'touchmove' , noop ) ;
84
+ } ) ;
114
85
}
0 commit comments