Skip to content

useGesture

Touch gesture detection hook. Supports directional swipe and long-press detection (mutually exclusive).

Usage

ts
import { ref, onMounted } from 'vue'
import { useGesture } from 'see-u-ui'

const boxRef = ref(null)
const { isSwiping, bindEvents } = useGesture(boxRef, {
  direction: 'horizontal',
  threshold: 10,
  onSwipe: (dir, dist) => console.log(`${dir}: ${dist}px`),
  onLongPress: () => console.log('long press')
})

onMounted(() => bindEvents())

API

useGesture(elementRef, options?)

ParamTypeDefaultDescription
elementRefRef<HTMLElement | null>Target element
options.direction'horizontal' | 'vertical' | 'both''both'Detection direction
options.thresholdnumber10Swipe threshold (px)
options.longPressDelaynumber350Long press delay (ms)
options.onSwipe(direction, distance) => void-Swipe callback
options.onSwipeStart() => void-Swipe start callback
options.onSwipeEnd(direction, distance) => void-Swipe end callback
options.onLongPress() => void-Long press callback
options.onLongPressEnd() => void-Long press end callback

Returns:

PropertyTypeDescription
isSwipingRef<boolean>Swiping state
swipeDistanceRef<number>Current swipe distance
isLongPressingRef<boolean>Long pressing state
bindEvents() => voidBind event listeners
unbindEvents() => voidUnbind event listeners
reset() => voidReset state

Liao ICP No. 2025070134