メインコンテンツへスキップ
バージョン: v8

@capacitor/haptics

Haptics APIは、タッチや振動を通じてユーザーに物理的なフィードバックを提供します。

Taptic Engineまたはバイブレーターを搭載していないデバイスでは、API呼び出しはアクションを実行せずに解決されます。

インストール

npm install @capacitor/haptics
npx cap sync

import { Haptics, ImpactStyle } from '@capacitor/haptics';

const hapticsImpactMedium = async () => {
await Haptics.impact({ style: ImpactStyle.Medium });
};

const hapticsImpactLight = async () => {
await Haptics.impact({ style: ImpactStyle.Light });
};

const hapticsVibrate = async () => {
await Haptics.vibrate();
};

const hapticsSelectionStart = async () => {
await Haptics.selectionStart();
};

const hapticsSelectionChanged = async () => {
await Haptics.selectionChanged();
};

const hapticsSelectionEnd = async () => {
await Haptics.selectionEnd();
};

API

impact(...)

impact(options?: ImpactOptions | undefined) => Promise<void>

ハプティクス「impact」フィードバックをトリガーします。

パラメータ
optionsImpactOptions

バージョン 1.0.0


notification(...)

notification(options?: NotificationOptions | undefined) => Promise<void>

ハプティクス「notification」フィードバックをトリガーします。

パラメータ
optionsNotificationOptions

バージョン 1.0.0


vibrate(...)

vibrate(options?: VibrateOptions | undefined) => Promise<void>

デバイスを振動させます。

パラメータ
optionsVibrateOptions

バージョン 1.0.0


selectionStart()

selectionStart() => Promise<void>

選択開始のハプティックヒントをトリガーします。

バージョン 1.0.0


selectionChanged()

selectionChanged() => Promise<void>

選択変更のハプティックヒントをトリガーします。既に選択が開始されている場合、デバイスはハプティックフィードバックを提供します。

バージョン 1.0.0


selectionEnd()

selectionEnd() => Promise<void>

selectionStart()が呼び出された場合、selectionEnd()は選択を終了します。例えば、ユーザーがコントロールから指を離したときに呼び出します。

バージョン 1.0.0


インターフェース

ImpactOptions

プロパティ説明デフォルトバージョン
styleImpactStyleUIImpactFeedbackGeneratorオブジェクトによってシミュレートされる衝突におけるオブジェクトの質量。ImpactStyle.Heavy1.0.0

NotificationOptions

プロパティ説明デフォルトバージョン
typeNotificationTypeUINotificationFeedbackGeneratorオブジェクトによって生成される通知フィードバックのタイプ。NotificationType.SUCCESS1.0.0

VibrateOptions

プロパティ説明デフォルトバージョン
duration数値振動の持続時間(ミリ秒)。3001.0.0

列挙型

ImpactStyle

メンバー説明バージョン
Heavy'HEAVY'大きく重いユーザーインターフェース要素間の衝突1.0.0
Medium'MEDIUM'中程度の大きさのユーザーインターフェース要素間の衝突1.0.0
Light'LIGHT'小さく軽いユーザーインターフェース要素間の衝突1.0.0

NotificationType

メンバー説明バージョン
Success'SUCCESS'タスクが正常に完了したことを示す通知フィードバックタイプ1.0.0
Warning'WARNING'タスクが警告を生成したことを示す通知フィードバックタイプ1.0.0
Error'ERROR'タスクが失敗したことを示す通知フィードバックタイプ1.0.0