{"id":31841893,"url":"https://github.com/simformsolutionspvtltd/react-native-haptic-patterns","last_synced_at":"2026-01-20T16:55:41.529Z","repository":{"id":318719686,"uuid":"952329049","full_name":"SimformSolutionsPvtLtd/react-native-haptic-patterns","owner":"SimformSolutionsPvtLtd","description":"A React Native library to create, record, and play customizable haptic feedback patterns on iOS and Android.","archived":false,"fork":false,"pushed_at":"2025-10-10T10:05:51.000Z","size":1069,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-11T23:52:29.536Z","etag":null,"topics":["android","component","haptic-feedback","ios","library","react-native","typescript","vibration"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SimformSolutionsPvtLtd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-03-21T05:24:53.000Z","updated_at":"2025-10-10T10:53:56.000Z","dependencies_parsed_at":"2025-10-11T23:53:06.102Z","dependency_job_id":"ff37f552-700d-4033-ae19-16336a908f5f","html_url":"https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns","commit_stats":null,"previous_names":["simformsolutionspvtltd/react-native-haptic-patterns"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/SimformSolutionsPvtLtd/react-native-haptic-patterns","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimformSolutionsPvtLtd%2Freact-native-haptic-patterns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimformSolutionsPvtLtd%2Freact-native-haptic-patterns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimformSolutionsPvtLtd%2Freact-native-haptic-patterns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimformSolutionsPvtLtd%2Freact-native-haptic-patterns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SimformSolutionsPvtLtd","download_url":"https://codeload.github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SimformSolutionsPvtLtd%2Freact-native-haptic-patterns/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010341,"owners_count":26084738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","component","haptic-feedback","ios","library","react-native","typescript","vibration"],"created_at":"2025-10-12T05:54:42.901Z","updated_at":"2025-10-12T05:54:44.122Z","avatar_url":"https://github.com/SimformSolutionsPvtLtd.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![React Native Haptic Patterns - Simform](./assets/react-native-haptic-patterns.png)\n\n# react-native-haptic-patterns\n\n[![react-native-haptic-patterns on npm](https://img.shields.io/npm/v/react-native-haptic-patterns.svg?style=flat)](https://www.npmjs.com/package/react-native-haptic-patterns) [![react-native-haptic-patterns downloads](https://img.shields.io/npm/dm/react-native-haptic-patterns)](https://www.npmtrends.com/react-native-haptic-patterns) [![react-native-haptic-patterns install size](https://packagephobia.com/badge?p=react-native-haptic-patterns)](https://packagephobia.com/result?p=react-native-haptic-patterns) [![Android](https://img.shields.io/badge/Platform-Android-green?logo=android)](https://www.android.com) [![iOS](https://img.shields.io/badge/Platform-iOS-green?logo=apple)](https://developer.apple.com/ios) [![MIT](https://img.shields.io/badge/License-MIT-green)](https://opensource.org/licenses/MIT)\n\nA 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.\n\n---\n\n## ✨ Features\n\n- ✅ **Cross-platform support** - Works seamlessly on both iOS and Android\n- ✅ **Custom haptic patterns** - Create your own vibration patterns with precise control\n- ✅ **Pattern recording \u0026 playback** - Record and replay complex haptic sequences\n- ✅ **Core Haptics API** - Leverage iOS's advanced haptic engine (iOS 13+)\n- ✅ **TypeScript support** - Full type definitions included\n- ✅ **Simple API** - Easy-to-use methods with Promise-based interface\n- ✅ **Lightweight** - Minimal dependencies and small bundle size\n\n---\n\n## Quick Access\n\n[Features](#-features) | [Requirements](#requirements) | [Installation](#installation) | [Usage](#usage) | [Methods](#methods) | [Types](#types) | [Examples](#examples) | [Troubleshooting](#troubleshooting) | [License](#license)\n\n---\n\n## Requirements\n\n- **React Native** \u003e= 0.70.0\n- **iOS** \u003e= 13.0 (for Core Haptics support)\n- **Android** API \u003e= 29 (Android 9.0+)\n\n### Permissions\n\n#### Android\n\nAdd the following permission to your `android/app/src/main/AndroidManifest.xml`:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.VIBRATE\" /\u003e\n```\n\n---\n\n## Getting Started\n\nHere's how to get started with `react-native-haptic-patterns` in your React Native project:\n\n### Installation\n\n**1. Install the package**\n\n```sh\nnpm install react-native-haptic-patterns\n```\n\nOr using Yarn:\n\n```sh\nyarn add react-native-haptic-patterns\n```\n\n**2. Install iOS dependencies**\n\n```sh\ncd ios \u0026\u0026 pod install \u0026\u0026 cd ..\n```\n\nOr using npx:\n\n```sh\nnpx pod-install\n```\n\n**3. Configure Android permissions**\n\nAdd the vibration permission to `android/app/src/main/AndroidManifest.xml`:\n\n```xml\n\u003cuses-permission android:name=\"android.permission.VIBRATE\" /\u003e\n```\n\n## Usage\n\n### Basic Example\n\nImport and use the library in your React Native app:\n\n```tsx\nimport React from 'react';\nimport { Button, View } from 'react-native';\nimport { HapticPatterns } from 'react-native-haptic-patterns';\n\nconst MyComponent = () =\u003e {\n  const handlePress = async () =\u003e {\n    try {\n      // Check if device supports haptics\n      const isSupported = await HapticPatterns.checkForHapticSupport();\n\n      if (isSupported) {\n        // Play a 200ms haptic pattern\n        HapticPatterns.playHapticPattern(200);\n      } else {\n        console.log('Haptics not supported on this device');\n      }\n    } catch (error) {\n      console.error('Haptic error:', error);\n    }\n  };\n\n  return (\n    \u003cView\u003e\n      \u003cButton onPress={handlePress} title=\"Feel the Haptic\" /\u003e\n    \u003c/View\u003e\n  );\n};\n```\n\n### Quick Start\n\n```tsx\nimport { HapticPatterns } from 'react-native-haptic-patterns';\n\n// Check haptic support\nconst isSupported = await HapticPatterns.checkForHapticSupport();\n\n// Play a simple haptic pattern\nHapticPatterns.playHapticPattern(200); // Vibrate for 200ms\n\n// Stop the current haptic pattern\nHapticPatterns.stopHapticPattern();\n\n// Play a recorded pattern\nconst recordedEvents = [\n  { startTime: 0, endTime: 100, isPause: false },\n  { startTime: 100, endTime: 200, isPause: true },\n  { startTime: 200, endTime: 400, isPause: false },\n];\n\nawait HapticPatterns.playRecordedPattern(recordedEvents);\n```\n\n### Advanced Pattern Example\n\n```tsx\nimport {\n  HapticPatterns,\n  RecordedEventType,\n} from 'react-native-haptic-patterns';\n\nconst playCustomPattern = () =\u003e {\n  // Create a custom haptic pattern\n  const pattern: RecordedEventType[] = [\n    { startTime: 0, endTime: 100, isPause: false }, // Short vibration\n    { startTime: 100, endTime: 200, isPause: true }, // Pause\n    { startTime: 200, endTime: 400, isPause: false }, // Longer vibration\n    { startTime: 400, endTime: 500, isPause: true }, // Pause\n    { startTime: 500, endTime: 600, isPause: false }, // Final vibration\n  ];\n\n  try {\n    HapticPatterns.playRecordedPattern(pattern);\n    console.log('Pattern playback completed');\n  } catch (error) {\n    console.error('Pattern playback error:', error);\n  }\n};\n\n// Use in different scenarios\nconst provideSuccessFeedback = () =\u003e {\n  HapticPatterns.playHapticPattern(50); // Quick tap\n};\n\nconst provideErrorFeedback = async () =\u003e {\n  const errorPattern: RecordedEventType[] = [\n    { startTime: 0, endTime: 100, isPause: false },\n    { startTime: 100, endTime: 150, isPause: true },\n    { startTime: 150, endTime: 250, isPause: false },\n  ];\n  await HapticPatterns.playRecordedPattern(errorPattern);\n};\n```\n\n## Methods\n\n### checkForHapticSupport\n\n```ts\ncheckForHapticSupport(): Promise\u003cboolean\u003e\n```\n\nChecks if the device supports haptic feedback.\n\nPlatform behavior:\n\n- **Android:** Always returns `true` as Android devices support haptic feedback through the Vibration API.\n- **iOS:** Queries the device's Core Haptics capabilities to determine if haptic feedback is supported.\n\nReturns:\n\n- A Promise that resolves to `true` if haptics are supported, `false` otherwise.\n\n---\n\n### playHapticPattern\n\n```ts\nplayHapticPattern(vibrationDuration: number): Promise\u003cvoid\u003e\n```\n\nPlays a custom haptic pattern for the specified duration.\n\nParameters:\n\n- `vibrationDuration`: Duration of the vibration in milliseconds.\n\nPlatform behavior:\n\n- **Android:** Uses the Vibration API.\n- **iOS:** Builds and plays a haptic pattern using Core Haptics.\n\nReturns:\n\n- A Promise that resolves when the pattern has started playing.\n\n---\n\n### stopHapticPattern\n\n```ts\nstopHapticPattern(): Promise\u003cvoid\u003e\n```\n\nStops the currently playing haptic pattern.\n\nPlatform behavior:\n\n- **Android:** Cancels vibration.\n- **iOS:** Stops the HapticEngine player.\n\nReturns:\n\n- A Promise that resolves when the pattern has been stopped.\n\n---\n\n### playRecordedPattern\n\n```ts\nplayRecordedPattern(recordedEvents: RecordedEventType[]): Promise\u003cvoid\u003e\n```\n\nPlays a recorded haptic pattern.\n\nParameters:\n\n- `recordedEvents`: An array of recorded haptic or pause events, each with `{ startTime, endTime, isPause }`.\n\nPlatform behavior:\n\n- **Android:** Converts events to a vibration pattern array and plays it.\n- **iOS:** Converts events to haptic events and plays them using Core Haptics.\n\nReturns:\n\n- A Promise that resolves when the entire pattern has finished playing.\n\n---\n\n## Types\n\n### RecordedEventType\n\nRepresents a single event in a recorded haptic pattern.\n\n```ts\ninterface RecordedEventType {\n  startTime: number; // Start time in milliseconds\n  endTime: number; // End time in milliseconds\n  isPause: boolean; // Whether this is a pause (true) or haptic event (false)\n}\n```\n\n**Example:**\n\n```ts\nconst pattern: RecordedEventType[] = [\n  { startTime: 0, endTime: 100, isPause: false }, // Vibrate for 100ms\n  { startTime: 100, endTime: 200, isPause: true }, // Pause for 100ms\n  { startTime: 200, endTime: 300, isPause: false }, // Vibrate for 100ms\n];\n```\n\n---\n\n## Examples\n\nTo better understand how to use these methods in a real-world scenario, refer to the following full working example project:\n\n[Example App](./example/src/App.tsx): Demonstrates how to record, play, and reset custom haptic patterns using the library's API in a React Native application.\n\n### Common Use Cases\n\n**Button Press Feedback**\n\n```tsx\n\u003cTouchableOpacity\n  onPress={() =\u003e {\n    HapticPatterns.playHapticPattern(50);\n    // Handle button action\n  }}\u003e\n  \u003cText\u003ePress Me\u003c/Text\u003e\n\u003c/TouchableOpacity\u003e\n```\n\n**Success/Error Notifications**\n\n```tsx\nconst showSuccessNotification = () =\u003e {\n  HapticPatterns.playHapticPattern(100); // Single haptic\n  // Show success message\n};\n\nconst showErrorNotification = async () =\u003e {\n  const errorPattern: RecordedEventType[] = [\n    { startTime: 0, endTime: 50, isPause: false },\n    { startTime: 50, endTime: 100, isPause: true },\n    { startTime: 100, endTime: 150, isPause: false },\n  ];\n  await HapticPatterns.playRecordedPattern(errorPattern);\n  // Show error message\n};\n```\n\n**Long Press Detection**\n\n```tsx\n\u003cTouchableOpacity\n  onLongPress={() =\u003e {\n    HapticPatterns.playHapticPattern(150);\n    // Handle long press\n  }}\u003e\n  \u003cText\u003eLong Press Me\u003c/Text\u003e\n\u003c/TouchableOpacity\u003e\n```\n\n---\n\n## Troubleshooting\n\n### iOS\n\n**Haptics not working on simulator**\n\n- Core Haptics only works on physical devices. Test on a real iPhone (iPhone 8 or newer recommended for best haptic support).\n\n**Build errors after installation**\n\n- Run `cd ios \u0026\u0026 pod install \u0026\u0026 cd ..` to ensure CocoaPods are properly installed.\n- Clean build folder in Xcode: `Product` \u003e `Clean Build Folder` (Shift + Cmd + K)\n- Delete derived data: `rm -rf ~/Library/Developer/Xcode/DerivedData`\n\n**Haptics not working on device**\n\n- Ensure the device supports Core Haptics (iPhone 8 and newer)\n- Check that haptic feedback is enabled in device settings\n- Verify iOS version is 13.0 or higher\n\n### Android\n\n**Vibration not working**\n\n- Ensure you've added the `VIBRATE` permission to `AndroidManifest.xml`\n- Check that vibration is enabled in device settings\n- Some devices may have battery optimization that affects vibration\n\n**Build errors**\n\n- Try cleaning the build: `cd android \u0026\u0026 ./gradlew clean \u0026\u0026 cd ..`\n- Delete build folders: `rm -rf android/app/build`\n- Invalidate caches in Android Studio: `File` \u003e `Invalidate Caches / Restart`\n\n**Permission denied errors**\n\n- Verify the `VIBRATE` permission is in the correct location in `AndroidManifest.xml`\n- Check that the permission is not being removed by other configurations\n\n### General\n\n**Module not found errors**\n\n- Ensure the package is properly installed: `npm install` or `yarn install`\n- Try resetting Metro bundler cache: `npx react-native start --reset-cache`\n- Rebuild the app completely: `npx react-native run-ios` or `npx react-native run-android`\n\n---\n\n## Acknowledgements\n\nThis library uses and modifies the iOS implementation from [react-native-core-haptics-api](https://github.com/insanj/react-native-core-haptics-api) for customization.\n\n## Find this library useful? ❤️\n\nSupport it by joining [stargazers](https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/stargazers) for this repository.⭐\n\n## Bugs / Feature requests / Feedbacks\n\nFor bugs, feature requests, and discussion please use [GitHub Issues](https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/issues/new?labels=bug\u0026template=BUG_REPORT.md\u0026title=%5BBUG%5D%3A), [GitHub New Feature](https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/issues/new?labels=enhancement\u0026template=FEATURE_REQUEST.md\u0026title=%5BFEATURE%5D%3A), [GitHub Feedback](https://github.com/SimformSolutionsPvtLtd/react-native-haptic-patterns/issues/new?labels=enhancement\u0026template=FEATURE_REQUEST.md\u0026title=%5BFEEDBACK%5D%3A)\n\n## 🤝 How to Contribute\n\nWe'd love to have you improve this library or fix a problem 💪\nCheck out our [Contributing Guide](CONTRIBUTING.md) for ideas on contributing.\n\n## Awesome Mobile Libraries\n\n- Check out our other [available awesome mobile libraries](https://github.com/SimformSolutionsPvtLtd/Awesome-Mobile-Libraries)\n\n## License\n\n- [MIT License](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimformsolutionspvtltd%2Freact-native-haptic-patterns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimformsolutionspvtltd%2Freact-native-haptic-patterns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimformsolutionspvtltd%2Freact-native-haptic-patterns/lists"}