1- import supportsPassive from '../../_util/supportsPassive' ;
21import type { Ref } from 'vue' ;
3- import { watch , onMounted } from 'vue' ;
2+ import { onBeforeUnmount , watch , onMounted } from 'vue' ;
43
54const SMOOTH_PTG = 14 / 15 ;
6-
75export default function useMobileTouchMove (
86 inVirtual : Ref < boolean > ,
97 listRef : Ref < HTMLDivElement | undefined > ,
@@ -19,15 +17,7 @@ export default function useMobileTouchMove(
1917
2018 const cleanUpEvents = ( ) => {
2119 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 ) ;
3121 element . removeEventListener ( 'touchend' , onTouchEnd ) ;
3222 }
3323 } ;
@@ -68,47 +58,28 @@ export default function useMobileTouchMove(
6858 touchY = Math . ceil ( e . touches [ 0 ] . pageY ) ;
6959
7060 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 } ) ;
8062 element ! . addEventListener ( 'touchend' , onTouchEnd ) ;
8163 }
8264 } ;
65+ const noop = ( ) => { } ;
8366
8467 onMounted ( ( ) => {
68+ document . addEventListener ( 'touchmove' , noop , { passive : false } ) ;
8569 watch (
8670 inVirtual ,
8771 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 ) ;
9773 cleanUpEvents ( ) ;
9874 clearInterval ( interval ) ;
9975 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 } ) ;
10977 }
11078 } ,
11179 { immediate : true } ,
11280 ) ;
11381 } ) ;
82+ onBeforeUnmount ( ( ) => {
83+ document . removeEventListener ( 'touchmove' , noop ) ;
84+ } ) ;
11485}
0 commit comments