@napacitor/haptics
Haptic feedback plugin (corresponds to @capacitor/haptics).
Installation
To use npm:
npm install @napacitor/haptics
To use yarn:
yarn add @napacitor/haptics
Sync native files:
npx nap sync
Usage
import { Haptics, ImpactStyle } from '@napacitor/haptics';
await Haptics.impact({ style: ImpactStyle.Heavy });
await Haptics.notification(); // Default SUCCESS
await Haptics.vibrate({ duration: 100 }); // Custom duration (milliseconds)
await Haptics.selection(); // Selection change (light feedback)
await Haptics.selectionChanged(); // Selection started (light feedback)
How It Works
Wraps the APIs described in the .NET MAUI Vibration documentation: Vibration.Default.Vibrate(TimeSpan) / IsSupported. MAUI has no Taptic-level feedback, so vibration durations approximate it: impact LIGHT 10ms / MEDIUM 25ms / HEAVY 40ms; notification SUCCESS 35ms / WARNING 45ms / ERROR 60ms; selection / selectionChanged are 10ms light feedback. Platforms without vibration support (such as Windows) are no-ops that log a debug message.
Permissions
Android
The VIBRATE permission must be declared (required by the MAUI documentation). Add it to AndroidManifest.xml:
<uses-permission android:name="android.permission.VIBRATE" />
Or add an assembly attribute in Platforms/Android/MainApplication.cs:
[assembly: UsesPermission(Android.Manifest.Permission.Vibrate)]
iOS
No additional configuration required. Note: the device only vibrates when "Vibrate on Ring" is enabled; it always vibrates for 500ms; vibration cannot be canceled.
Windows
No additional configuration required. Desktop platforms do not support vibration; calls are no-ops that log a debug message.
API
impact(options?)
Haptic impact (default MEDIUM).
| Param | Type |
|---|---|
options | ImpactOptions |
Returns: Promise<void>
notification(options?)
Notification haptic (default SUCCESS).
| Param | Type |
|---|---|
options | NotificationOptions |
Returns: Promise<void>
vibrate(options?)
Vibrates for a custom duration (default 60ms).
| Param | Type |
|---|---|
options | VibrateOptions |
Returns: Promise<void>
selection()
Selection change haptic (light, 10ms).
Returns: Promise<void>
selectionChanged()
Selection started haptic (same light feedback as selection, 10ms).
Returns: Promise<void>
Interfaces
ImpactOptions
| Prop | Type | Description |
|---|---|---|
style | ImpactStyle | Impact intensity: LIGHT (10ms) / MEDIUM (25ms) / HEAVY (40ms); default MEDIUM. Unknown values are treated as 25ms. |
NotificationOptions
| Prop | Type | Description |
|---|---|---|
type | NotificationType | Notification type: SUCCESS (35ms) / WARNING (45ms) / ERROR (60ms); default SUCCESS. Unknown values are treated as 35ms. |
VibrateOptions
| Prop | Type | Description |
|---|---|---|
duration | number | Vibration duration (milliseconds, default 60). |