@capacitor/haptics
The Haptics API provides physical feedback to the user through touch or vibration.
On devices that don't have Taptic Engine or Vibrator, the API calls will resolve without performing any action.
Installโ
npm install @capacitor/haptics
npx cap sync
Exampleโ
import { Haptics, ImpactStyle } from '@capacitor/haptics';
const hapticsImpactMedium = async () => {
await Haptics.impact({ style: ImpactStyle.Medium });
};
const hapticsImpactLight = async () => {
await Haptics.impact({ style: ImpactStyle.Light });
};
const hapticsVibrate = async () => {
await Haptics.vibrate();
};
const hapticsSelectionStart = async () => {
await Haptics.selectionStart();
};
const hapticsSelectionChanged = async () => {
await Haptics.selectionChanged();
};
const hapticsSelectionEnd = async () => {
await Haptics.selectionEnd();
};
APIโ
impact(...)โ
impact(options?: ImpactOptions | undefined) => Promise<void>
Trigger a haptics "impact" feedback
Param | Type |
---|---|
options |
|
Since: 1.0.0
notification(...)โ
notification(options?: NotificationOptions | undefined) => Promise<void>
Trigger a haptics "notification" feedback
Param | Type |
---|---|
options |
|
Since: 1.0.0
vibrate(...)โ
vibrate(options?: VibrateOptions | undefined) => Promise<void>
Vibrate the device
Param | Type |
---|---|
options |
|
Since: 1.0.0
selectionStart()โ
selectionStart() => Promise<void>
Trigger a selection started haptic hint
Since: 1.0.0