Skip to content

useLongPress

@astryxdesign/core v0.7.1 · useLongPress

Parameters ​

NameTypeDefaultDescription
optionsLongPressOptions—Configuration object. Required.
options.onLongPress(point: { x: number, y: number }) => void—Fired with the press start point once the press is held for delayMs. Required.
options.disabledMaybeRefOrGetter<boolean>falseWhen true the detector is inert, so a disabled trigger can flip the flag without re-registering anything. Read on each press, so a ref or a getter works as well as a plain boolean.
options.isDisabledMaybeRefOrGetter<boolean>—The same switch under its other name; either one being true keeps the detector inert.
options.delayMsnumber500Hold duration before the press fires, in milliseconds.
options.moveCancelPxnumber10Movement past this distance on either axis cancels the press, treating it as a scroll or drag.

Returns ​

NameTypeDescription
handlers{ onTouchStart, onTouchMove, onTouchEnd, onTouchCancel }The four touch listeners to spread onto the target element, e.g. <button v-on="press.handlers">. A second finger, a lift, or a cancel ends the press; a move past moveCancelPx does too.
start(point: { x: number, y: number }) => voidBegins detection at a point. Call it from pointerdown. It clears any pending press first, then re-arms the timer.
moveTo(point: { x: number, y: number }) => booleanReports the pointer's new position. Returns true while the press is still inside the tolerance; past it the press is cancelled and it returns false. Returns false as well when no press is pending.
cancel() => voidDrops any pending press. Bind it to pointerup and pointercancel. Also runs when the component unmounts.