The Haptics API provides physical feedback to the user through touch or vibration.
To use vibration, you must add this permission to your AndroidManifest.xml
file:
<uses-permission android:name="android.permission.VIBRATE" />
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();
}
}
impact(options: HapticsImpactOptions, x?: number | undefined) => Promise<HapticsImpact>
Trigger a haptics "impact" feedback
Param | Type | Description |
---|---|---|
options | HapticsImpactOptions | The impact options |
x | number |
Returns: Promise<HapticsImpact>
Since: 1.0.0
notification(options?: HapticsNotificationOptions | undefined) => Promise<string | number>
Trigger a haptics "notification" feedback
Param | Type |
---|---|
options | HapticsNotificationOptions |
Returns: Promise<string | number>
Since: 1.0.0
vibrate(options?: VibrateOptions | undefined) => Promise<number>
Vibrate the device
Param | Type |
---|---|
options | VibrateOptions |
Returns: Promise<number>
Since: 1.0.0
selectionStart(value: number | string) => Promise<void>
Trigger a selection started haptic hint
Param | Type |
---|---|
value | string | number |
Returns: Promise<void>
Since: 1.0.0
Prop | Type |
---|---|
value | number |
Prop | Type | Description | Default | Since |
---|---|---|---|---|
style | HapticsImpactStyle | Impact Feedback Style The mass of the objects in the collision simulated by a UIImpactFeedbackGenerator object. | HapticsImpactStyle.Heavy | 1.0.0 |
value | boolean |
Prop | Type | Description | Default | Since |
---|---|---|---|---|
type | HapticsNotificationType | Notification Feedback Type The type of notification feedback generated by a UINotificationFeedbackGenerator object. | HapticsNotificationType.SUCCESS | 1.0.0 |
Prop | Type | Description | Default | Since |
---|---|---|---|---|
duration | number | Duration of the vibration in milliseconds. Not supported in iOS. | 300 | 1.0.0 |
Members | Value | Description | Since |
---|---|---|---|
Heavy | 'HEAVY' | A collision between small, light user interface elements | 1.0.0 |
Medium | 'MEDIUM' | A collision between moderately sized user interface elements | 1.0.0 |
Light | 'LIGHT' | A collision between small, light user interface elements | 1.0.0 |
Members | Value | Description | Since |
---|---|---|---|
SUCCESS | 'SUCCESS' | A notification feedback type indicating that a task has completed successfully | 1.0.0 |
WARNING | 'WARNING' | A notification feedback type indicating that a task has produced a warning | 1.0.0 |
ERROR | 'ERROR' | A notification feedback type indicating that a task has failed | 1.0.0 |