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:
optionstouchend, touchcancel, and touchstart effects. See the Options section for more guidance.Options
minDuration0minDistance0minVelocity0onStartundefinedA function that is called when the touch starts.
onStart receives the touchrelease hook API as its only parameter.
onMoveundefinedA function that is called when the touch moves.
onMove receives the touchrelease hook API as its only parameter.
onCancelundefinedA function that is called when the touch leaves the target.
onCancel receives the touchrelease hook API as its only parameter.
onUpundefinedA 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:
statusrecognized, denied, or recognizing.sequenceMetadata
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)
})