@capawesome/capacitor-haptics

中文文档
0.2.0发布于 2026/10/30MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 8244

Capacitor plugin to provide haptic feedback such as impacts, notifications, vibrations and custom haptic patterns on Android, iOS, and Web.

原始使用文档
文档目录43 节
  1. Features
  2. Use Cases
  3. Compatibility
  4. Installation
  5. Android
  6. iOS
  7. Configuration
  8. Usage
  9. Check if haptic feedback is available
  10. Trigger impact feedback
  11. Trigger notification feedback
  12. Give selection feedback
  13. Play a custom haptic pattern
  14. Play an Android composition
  15. Perform an Android haptic effect
  16. Vibrate the device
  17. API
  18. impact(...)
  19. isAvailable()
  20. notification(...)
  21. performAndroidHapticFeedback(...)
  22. playAndroidComposition(...)
  23. playPattern(...)
  24. selectionChanged()
  25. selectionEnd()
  26. selectionStart()
  27. vibrate(...)
  28. Interfaces
  29. Enums
  30. Migrating from @capacitor/haptics
  31. Platform behavior
  32. FAQ
  33. How is this plugin different from other similar plugins?
  34. How is this plugin different from the official Capacitor Ha…
  35. Do I need to configure any permissions?
  36. Why don't I feel any haptic feedback on my device?
  37. Are custom haptic patterns supported on all platforms?
  38. What is the difference between vibrate and playPattern ?
  39. Can I use this plugin with Ionic, React, Vue or Angular?
  40. Related Plugins
  41. Newsletter
  42. Changelog
  43. License

Capacitor Haptics Plugin

Capacitor plugin to provide haptic feedback such as impacts, notifications, vibrations and custom haptic patterns.

Features

  • 💥 Impact: Trigger impact haptic feedback with five different styles, including the modern Rigid and Soft styles.
  • 🔔 Notification: Trigger notification haptic feedback for success, warning and error events.
  • 🎯 Selection: Trigger selection haptic feedback for picker-style interactions.
  • 🎼 Custom patterns: Play custom haptic patterns with per-event intensity and sharpness (Core Haptics on iOS, vibration effects on Android).
  • 🤖 Android haptics: Perform semantic Android haptic feedback effects that respect the user's haptic feedback settings.
  • 📳 Vibrate: Vibrate the device with a custom duration.
  • 🔎 Availability check: Check if haptic feedback is available on the device.
  • 🌐 Web support: Best-effort support for the Web using the Vibration API.
  • 🤝 Compatibility: Works alongside the Shake, Silent Mode and Volume plugins.
  • 📦 CocoaPods & SPM: Supports CocoaPods and Swift Package Manager for iOS.
  • 🔁 Up-to-date: Always supports the latest Capacitor version.

Missing a feature? Just open an issue and we'll take a look!

Use Cases

The Haptics plugin is typically used to make an app feel more responsive and tactile, for example:

  • Button and gesture feedback: Trigger impact feedback when user interface elements collide or a drag operation snaps into place.
  • Success and error feedback: Use notification haptics to communicate that a task has succeeded, failed, or produced a warning.
  • Pickers and selection controls: Give subtle selection feedback while the user scrolls through a picker.
  • Games and rich interactions: Play custom haptic patterns with per-event intensity and sharpness for immersive experiences.
  • Alerts: Vibrate the device with a custom duration to get the user's attention.

Compatibility

Plugin VersionCapacitor VersionStatus
0.2.x>=8.x.xActive support
0.1.x>=8.x.xDeprecated

Installation

You can use our AI-Assisted Setup to install the plugin. Add the Capawesome Skills to your AI tool using the following command:

npx skills add capawesome-team/skills --skill capacitor-plugins

Then use the following prompt:

 Use the `capacitor-plugins` skill from `capawesome-team/skills` to install the `@capawesome/capacitor-haptics` plugin in my project.

If you prefer Manual Setup, install the plugin by running the following commands and follow the platform-specific instructions below:

npm install @capawesome/capacitor-haptics
npx cap sync

Android

This plugin already declares the android.permission.VIBRATE permission in its manifest, so no additional configuration is required.

iOS

No additional configuration is required for this plugin.

Configuration

No configuration required for this plugin.

Usage

The following examples show how to check if haptic feedback is available, trigger impact and notification feedback, give selection feedback, play a custom haptic pattern, perform an Android haptic effect, and vibrate the device.

Check if haptic feedback is available

Check whether the device supports haptic feedback before using the other methods:

import { Haptics } from '@capawesome/capacitor-haptics';

