Ioniconf 2022 logo

Uniting our global community of Ionic developers and contributors. May 25, 2022.

DocsPluginsCLI
iosandroid

Haptics

The Haptics API provides physical feedback to the user through touch or vibration.

Android Notes

To use vibration, you must add this permission to your AndroidManifest.xml file:

<uses-permission android:name="android.permission.VIBRATE" />

Example

import { Plugins, HapticsImpactStyle } from '@capacitor/core';

const { Haptics } = Plugins;

export class HapticsExample {
  hapticsImpact(style = HapticsImpactStyle.Heavy) {
    Haptics.impact({
      style: style,
    });
  }

  hapticsImpactMedium(style) {
    this.hapticsImpact(HapticsImpactStyle.Medium);
  }

  hapticsImpactLight(style) {
    this.hapticsImpact(HapticsImpactStyle.Light);
  }

  hapticsVibrate() {
    Haptics.vibrate();
  }

  hapticsSelectionStart() {
    Haptics.selectionStart();
  }

  hapticsSelectionChanged() {
    Haptics.selectionChanged();
  }

  hapticsSelectionEnd() {
    Haptics.selectionEnd();
  }
}

API

impact(…)

impact(options: HapticsImpactOptions) => void

Trigger a haptics “impact” feedback

Param Type
options HapticsImpactOptions

notification(…)

notification(options: HapticsNotificationOptions) => void

Trigger a haptics “notification” feedback

Param Type
options HapticsNotificationOptions

vibrate()

vibrate() => void

Vibrate the device


selectionStart()

selectionStart() => void

Trigger a selection started haptic hint


selectionChanged()

selectionChanged() => void

Trigger a selection changed haptic hint. If a selection was started already, this will cause the device to provide haptic feedback


selectionEnd()

selectionEnd() => void

If selectionStart() was called, selectionEnd() ends the selection. For example, call this when a user has lifted their finger from a control


Interfaces

HapticsImpactOptions

Prop Type
style HapticsImpactStyle

HapticsNotificationOptions

Prop Type
type HapticsNotificationType

Enums

HapticsImpactStyle

Members Value
Heavy "HEAVY"
Medium "MEDIUM"
Light "LIGHT"

HapticsNotificationType

Members Value
SUCCESS "SUCCESS"
WARNING "WARNING"
ERROR "ERROR"
Previous
<- Geolocation
Next
Keyboard ->
Contribute ->