react-native-haptic-engine
v1.0.3
Published
Advanced haptic feedback and vibration control using Pure JSI for React Native
Downloads
11
Maintainers
Readme
react-native-haptic-engine 📳
A unified, high-performance haptic feedback & vibration library for React Native.
Bridge the gap between Android’s precise Vibrator API and iOS’s Taptic Engine with a single, simple function.
✨ Features
📳 Unified API
One function works seamlessly on both Android and iOS.🤖 Android Precision
Control exact duration (milliseconds) and intensity (1–255).🍏 iOS Taptic Support
Automatically maps vibration strength to Light / Medium / Heavy impact styles.⚡ Zero Lag
Pure native implementation for instant feedback.📱 Expo Compatible
Works with Expo Development Builds (CNG).📦 Zero Dependencies
📦 Installation
npm install react-native-haptic-engine🍏 iOS Setup (React Native CLI only)
If you are using React Native CLI, install CocoaPods:
cd ios && pod install && cd ..📱 Expo Support
This library includes custom native code and will NOT work in Expo Go.
You must use a Development Build.
Steps
- Install the package:
npm install react-native-haptic-engine- Rebuild your app:
npx expo run:android
# or
npx expo run:ios✅ Final Verdict
| Environment | Supported | |-----------|-----------| | React Native CLI | ✅ Yes | | Expo Dev Client | ✅ Yes | | Expo Go | ❌ No |
🚀 Usage
import { vibrate, stop } from 'react-native-haptic-engine';
// 1. Light Tick (toggle / selection)
// Android: 50ms at low power
// iOS: Light Impact
vibrate(50, 40);
// 2. Normal Tap (button press)
// Android: 100ms at medium power
// iOS: Medium Impact
vibrate(100, 150);
// 3. Heavy Thud (error / explosion)
// Android: 500ms at max power
// iOS: Heavy Impact
vibrate(500, 255);
// 4. Stop vibration (Android only)
stop();📚 API Reference
vibrate(milliseconds, amplitude)
Triggers a haptic / vibration event.
| Parameter | Type | Default | Description | |---------|------|---------|-------------| | milliseconds | number | 400 | Android only. Duration of vibration. Ignored on iOS | | amplitude | number | 255 | Intensity from 1–255 |
📱 Platform Behavior Mapping
| Amplitude Range | Android Behavior | iOS Behavior | |----------------|-----------------|--------------| | 1 – 50 | Low intensity vibration | UIImpactFeedbackStyle.Light | | 51 – 150 | Medium intensity vibration | UIImpactFeedbackStyle.Medium | | 151 – 255 | High intensity vibration | UIImpactFeedbackStyle.Heavy |
stop()
Stops any ongoing vibration.
| Platform | Behavior | |--------|----------| | Android | Stops vibration immediately | | iOS | No-op (impact haptics are instantaneous) |
🛠 Troubleshooting
❌ "Native module not found"
Cause:
Running the app in Expo Go.
Fix:
Build a development client:
npx expo run:android
# or
npx expo run:ios❌ Vibration not working on Android
- Ensure the device is not in Silent / Do Not Disturb mode
- Some OEMs disable vibration in silent mode
- No manual permissions needed
The library automatically adds:
<uses-permission android:name="android.permission.VIBRATE" />📄 License
MIT
Author: Vasanth S