const isAvailable = async () => {
  const { available } = await Haptics.isAvailable();
  return available;
};

Trigger impact feedback

Simulate a physical impact, for example when user interface elements collide or a drag operation snaps into place. Five different styles are available, including the modern Rigid and Soft styles:

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

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

Trigger notification feedback

Communicate that a task or action has succeeded, failed, or produced a warning:

import { Haptics, NotificationType } from '@capawesome/capacitor-haptics';

const notification = async () => {
  await Haptics.notification({ type: NotificationType.Success });
};

Give selection feedback

Give subtle feedback during picker-style interactions. Call selectionStart() when the interaction begins, selectionChanged() whenever the selection changes, and selectionEnd() when the interaction finishes:

import { Haptics } from '@capawesome/capacitor-haptics';

const selection = async () => {
  await Haptics.selectionStart();
  await Haptics.selectionChanged();
  await Haptics.selectionEnd();
};

Play a custom haptic pattern

Play a custom pattern composed of individual haptic events with per-event intensity and sharpness. On iOS, the pattern is played using Core Haptics; on Android, it is approximated using vibration effects:

import { Haptics } from '@capawesome/capacitor-haptics';

const playPattern = async () => {
  await Haptics.playPattern({
    events: [
      { time: 0, intensity: 1, sharpness: 0.8 },
      { time: 200, intensity: 0.6, sharpness: 0.4 },
      { time: 400, intensity: 0.8, duration: 500 },
    ],
  });
};

On iOS, parameter curves change the intensity or sharpness of the whole pattern over time, for example to ramp up a continuous event before a final tap:

import { HapticParameter, Haptics } from '@capawesome/capacitor-haptics';

const playRampUp = async () => {
  await Haptics.playPattern({
    events: [
      { time: 0, intensity: 1, sharpness: 0.3, duration: 1000 },
      { time: 1000, intensity: 1, sharpness: 0.9 },
    ],
    parameterCurves: [
      {
        parameter: HapticParameter.Intensity,
        controlPoints: [
          { time: 0, value: 0.1 },
          { time: 1000, value: 1 },
        ],
      },
    ],
  });
};

Play an Android composition

Play a composition of haptic primitives, for example the double click that Android uses for toggles. Only available on Android 12+:

import {
  AndroidHapticPrimitiveType,
  Haptics,
} from '@capawesome/capacitor-haptics';

const playToggleOn = async () => {
  await Haptics.playAndroidComposition({
    primitives: [
      { type: AndroidHapticPrimitiveType.Tick, scale: 0.5 },
      { type: AndroidHapticPrimitiveType.Click, delay: 50 },
    ],
  });
};

Perform an Android haptic effect

Perform a semantic Android haptic feedback effect that respects the user's haptic feedback settings. Only available on Android:

import { AndroidHapticFeedbackType, Haptics } from '@capawesome/capacitor-haptics';

const performAndroidHapticFeedback = async () => {
  await Haptics.performAndroidHapticFeedback({ type: AndroidHapticFeedbackType.Confirm });
};

Vibrate the device

Vibrate the device. The duration option is only available on Android and Web:

import { Haptics } from '@capawesome/capacitor-haptics';

const vibrate = async () => {
  await Haptics.vibrate({ duration: 500 });
};

API

impact(...)

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

Trigger an impact haptic feedback.

Use this to simulate a physical impact, for example when user interface elements collide or a drag operation snaps into place.

On Android, the impact style is mapped to a best-effort vibration effect.

ParamType
optionsImpactOptions

Since: 0.1.0


isAvailable()

isAvailable() => Promise<IsAvailableResult>

Check if haptic feedback is available on the device.

On Android, this checks whether the device has a vibrator. On iOS, this checks whether the device supports haptic event playback. On the web, this checks whether the Vibration API is supported.

Returns: Promise<IsAvailableResult>

Since: 0.1.0


notification(...)

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

Trigger a notification haptic feedback.

Use this to communicate that a task or action has succeeded, failed, or produced a warning.

On Android, the notification type is mapped to a best-effort vibration effect.

ParamType
optionsNotificationOptions

Since: 0.1.0


performAndroidHapticFeedback(...)

performAndroidHapticFeedback(options: PerformAndroidHapticFeedbackOptions) => Promise<void>

Perform a predefined Android haptic feedback effect.

In contrast to the other methods, this method does not use the vibrator but the semantic haptic feedback constants of the Android view system. This respects the user's haptic feedback settings.

Only available on Android.

ParamType
optionsPerformAndroidHapticFeedbackOptions

