Long press hook
  • Introduction
  • Installation
  • Basics
  • Advanced
    • Definition
    • Callback
    • Options
      • Configuration
        • Events detection
        • Long press threshold
      • React events
        • Persisting event
        • Filtering events
      • Callbacks
        • Press started
        • On move
        • Press finished
        • Long press cancelled
      • Cancellation
        • Cancel outside element
        • Cancel on movement
    • Hook result / Bind function
      • Context
      • Handlers
  • Examples
    • Advanced usage example
    • Live examples
      • Version 3
      • Version 2 (deprecated)
      • Version 1 (deprecated)
  • Migration
    • V1 to V2
    • V2 to V3
    • ⚠️V3.1+
    • Change log
  • Contributions
    • ❤️Donations
    • Pull requests policy
  • Architectural Decisions
    • V1 and V2 deprecation
    • Moving to new repository
Powered by GitBook
On this page
  • Structure
  • Context
  • Reason

Was this helpful?

  1. Advanced
  2. Options

Callbacks

Long press lifecycle callbacks

PreviousFiltering eventsNextPress started

Last updated 1 year ago

Was this helpful?

Structure

All callbacks (including function) has the same structure.

Pseudocode
callbackFn(event, meta): void
TypeScript
type LongPressCallback<Target extends Element = Element, Context = unknown> = (
  event: LongPressEvent<Target>,
  meta: LongPressCallbackMeta<Context>
) => void

As a first argument callback receives from a proper (e.g. onMouseDown) and as second receives meta object with following structure:

Pseudocode

Pseudocode
{ [context: any], [reason: string] }
TypeScript
export type LongPressCallbackMeta<Context = unknown> = { 
    context?: Context; 
    reason?: LongPressCallbackReason 
};

Both object properties are optional.

Context

context will be present if you pass it to . See for more info.

Reason

Here is a list of all possible reason values

Javascript
'cancelled-by-movement' | 'cancelled-by-release' | 'cancelled-outside-element'
TypeScript
export enum LongPressCallbackReason {
  /**
   * Returned when mouse / touch / pointer was moved outside initial press area when _cancelOnMovement_ is active
   */
  CancelledByMovement = 'cancelled-by-movement',
  /**
   * Returned when click / tap / point was released before long press detection time threshold
   */
  CancelledByRelease = 'cancelled-by-release',
  /**
   * Returned when mouse / touch / pointer was moved outside element and _cancelOutsideElement_ option was set to `true`
   */
  CancelledOutsideElement = 'cancelled-outside-element',
}

reason will be present in callback to indicate why long press was cancelled.

main callback
React event
handler
bind function
context
onCancel
Press started
On move
Press finished
Long press cancelled