useVelocity

Commons
stable

Tracks touch-event samples per finger (identified by touch.identifier) in circular buffers and computes the instantaneous velocity vector at touchend via impulse-velocity analysis. Used by useTouch to decide whether a fling gesture is fast enough to open or close a drawer.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

useVelocity is a low-level primitive consumed internally by useTouch. The HISTORY constant controls the circular buffer size (number of samples kept) and HORIZON controls the time window (ms) over which velocity is computed. Direct use is rarely needed — prefer useTouch for drawer gestures.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

addMovement
Record a touchstart or touchmove event sample. Each touch point is tracked independently. Call this on every touchmove to build a time-stamped sample history.
endTouch
Clear the circular buffer for all changed touches. Call at touchstart before starting a new gesture to discard leftover samples from a previous interaction.
getVelocity
Compute the velocity vector for the given touch identifier from the recent sample history. Returns px/ms values for x and y axes and the dominant direction string. Throws if no samples are found for the id.

Usage

Exemples

Extraits de code prêts à coller.

Fling detection in a custom swipeable

vue