useVibrate
リアクティブ Vibration API
ほとんどの最新のモバイルデバイスには、デバイスを振動させることで、ソフトウェアコードがユーザーに物理的なフィードバックを提供する振動ハードウェアが含まれています。
Vibration APIは、Webアプリがこのハードウェア(存在する場合)にアクセスできるようにし、デバイスがそれをサポートしていない場合は何も実行しません。
使用法
振動は、オンとオフのパルスのパターンとして記述されます。これは、さまざまな長さである可能性があります。
パターンは、振動するミリ秒数を記述する単一の整数、または振動と一時停止のパターンを記述する整数の配列のいずれかで構成できます。
ts
import { useVibrate } from '@vueuse/core'
// This vibrates the device for 300 ms
// then pauses for 100 ms before vibrating the device again for another 300 ms:
const { vibrate, stop, isSupported } = useVibrate({ pattern: [300, 100, 300] })
// Start the vibration, it will automatically stop when the pattern is complete:
vibrate()
// But if you want to stop it, you can:
stop()
型宣言
型宣言を表示
typescript
export interface UseVibrateOptions extends ConfigurableNavigator {
/**
*
* 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<number[] | number>
/**
* Interval to run a persistent vibration, in ms
*
* Pass `0` to disable
*
* @default 0
*
*/
interval?: number
}
/**
* Reactive vibrate
*
* @see https://vueuse.dokyumento.jp/useVibrate
* @see https://developer.mozilla.org/en-US/docs/Web/API/Vibration_API
* @param options
*/
export declare function useVibrate(options?: UseVibrateOptions): {
isSupported: ComputedRef<boolean>
pattern: MaybeRefOrGetter<number | number[]>
intervalControls: Pausable | undefined
vibrate: (pattern?: number | number[]) => void
stop: () => void
}
export type UseVibrateReturn = ReturnType<typeof useVibrate>
ソース
貢献者
変更履歴
v10.0.0-beta.4
2023/04/134d757
- feat(types)!: MaybeComputedRef
を MaybeRefOrGetter
に名前変更10e98
- feat(toRef)!: resolveRef
を toRef
に名前変更