Lightweight, fast haptics for React Native powered by Nitro Modules. Supports simple presets and fully custom haptic patterns on iOS and Android.
This library was primarily generated by ChatGPT. The author does not know C++, Kotlin, or Swift. Use at your own risk; reviews and contributions are welcome.
Install the library and Nitro Modules:
npm i react-native-nitro-haptic react-native-nitro-modules
# or
bun add react-native-nitro-haptic react-native-nitro-modules
# or
yarn add react-native-nitro-haptic react-native-nitro-modulesiOS pods:
npx pod-installThen rebuild your app.
Notes
- Android vibrate permission is included by the library manifest
- iOS Core Haptics custom patterns require iOS 13+; presets work on older iOS via UIKit feedback generators
Trigger a preset or play a custom pattern
import { notify, play } from 'react-native-nitro-haptic'
notify('selection')
play({
events: [
{ eventType: 'hapticTransient', time: 0, parameters: { intensity: 1, sharpness: 0.6 } },
{ eventType: 'hapticTransient', time: 0.2, parameters: { intensity: 0.8, sharpness: 0.3 } }
]
})Check availability
import { NitroHaptic } from 'react-native-nitro-haptic'
if (NitroHaptic.isAvailable()) {
notify('impactMedium')
}Available HapticPreset values
'selection' | 'impactLight' | 'impactMedium' | 'impactHeavy' | 'impactSoft' | 'impactRigid' | 'notificationSuccess' | 'notificationWarning' | 'notificationError'
| Name | Type | Description |
|---|---|---|
| notify | (preset: HapticPreset) => void | Triggers a one-shot preset. Cross‑platform. |
| play | (pattern: HapticPattern) => Promise | Plays a custom haptic pattern. On iOS uses Core Haptics; on Android approximates with waveform. |
| NitroHaptic | Haptic | The underlying Nitro hybrid object exposing isAvailable, notify, play. |
| HapticPreset | union | See Presets list above. |
| HapticPattern | { events: HapticEvent[] } | Pattern container. |
| HapticEvent | { eventType, time, eventDuration?, parameters? } | Single event within a pattern. |
| HapticEventType | 'hapticTransient' | 'hapticContinuous' | Event kind: transient tap or continuous buzz. |
| HapticParameters | { intensity?: number; sharpness?: number } | Both in [0..1]. |
Event fields
- eventType: 'hapticTransient' or 'hapticContinuous'
- time: seconds from pattern start (number)
- eventDuration: duration in seconds for continuous events
- parameters.intensity: 0..1 amplitude
- parameters.sharpness: 0..1 brightness (iOS); used to shape transient length on Android
Heartbeat
import { play } from 'react-native-nitro-haptic'
play({
events: [
{ eventType: 'hapticTransient', time: 0, parameters: { intensity: 0.8, sharpness: 0.2 } },
{ eventType: 'hapticTransient', time: 0.2, parameters: { intensity: 1, sharpness: 0.3 } }
]
})Crescendo
play({
events: Array.from({ length: 8 }).map((_, i) => ({
eventType: 'hapticTransient' as const,
time: i * 0.06,
parameters: { intensity: Math.min(0.2 + i * 0.1, 1), sharpness: 0.3 + i * 0.05 }
}))
})Use the helper map to keep familiar names
import { RNHFPresetToNitro, notify } from 'react-native-nitro-haptic'
notify(RNHFPresetToNitro.rigid)
notify(RNHFPresetToNitro.notificationSuccess)- iOS: Presets are backed by
UI*FeedbackGenerator. Custom patterns use Core Haptics and require a device with haptics (iOS 13+). On devices without Core Haptics,playresolves without producing haptics. - Android: Presets and patterns use
Vibrator/VibrationEffect. On API < 26, patterns degrade to a single vibration; on API 26+, waveforms with custom amplitudes are used.
See example for a runnable showcase with multiple presets and patterns.
MIT
—
Made with create-react-native-library