Skip to content

⬅️ Back to Table of Contents

📄 useVibrate

📊 Analysis Summary

Metric Count
🔧 Functions 3
📦 Imports 9
📐 Interfaces 2

📚 Table of Contents

🛠️ File Location:

📂 packages/core/useVibrate/index.ts

📦 Imports

Name Source
Arrayable @vueuse/shared
Pausable @vueuse/shared
MaybeRefOrGetter vue
ConfigurableNavigator ../_configurable
ConfigurableScheduler ../_configurable
Supportable ../types
toRef @vueuse/shared
defaultNavigator ../_configurable
useSupported ../useSupported

Functions

useVibrate(options: UseVibrateOptions): UseVibrateReturn

Reactive vibrate

Parameters:

  • options any: No description

See: https://vueuse.org/useVibrate, https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API

Tags: @__NO_SIDE_EFFECTS__

Raw JSDoc
/**
 * Reactive vibrate
 *
 * @see https://vueuse.org/useVibrate
 * @see https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API
 * @param options
 *
 * @__NO_SIDE_EFFECTS__
 */

Calls:

  • useSupported (from ../useSupported)
  • toRef (from @vueuse/shared)
  • navigator!.vibrate
  • scheduler
  • intervalControls?.pause

Internal Comments:

// Attempt to stop the vibration: (x2)
// Stope the vibration if we need to:

Code
export function useVibrate(options?: UseVibrateOptions): UseVibrateReturn {
  const {
    pattern = [],
    scheduler,
    navigator = defaultNavigator,
  } = options || {}

  const isSupported = useSupported(() => typeof navigator !== 'undefined' && 'vibrate' in navigator)

  const patternRef = toRef(pattern)

  const vibrate = (pattern = patternRef.value) => {
    if (isSupported.value)
      navigator!.vibrate(pattern)
  }

  const intervalControls = scheduler?.(vibrate)

  // Attempt to stop the vibration:
  const stop = () => {
    // Stope the vibration if we need to:
    if (isSupported.value)
      navigator!.vibrate(0)
    intervalControls?.pause()
  }

  return {
    isSupported,
    pattern,
    intervalControls,
    vibrate,
    stop,
  }
}

Internal helpers

Declared inside another function in this file.

vibrate(pattern: any): void

Parameters:

  • pattern any

Returns: void

Calls:

  • navigator!.vibrate
Code
(pattern = patternRef.value) => {
    if (isSupported.value)
      navigator!.vibrate(pattern)
  }

stop(): void

Returns: void

Calls:

  • navigator!.vibrate
  • intervalControls?.pause

Internal Comments:

// Stope the vibration if we need to:

Code
() => {
    // Stope the vibration if we need to:
    if (isSupported.value)
      navigator!.vibrate(0)
    intervalControls?.pause()
  }

Interfaces

UseVibrateOptions

Interface Code
export interface UseVibrateOptions extends ConfigurableNavigator, ConfigurableScheduler {
  /**
   *
   * Vibration Pattern
   *
   * An array of values describes alternating periods in which the
   * device is vibrating and not vibrating. Each value in the array
   * is converted to an integer, then interpreted alternately as
   * the number of milliseconds the device should vibrate and the
   * number of milliseconds it should not be vibrating
   *
   * @default []
   *
   */
  pattern?: MaybeRefOrGetter<Arrayable<number>>
}

Properties

Name Type Optional Description
pattern MaybeRefOrGetter<Arrayable<number>> not shown

UseVibrateReturn

Interface Code
export interface UseVibrateReturn extends Supportable {
  pattern: MaybeRefOrGetter<Arrayable<number>>
  intervalControls?: Pausable
  vibrate: (pattern?: Arrayable<number>) => void
  stop: () => void
}

Properties

Name Type Optional Description
pattern MaybeRefOrGetter<Arrayable<number>> not shown
intervalControls Pausable not shown
vibrate (pattern?: Arrayable<number>) => void not shown
stop () => void not shown

Generated by Syntax Scribe