SHIFT + D

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:

Parameter
Type
Required
Description
options
Object
no
Options to customize the behavior of the touchend, touchcancel, and touchstart effects. See the Options section for more guidance.

Options

Option
Type
Default
Description
minDuration
number
0
The minimum millisecond duration of the touch release, in milliseconds.
minDistance
number
0
The minimum pixel distance the touch must move.
minVelocity
number
0
The minimum pixel velocity the touch must move.
onStart
Function
undefined

A function that is called when the touch starts.

onStart receives the touchrelease hook API as its only parameter.

onMove
Function
undefined

A function that is called when the touch moves.

onMove receives the touchrelease hook API as its only parameter.

onCancel
Function
undefined

A function that is called when the touch leaves the target.

onCancel receives the touchrelease hook API as its only parameter.

onUp
Function
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:

Property
Type
Description
status
string
The status of the sequence. One of recognized, denied, or recognizing.
metadata
Object
Metadata about the sequence. See the Metadata section for more guidance.
sequence
Array
The sequence of events that have occurred so far.

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)
})

Touchpressassociative array clear

Edit doc on GitHub

ON THIS PAGE

TouchreleaseCreate touchreleaseOptionsHook APIMetadataUsing with Listenable