@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」フィードバックをトリガーします。
パラメータ | 型 |
---|---|
options | ImpactOptions |
バージョン 1.0.0
notification(...)
notification(options?: NotificationOptions | undefined) => Promise<void>
ハプティクス「notification」フィードバックをトリガーします。
パラメータ | 型 |
---|---|
options | NotificationOptions |
バージョン 1.0.0
vibrate(...)
vibrate(options?: VibrateOptions | undefined) => Promise<void>
デバイスを振動させます。
パラメータ | 型 |
---|---|
options | VibrateOptions |
バージョン 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
プロパティ | 型 | 説明 | デフォルト | バージョン |
---|---|---|---|---|
style | ImpactStyle | UIImpactFeedbackGeneratorオブジェクトによってシミュレートされる衝突におけるオブジェクトの質量。 | ImpactStyle.Heavy | 1.0.0 |
NotificationOptions
プロパティ | 型 | 説明 | デフォルト | バージョン |
---|---|---|---|---|
type | NotificationType | UINotificationFeedbackGeneratorオブジェクトによって生成される通知フィードバックのタイプ。 | NotificationType.SUCCESS | 1.0.0 |
VibrateOptions
プロパティ | 型 | 説明 | デフォルト | バージョン |
---|---|---|---|---|
duration | 数値 | 振動の持続時間(ミリ秒)。 | 300 | 1.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 |