API reference
Complete reference for the Haptics methods, types, and error codes.
Import
The library exports a default Haptics object that provides methods for triggering haptic feedback:
import Haptics from '@mhpdev/react-native-haptics';Methods
| Method | Returns | Platform | Description |
|---|---|---|---|
Haptics.impact(style) | Promise<void> | Both | Impact feedback, corresponding to UIImpactFeedbackGenerator on iOS. See Impact. |
Haptics.notification(type) | Promise<void> | Both | Notification feedback, corresponding to UINotificationFeedbackGenerator on iOS. See Notification. |
Haptics.selection() | Promise<void> | Both | Selection-change feedback, corresponding to UISelectionFeedbackGenerator on iOS. VIRTUAL_KEY on Android. See Selection. |
Haptics.androidHaptics(type) | Promise<void> | Android | Platform-specific Android feedback; a no-op on iOS. See Android-specific effects. |
Every method returns a promise that resolves when the haptic feedback is completed.
Types
ImpactFeedback
type ImpactFeedback = 'light' | 'medium' | 'heavy' | 'soft' | 'rigid';Corresponds to Apple's UIImpactFeedbackGenerator.FeedbackStyle. On Android, the behavior is simulated to match the iOS equivalent. soft and rigid require iOS 13.0+.
NotificationFeedback
type NotificationFeedback = 'success' | 'warning' | 'error';Corresponds to Apple's UINotificationFeedbackGenerator.FeedbackType. On Android, the behavior is simulated to match the iOS equivalent.
AndroidHapticsFeedback
type AndroidHapticsFeedback =
| 'clock-tick'
| 'confirm'
| 'context-click'
| 'drag-start'
| 'gesture-end'
| 'gesture-start'
| 'gesture-threshold-activate'
| 'gesture-threshold-deactivate'
| 'keyboard-press'
| 'keyboard-release'
| 'keyboard-tap'
| 'long-press'
| 'no-haptics'
| 'reject'
| 'segment-frequent-tick'
| 'segment-tick'
| 'text-handle-move'
| 'toggle-off'
| 'toggle-on'
| 'virtual-key'
| 'virtual-key-release';A set of predefined haptic types corresponding to Android's native HapticFeedbackConstants. Availability varies by Android SDK version; unsupported types fall back to virtual-key.
Error codes
| Code | Method | When it occurs |
|---|---|---|
E_INVALID_STYLE | impact | The style is not one of the ImpactFeedback values. |
E_INVALID_TYPE | notification | The type is not one of the NotificationFeedback values. |
E_INVALID_TYPE | androidHaptics | The type is not one of the AndroidHapticsFeedback values. |
E_NO_VIEW | androidHaptics | There is no current activity view to perform haptic feedback on. |
E_UNEXPECTED | Any | An unexpected native error occurred. |
Rejected promises carry the error code and a descriptive message; invalid values list the allowed values in the message.
Native module
The Turbo Module is registered as Haptics. All methods above are declared in the library's Spec, so they are fully type-safe when written in TypeScript.