
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
react-native-haptic-patterns
Advanced tools
A React Native library for creating and playing customizable haptic feedback patterns on iOS and Android. Supports advanced pattern recording and playback.

A React Native library for creating and playing customizable haptic feedback patterns on iOS and Android. Supports advanced pattern recording and playback, enabling developers to deliver rich, tactile experiences in their mobile applications.
Features | Requirements | Installation | Usage | Methods | Types | Examples | Troubleshooting | License
Add the following permission to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.VIBRATE" />
Here's how to get started with react-native-haptic-patterns in your React Native project:
1. Install the package
npm install react-native-haptic-patterns
Or using Yarn:
yarn add react-native-haptic-patterns
2. Install iOS dependencies
cd ios && pod install && cd ..
Or using npx:
npx pod-install
3. Configure Android permissions
Add the vibration permission to android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.VIBRATE" />
Import and use the library in your React Native app:
import React from 'react';
import { Button, View } from 'react-native';
import { HapticPatterns } from 'react-native-haptic-patterns';
const MyComponent = () => {
const handlePress = async () => {
try {
// Check if device supports haptics
const isSupported = await HapticPatterns.checkForHapticSupport();
if (isSupported) {
// Play a 200ms haptic pattern
HapticPatterns.playHapticPattern(200);
} else {
console.log('Haptics not supported on this device');
}
} catch (error) {
console.error('Haptic error:', error);
}
};
return (
<View>
<Button onPress={handlePress} title="Feel the Haptic" />
</View>
);
};
import { HapticPatterns } from 'react-native-haptic-patterns';
// Check haptic support
const isSupported = await HapticPatterns.checkForHapticSupport();
// Play a simple haptic pattern
HapticPatterns.playHapticPattern(200); // Vibrate for 200ms
// Stop the current haptic pattern
HapticPatterns.stopHapticPattern();
// Play a recorded pattern
const recordedEvents = [
{ startTime: 0, endTime: 100, isPause: false },
{ startTime: 100, endTime: 200, isPause: true },
{ startTime: 200, endTime: 400, isPause: false },
];
await HapticPatterns.playRecordedPattern(recordedEvents);
import {
HapticPatterns,
RecordedEventType,
} from 'react-native-haptic-patterns';
const playCustomPattern = () => {
// Create a custom haptic pattern
const pattern: RecordedEventType[] = [
{ startTime: 0, endTime: 100, isPause: false }, // Short vibration
{ startTime: 100, endTime: 200, isPause: true }, // Pause
{ startTime: 200, endTime: 400, isPause: false }, // Longer vibration
{ startTime: 400, endTime: 500, isPause: true }, // Pause
{ startTime: 500, endTime: 600, isPause: false }, // Final vibration
];
try {
HapticPatterns.playRecordedPattern(pattern);
console.log('Pattern playback completed');
} catch (error) {
console.error('Pattern playback error:', error);
}
};
// Use in different scenarios
const provideSuccessFeedback = () => {
HapticPatterns.playHapticPattern(50); // Quick tap
};
const provideErrorFeedback = async () => {
const errorPattern: RecordedEventType[] = [
{ startTime: 0, endTime: 100, isPause: false },
{ startTime: 100, endTime: 150, isPause: true },
{ startTime: 150, endTime: 250, isPause: false },
];
await HapticPatterns.playRecordedPattern(errorPattern);
};
checkForHapticSupport(): Promise<boolean>
Checks if the device supports haptic feedback.
Platform behavior:
true as Android devices support haptic feedback through the Vibration API.Returns:
true if haptics are supported, false otherwise.playHapticPattern(vibrationDuration: number): Promise<void>
Plays a custom haptic pattern for the specified duration.
Parameters:
vibrationDuration: Duration of the vibration in milliseconds.Platform behavior:
Returns:
stopHapticPattern(): Promise<void>
Stops the currently playing haptic pattern.
Platform behavior:
Returns:
playRecordedPattern(recordedEvents: RecordedEventType[]): Promise<void>
Plays a recorded haptic pattern.
Parameters:
recordedEvents: An array of recorded haptic or pause events, each with { startTime, endTime, isPause }.Platform behavior:
Returns:
Represents a single event in a recorded haptic pattern.
interface RecordedEventType {
startTime: number; // Start time in milliseconds
endTime: number; // End time in milliseconds
isPause: boolean; // Whether this is a pause (true) or haptic event (false)
}
Example:
const pattern: RecordedEventType[] = [
{ startTime: 0, endTime: 100, isPause: false }, // Vibrate for 100ms
{ startTime: 100, endTime: 200, isPause: true }, // Pause for 100ms
{ startTime: 200, endTime: 300, isPause: false }, // Vibrate for 100ms
];
To better understand how to use these methods in a real-world scenario, refer to the following full working example project:
Example App: Demonstrates how to record, play, and reset custom haptic patterns using the library's API in a React Native application.
Button Press Feedback
<TouchableOpacity
onPress={() => {
HapticPatterns.playHapticPattern(50);
// Handle button action
}}>
<Text>Press Me</Text>
</TouchableOpacity>
Success/Error Notifications
const showSuccessNotification = () => {
HapticPatterns.playHapticPattern(100); // Single haptic
// Show success message
};
const showErrorNotification = async () => {
const errorPattern: RecordedEventType[] = [
{ startTime: 0, endTime: 50, isPause: false },
{ startTime: 50, endTime: 100, isPause: true },
{ startTime: 100, endTime: 150, isPause: false },
];
await HapticPatterns.playRecordedPattern(errorPattern);
// Show error message
};
Long Press Detection
<TouchableOpacity
onLongPress={() => {
HapticPatterns.playHapticPattern(150);
// Handle long press
}}>
<Text>Long Press Me</Text>
</TouchableOpacity>
Haptics not working on simulator
Build errors after installation
cd ios && pod install && cd .. to ensure CocoaPods are properly installed.Product > Clean Build Folder (Shift + Cmd + K)rm -rf ~/Library/Developer/Xcode/DerivedDataHaptics not working on device
Vibration not working
VIBRATE permission to AndroidManifest.xmlBuild errors
cd android && ./gradlew clean && cd ..rm -rf android/app/buildFile > Invalidate Caches / RestartPermission denied errors
VIBRATE permission is in the correct location in AndroidManifest.xmlModule not found errors
npm install or yarn installnpx react-native start --reset-cachenpx react-native run-ios or npx react-native run-androidThis library uses and modifies the iOS implementation from react-native-core-haptics-api for customization.
Support it by joining stargazers for this repository.⭐
For bugs, feature requests, and discussion please use GitHub Issues, GitHub New Feature, GitHub Feedback
We'd love to have you improve this library or fix a problem 💪 Check out our Contributing Guide for ideas on contributing.
FAQs
A React Native library for creating and playing customizable haptic feedback patterns on iOS and Android. Supports advanced pattern recording and playback.
We found that react-native-haptic-patterns demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.