Since: 0.1.0


playAndroidComposition(...)

playAndroidComposition(options: PlayAndroidCompositionOptions) => Promise<void>

Play a composition of haptic primitives.

In contrast to playPattern(...), this method maps directly to the composition primitives of the Android vibrator system, for example to build the direction-aware double click that Android uses for toggles. The composition respects the system touch feedback setting on Android 13+.

A primitive the device does not support is played as Click.

Only available on Android 12+. This requires a device with haptic primitive support. Otherwise, the call rejects as unavailable.

ParamType
optionsPlayAndroidCompositionOptions

Since: 0.2.0


playPattern(...)

playPattern(options: PlayPatternOptions) => Promise<void>

Play a custom haptic pattern composed of individual haptic events.

On iOS, the pattern is played using Core Haptics with full support for intensity and sharpness. This requires a device with haptic event playback support (for example an iPhone with a Taptic Engine). Otherwise, the call rejects as unavailable.

On Android, the pattern is played using vibration effects. Intensity is only respected on devices with amplitude control. On Android 12+, a pattern of transient events only is played as a composition of click primitives. On Android 13+, the pattern respects the system touch feedback setting.

On the web, the pattern is approximated using the Vibration API.

ParamType
optionsPlayPatternOptions

Since: 0.1.0


selectionChanged()

selectionChanged() => Promise<void>

Trigger a selection changed haptic feedback.

Call this method after selectionStart() whenever the selection changes.

On the web, this method does nothing.

Since: 0.1.0


selectionEnd()

selectionEnd() => Promise<void>

End a selection session.

Call this method when the user finishes a selection interaction.

On the web, this method does nothing.

Since: 0.1.0


selectionStart()

selectionStart() => Promise<void>

Start a selection session.

Call this method when the user starts a selection interaction, for example when a picker starts scrolling. It prepares the haptic hardware to reduce the latency of subsequent selectionChanged() calls.

On the web, this method does nothing.

Since: 0.1.0


vibrate(...)

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

Vibrate the device.

ParamType
optionsVibrateOptions

Since: 0.1.0


Interfaces

ImpactOptions

PropTypeDescriptionDefaultSince
styleImpactStyleThe style of the impact.ImpactStyle.Medium0.1.0

IsAvailableResult

PropTypeDescriptionSince
availablebooleanWhether or not haptic feedback is available on the device.0.1.0

NotificationOptions

PropTypeDescriptionDefaultSince
typeNotificationTypeThe type of the notification.NotificationType.Success0.1.0

PerformAndroidHapticFeedbackOptions

PropTypeDescriptionSince
typeAndroidHapticFeedbackTypeThe Android haptic feedback effect to perform.0.1.0

PlayAndroidCompositionOptions

PropTypeDescriptionSince
primitivesAndroidHapticPrimitive[]The primitives that make up the composition, in playback order.0.2.0

AndroidHapticPrimitive

PropTypeDescriptionDefaultSince
delaynumberThe time to wait before playing this primitive, in milliseconds. The delay starts when the previous primitive of the composition has finished.00.2.0
scalenumberThe scale of the primitive as a value between 0 and 1.10.2.0
typeAndroidHapticPrimitiveTypeThe type of the primitive.0.2.0

PlayPatternOptions

PropTypeDescriptionSince
eventsHapticEvent[]The haptic events that make up the pattern.0.1.0
parameterCurvesHapticParameterCurve[]The curves that change a parameter of the whole pattern over time, for example an intensity that ramps up. Only available on iOS.0.2.0

HapticEvent

PropTypeDescriptionDefaultSince
durationnumberThe duration of the event in milliseconds. If omitted, the event is a transient tap.0.1.0
intensitynumberThe intensity of the event as a value between 0 and 1. On Android, the intensity is only respected on devices with amplitude control.0.1.0
sharpnessnumberThe sharpness of the event as a value between 0 and 1. A lower value results in a rounder, softer feedback while a higher value results in a crisper, more precise feedback. Only available on iOS.0.50.1.0
timenumberThe relative time at which the event occurs, in milliseconds.0.1.0

HapticParameterCurve

PropTypeDescriptionSince
controlPointsHapticParameterCurveControlPoint[]The control points of the curve, at most 16. The value is interpolated linearly between consecutive control points.0.2.0
parameterHapticParameterThe parameter the curve controls.0.2.0

HapticParameterCurveControlPoint

PropTypeDescriptionSince
timenumberThe time of the control point relative to the start of the pattern, in milliseconds.0.2.0
valuenumberThe value of the parameter at this control point.0.2.0

