@@ -35,6 +35,11 @@ export interface UseSwipeOptions {
3535 * 滑动结束时的回调函数
3636 */
3737 onSwipeEnd ?: ( e : TouchEvent ) => void ;
38+
39+ /**
40+ * 是否禁用
41+ */
42+ disabled ?: boolean ;
3843}
3944
4045/**
@@ -48,7 +53,7 @@ export function useSwipe(target: EventTarget | null | undefined, options = {} as
4853 const coordsStart = useRef < Position > ( { x : 0 , y : 0 } ) ; // 用于存储触摸起始位置的坐标
4954 const coordsEnd = useRef < Position > ( { x : 0 , y : 0 } ) ; // 用于存储触摸结束位置的坐标
5055 const coordsOffset = useRef < Position > ( { x : 0 , y : 0 } ) ; // 用于存储滑动偏移量
51- const { threshold = 0 , onSwipe, onSwipeEnd, onSwipeStart, listenerOptions = { passive : true } } = options ;
56+ const { threshold = 0 , onSwipe, onSwipeEnd, onSwipeStart, listenerOptions = { passive : true } , disabled } = options ;
5257
5358 const updateOffset = useCallback ( ( ) => {
5459 coordsOffset . current = {
@@ -95,6 +100,7 @@ export function useSwipe(target: EventTarget | null | undefined, options = {} as
95100 const onTouchStart = useCallback (
96101 ( e : TouchEvent ) => {
97102 if ( e . touches . length !== 1 ) return ;
103+ if ( disabled ) return ;
98104 if (
99105 listenerOptions === true ||
100106 ( isObject ( listenerOptions ) && listenerOptions . capture && listenerOptions . passive )
@@ -106,6 +112,7 @@ export function useSwipe(target: EventTarget | null | undefined, options = {} as
106112 updateCoordsEnd ( x , y ) ;
107113 onSwipeStart ?.( e ) ;
108114 } ,
115+ // eslint-disable-next-line react-hooks/exhaustive-deps
109116 [ listenerOptions , updateCoordsStart , updateCoordsEnd , onSwipeStart ] ,
110117 ) ;
111118
0 commit comments