Touchrelease
Updated on September 20, 2024Source codeTests
createTouchrelease
is a factory that returns Recognizeable
effects for recognizing touch releases.
A touch release is a sequence of a touchstart
and a touchend
, and allows for touchmove
in between those events, but denies the event on touchcancel
.
createTouchrelease
attempts to recognize the gesture when touchend
fires. The gesture is recognized at on touchstart
if the touch has been down for a minimum duration and has moved a minimum distance, both of which are configurable.
Create touchrelease
Call createTouchrelease
with these parameters to create your touchend
, touchcancel
, and touchstart
effects:
options
touchend
, touchcancel
, and touchstart
effects. See the Options section for more guidance.Options
minDuration
0
minDistance
0
minVelocity
0
onStart
undefined
A function that is called when the touch starts.
onStart
receives the touchrelease
hook API as its only parameter.
onMove
undefined
A function that is called when the touch moves.
onMove
receives the touchrelease
hook API as its only parameter.
onCancel
undefined
A function that is called when the touch leaves the target.
onCancel
receives the touchrelease
hook API as its only parameter.
onUp
undefined
A function that is called when the touch is released.
onUp
receives the touchrelease
hook API as its only parameter.
Hook API
The hook API is an object that is passed to the onStart
, onMove
, onCancel
, and onUp
options as their only parameter. It contains the following properties:
status
recognized
, denied
, or recognizing
.sequence
Metadata
Your created touchrelease effects store data in the Recognizeable
instance's metadata
property.
Touchrelease metadata includes all pointer metadata.
Using with Listenable
The easiest way to use createTouchrelease
with Listenable
is to use the Touchrelease
class, which is a very minimal subclass of Listenable
that handles configuration for you.
Here's an example of how to use Touchrelease
to nicely combine createTouchrelease
with Listenable
:
import { Touchrelease } from '@baleada/logic'
const touchrelease = new Touchrelease([touchreleaseOptions])
touchrelease.listen(() => {
console.log(touchrelease.metadata.velocity)
})