VibrateOptions

PropTypeDescriptionDefaultSince
durationnumberThe duration of the vibration in milliseconds. Only available on Android and Web.3000.1.0

Enums

ImpactStyle

MembersValueDescriptionSince
Heavy'HEAVY'A collision between large, heavy user interface elements.0.1.0
Light'LIGHT'A collision between small, light user interface elements.0.1.0
Medium'MEDIUM'A collision between moderately sized user interface elements.0.1.0
Rigid'RIGID'A collision between hard or inflexible user interface elements.0.1.0
Soft'SOFT'A collision between soft or flexible user interface elements.0.1.0

NotificationType

MembersValueDescriptionSince
Error'ERROR'A task or action has failed.0.1.0
Success'SUCCESS'A task or action has completed successfully.0.1.0
Warning'WARNING'A task or action has produced a warning.0.1.0

AndroidHapticFeedbackType

MembersValueDescriptionSince
ClockTick'CLOCK_TICK'The user has pressed either an hour or minute tick of a clock.0.1.0
Confirm'CONFIRM'The confirmation of a user's action. On Android 10 and older, ContextClick is performed instead.0.1.0
ContextClick'CONTEXT_CLICK'The user has performed a context click on an object.0.1.0
KeyboardTap'KEYBOARD_TAP'The user has pressed a virtual or software keyboard key.0.1.0
LongPress'LONG_PRESS'The user has performed a long press on an object.0.1.0
Reject'REJECT'The rejection or failure of a user's action. On Android 10 and older, LongPress is performed instead.0.1.0
ToggleOff'TOGGLE_OFF'The user has toggled a switch or button into the off position. On Android 13 and older, ClockTick is performed instead.0.1.0
ToggleOn'TOGGLE_ON'The user has toggled a switch or button into the on position. On Android 13 and older, ClockTick is performed instead.0.1.0
VirtualKey'VIRTUAL_KEY'The user has pressed on a virtual on-screen key.0.1.0

AndroidHapticPrimitiveType

MembersValueDescriptionSince
Click'CLICK'A sharp, crisp click.0.2.0
LowTick'LOW_TICK'A very short, low frequency tick.0.2.0
QuickFall'QUICK_FALL'A quick downwards movement with gravity.0.2.0
QuickRise'QUICK_RISE'A quick upwards movement against gravity.0.2.0
SlowRise'SLOW_RISE'A slow upwards movement against gravity.0.2.0
Spin'SPIN'A spinning momentum.0.2.0
Thud'THUD'A downwards movement with gravity, ending in a collision.0.2.0
Tick'TICK'A very short, light and crisp tick.0.2.0

HapticParameter

MembersValueDescriptionSince
Intensity'INTENSITY'Multiplies the intensity of every event. Control point values range from 0 to 1.0.2.0
Sharpness'SHARPNESS'Offsets the sharpness of every event. Control point values range from -1 to 1.0.2.0

Migrating from @capacitor/haptics

This plugin is a drop-in replacement for the official @capacitor/haptics plugin with a few differences:

@capacitor/hapticsHaptics
impact() (defaults to ImpactStyle.Heavy)impact() (defaults to ImpactStyle.Medium)
impact({ style }) (Heavy, Medium, Light)impact({ style }) (plus the new Rigid and Soft styles)
notification({ type })notification({ type })
vibrate({ duration })vibrate({ duration })
selectionStart()selectionStart()
selectionChanged()selectionChanged()
selectionEnd()selectionEnd()
—isAvailable()
—performAndroidHapticFeedback({ type })
—playPattern({ events })

Attention: The default impact style changed from ImpactStyle.Heavy to ImpactStyle.Medium. If you rely on the old default, pass ImpactStyle.Heavy explicitly.

Platform behavior

The haptic capabilities of the platforms differ. This plugin maps every method to the best available platform API:

MethodAndroidiOSWeb
impact(...)Predefined or tuned vibration effectsUIImpactFeedbackGenerator (all 5 styles)Vibration API
notification(...)Tuned vibration waveformsUINotificationFeedbackGeneratorVibration API
selection*()Tick vibration effectUISelectionFeedbackGeneratorNo-op
vibrate(...)Vibrator with custom durationSystem vibration (fixed duration)Vibration API
performAndroidHapticFeedback(...)Haptic feedback constants (no vibrator)Not availableNot available
playAndroidComposition(...)Composition of haptic primitivesNot availableNot available
playPattern(...)Vibration effects (composition or waveform)Core Haptics (intensity, sharpness and parameter curves)Vibration API

