0.1.3 • Published 3 years ago

@adrianbielawski/use-swipe v0.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

useSwipe react hook

Description

Very easy to use react hook for detection of swipe length and quick swipe check on touch screen.

Technology

Created with TypeScript and React. Tested with Jest and React-testing-library.

Usage

$ npm i @adrianbielawski/use-swipe

import useSwipe from '@adrianbielawski/use-swipe'

const YourComponent = () => {
    const swipeRef = useSwipe(handleSwipe, handleSwipeEnd)

    const handleSwipe = (x: number, y: number) => {
        console.log(x, y)
    }
        
    const handleSwipeEnd = (x: number, y: number, isQuick: boolean) => {
        console.log(x, y, isQuick)
    }

    return (
        <div ref={swipeRef}>
            your content here
        </div>
    )
}

Props / Config

All must be passed as ordered below

x, y - swipe lendth \ isQuick - was the swipe quick and short enough

NameTyperequiredDescription
onSwipe(x: number, y: number) => voidtrueCalled while swiping
onSwipeEnd(x: number, y: number, isQuick: boolean) => voidtrueCalled when swipe has ended
onSwipeStart(x: number, y: number, isQuick: boolean) => voidfalseCalled when swipe has ended
stopPropagationboolean, default truefalseif true, e.stopPropagation is called on every events
quickSwipeDurationnumber, default 300falsemax time of swipe to be considered as quick (in miliseconds)
quickSwipeDistancenumber, default 50falsemin length of swipe to be considered as quick (in miliseconds)
0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago