@quintenkasteel/useswipe
v1.0.0
Published
A simple to use library that provides useSwipe hook for React that enables swipe gestures for touch screens.
Maintainers
Readme
Getting Started with UseSwipe
A simple to use library that provides useSwipe hook for React that enables swipe gestures for touch screens.
Usage
import useSwipe from '@quintenkasteel/useswipe'
example without element
const swipe = useSwipe({})
example with element
const swipe = useSwipe(".header", true)
Props
element: StringDOM element where the swipe is enabled. default value is body.
preventDefault: BoolPrevent all default events when moving. for example scrolling.
onStart: () => {}function that will be fired on start of moving. (not yet in)
onMove: () => {}function that will be fired on every move. (not yet in)
onEnd: () => {}function that will be fired on end of moving. (not yet in)
onCancel: () => {}function that will be fired on cancel of moving. (not yet in)
Return Values
direction: StringGet the current swiping direction in uppercase.
one of: "RIGHT" | "LEFT" | "DOWN" | "UP"
distance: NumberGet the swiped amount in pixels.
startX: NumberGet the starting X position in pixels.
startY: NumberGet the starting Y position in pixels.
endX: NumberGet the end X position in pixels.
endY: NumberGet the end Y position in pixels.
startTime: DateGet the date at the beginning of the swipe.
elapsedTime: NumberGet the duration of the swipe in seconds.
speed: NumberGet the speed of the swipe
isSwiping: Bool True when swiping.