Custom haptic patterns are strongest on iOS, where Core Haptics supports per-event intensity and sharpness. On Android, patterns are approximated using vibration effect primitives (Android 12+ with supported hardware) or amplitude-controlled waveforms. On the web, patterns are approximated using the Vibration API, which only supports on/off timings.

FAQ

How is this plugin different from other similar plugins?

It covers the full range of haptic feedback through one fully typed API: impacts with five styles including the modern Rigid and Soft, notification and selection feedback, custom patterns with per-event intensity and sharpness via Core Haptics on iOS, semantic Android effects that respect the user's system settings, and an availability check — consistently across Android, iOS, and best-effort Web. It is actively maintained against the latest Capacitor and OS versions. If you only need a simple vibration, a minimal setup is fine; if you want rich, platform-aware haptics, this plugin is designed for exactly that.

How is this plugin different from the official Capacitor Haptics plugin?

This plugin is a drop-in replacement for the official @capacitor/haptics plugin with additional features: an isAvailable() method, semantic Android haptic effects via performAndroidHapticFeedback(...), custom haptic patterns via playPattern(...), and the modern Rigid and Soft impact styles. Note that the default impact style is ImpactStyle.Medium instead of ImpactStyle.Heavy, see Migrating from @capacitor/haptics.

Do I need to configure any permissions?

No, the plugin already declares the android.permission.VIBRATE permission in its own manifest, so no additional configuration is required on Android. On iOS and Web, no configuration is required either.

Why don't I feel any haptic feedback on my device?

First, use the isAvailable() method to check whether haptic feedback is available: on Android it checks whether the device has a vibrator, on iOS whether the device supports haptic event playback, and on the web whether the Vibration API is supported. Also keep in mind that on Android, the intensity of haptic events is only respected on devices with amplitude control, and that performAndroidHapticFeedback(...) respects the user's haptic feedback settings.

Are custom haptic patterns supported on all platforms?

Custom patterns are strongest on iOS, where Core Haptics supports per-event intensity and sharpness; this requires a device with haptic event playback support (for example an iPhone with a Taptic Engine), otherwise the call rejects as unavailable. On Android, patterns are approximated using vibration effect primitives or amplitude-controlled waveforms. On the web, patterns are approximated using the Vibration API, which only supports on/off timings.

What is the difference between vibrate and playPattern?

The vibrate(...) method triggers a single vibration with a custom duration, whereby the duration is only respected on Android and Web (on iOS, a system vibration with a fixed duration is played). The playPattern(...) method plays a sequence of individual haptic events, each with its own time, intensity, sharpness, and duration.

Can I use this plugin with Ionic, React, Vue or Angular?

Yes, the plugin is framework-agnostic. It works in any Capacitor app regardless of the web framework, including Ionic with Angular, React, or Vue, as well as plain JavaScript projects.

  • Shake: Detect shake gestures, for example to respond with haptic feedback.
  • Silent Mode: Detect whether the device is in silent mode.
  • Volume: Control the volume and observe hardware volume button presses.

Newsletter

Stay up to date with the latest news and updates about the Capawesome, Capacitor, and Ionic ecosystem by subscribing to our Capawesome Newsletter.

Changelog

See CHANGELOG.md.

License

See LICENSE.

版本与发布记录

@capawesome/capacitor-haptics 共发布 5 个版本,首次发布于 2026/07/07;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.0latest2026/10/3010 天前
0.1.22026/09/022 个月前
0.1.12026/07/153 个月前
0.1.02026/07/143 个月前
0.0.12026/07/074 个月前

关于 @capawesome/capacitor-haptics 的常见问题

@capawesome/capacitor-haptics 是什么?

Capacitor plugin to provide haptic feedback such as impacts, notifications, vibrations and custom haptic patterns on Android, iOS, and Web.

如何安装 @capawesome/capacitor-haptics?

在项目目录运行 npm install @capawesome/capacitor-haptics,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@capacitor/core(>=8.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@capawesome/capacitor-haptics 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@capawesome/capacitor-haptics 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@capawesome/capacitor-haptics 可以商用吗?

@capawesome/capacitor-haptics 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@capawesome/capacitor-haptics 的下载量有多少?

根据 npm 官方下载统计,@capawesome/capacitor-haptics 在 2026/10/09 – 2026/11/07 这 30 天内被下载 8,244 次,日均约 275 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@capawesome/capacitor-haptics 还在维护吗?

最新版本 0.2.0 发布于 2026/10/30(10 天前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2026/07/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。