Skip to main content

@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).

ParamType
optionsImpactOptions

Returns: Promise<void>

notification(options?)​

Notification haptic (default SUCCESS).

ParamType
optionsNotificationOptions

Returns: Promise<void>

vibrate(options?)​

Vibrates for a custom duration (default 60ms).

ParamType
optionsVibrateOptions

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​

PropTypeDescription
styleImpactStyleImpact intensity: LIGHT (10ms) / MEDIUM (25ms) / HEAVY (40ms); default MEDIUM. Unknown values are treated as 25ms.

NotificationOptions​

PropTypeDescription
typeNotificationTypeNotification type: SUCCESS (35ms) / WARNING (45ms) / ERROR (60ms); default SUCCESS. Unknown values are treated as 35ms.

VibrateOptions​

PropTypeDescription
durationnumberVibration duration (milliseconds, default 60).