### Installation Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/v2.md Instructions for installing version 2 of the react-native-haptic-feedback library. ```APIDOC ## Installation ```bash npm install react-native-haptic-feedback@2 # or yarn add react-native-haptic-feedback@2 ``` React Native 0.60+ uses auto-linking — no extra steps needed. For older versions, run `react-native link react-native-haptic-feedback`. ``` -------------------------------- ### Install react-native-haptic-feedback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/README.md Install the library using npm or yarn. No extra steps are needed for React Native 0.71+ due to auto-linking. ```bash npm install react-native-haptic-feedback # or yarn add react-native-haptic-feedback ``` -------------------------------- ### Install iOS CocoaPods Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/getting-started.md Run pod install in the ios directory after adding the package. ```sh cd ios && pod install ``` -------------------------------- ### Install and Setup for React Native Haptic Feedback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/README.md Install the latest version of the library using npm and update your iOS dependencies by running pod install. This is a standard procedure for integrating new packages into your React Native project. ```bash npm install react-native-haptic-feedback@latest cd ios && pod install ``` -------------------------------- ### Install react-native-haptic-feedback v2 Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/v2.md Use npm or yarn to install the specific v2 version of the package. ```bash npm install react-native-haptic-feedback@2 # or yarn add react-native-haptic-feedback@2 ``` -------------------------------- ### Install react-native-haptic-feedback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/getting-started.md Use npm or yarn to add the package to your project. ```sh npm install react-native-haptic-feedback ``` ```sh yarn add react-native-haptic-feedback ``` -------------------------------- ### Start Metro Development Server Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/example/README.md Run the Metro JavaScript build tool from the project root to enable live reloading and development features. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### AHAP File Structure Example Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/README.md A minimal example of an AHAP file, which is a JSON document describing haptic events. This format is used for advanced haptic patterns on iOS. ```json { "Version": 1.0, "Pattern": [ { "Event": { "EventType": "HapticTransient", "Time": 0.0, "EventParameters": [ { "ParameterID": "HapticIntensity", "ParameterValue": 0.5 }, { "ParameterID": "HapticSharpness", "ParameterValue": 0.3 } ] } }, { "Event": { "EventType": "HapticTransient", "Time": 0.15, "EventParameters": [ { "ParameterID": "HapticIntensity", "ParameterValue": 1.0 }, { "ParameterID": "HapticSharpness", "ParameterValue": 0.5 } ] } } ] } ``` -------------------------------- ### Install react-native-haptic-feedback with yarn Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/index.md Install the library using yarn. This is an alternative package manager for React Native projects. ```sh yarn add react-native-haptic-feedback ``` -------------------------------- ### Minimal AHAP file example Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/ahap.md A basic AHAP file structure defining two transient haptic events with specified intensity and sharpness at different times. ```json { "Version": 1.0, "Pattern": [ { "Event": { "EventType": "HapticTransient", "Time": 0.0, "EventParameters": [ { "ParameterID": "HapticIntensity", "ParameterValue": 1.0 }, { "ParameterID": "HapticSharpness", "ParameterValue": 0.8 } ] } }, { "Event": { "EventType": "HapticTransient", "Time": 0.1, "EventParameters": [ { "ParameterID": "HapticIntensity", "ParameterValue": 0.5 }, { "ParameterID": "HapticSharpness", "ParameterValue": 0.3 } ] } } ] } ``` -------------------------------- ### Install CocoaPods Dependencies Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/example/README.md Commands for setting up and updating native iOS dependencies via CocoaPods. ```sh bundle install ``` ```sh bundle exec pod install ``` -------------------------------- ### useHaptics with playHaptic Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/use-haptics.md Example of using the playHaptic method with the useHaptics hook, demonstrating how default options are merged with per-call options. ```typescript const haptics = useHaptics({ enableVibrateFallback: true }); await haptics.playHaptic("celebration.ahap", pattern("o.o.o.O")); // defaultOptions are merged: { enableVibrateFallback: true, ...perCallOpts } ``` -------------------------------- ### Toggle Haptics Based on User Preference Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/enabled.md This example demonstrates how to integrate haptic feedback control with user preferences using `AsyncStorage` for persistence. It shows restoring the preference on app startup and updating it in a settings screen. ```typescript import HapticFeedback from 'react-native-haptic-feedback'; import AsyncStorage from '@react-native-async-storage/async-storage'; // On app startup — restore preference const saved = await AsyncStorage.getItem('haptics_enabled'); HapticFeedback.setEnabled(saved !== 'false'); // In settings screen function HapticsToggle() { const [enabled, setEnabled] = useState(HapticFeedback.isEnabled()); const toggle = async () => { const next = !enabled; HapticFeedback.setEnabled(next); setEnabled(next); await AsyncStorage.setItem('haptics_enabled', String(next)); }; return ; } ``` -------------------------------- ### Trigger Method Usage Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/trigger.md Examples of triggering haptic feedback using enums, string literals, and custom options. ```ts import HapticFeedback, { HapticFeedbackTypes, } from "react-native-haptic-feedback"; // Using enum (recommended — autocomplete + type safety) HapticFeedback.trigger(HapticFeedbackTypes.impactMedium); // Using string literal HapticFeedback.trigger("impactMedium"); // With options HapticFeedback.trigger("notificationSuccess", { enableVibrateFallback: true, ignoreAndroidSystemSettings: false, }); ``` -------------------------------- ### Configure Jest automatic mock resolution Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/testing.md Use setup files to register the mock when module directories are configured. ```javascript // jest.config.js module.exports = { preset: "react-native", automock: false, // the mock is explicit, not automatic setupFilesAfterFramework: ["./setupTests.js"], }; ``` ```javascript // setupTests.js jest.mock("react-native-haptic-feedback"); ``` -------------------------------- ### Display Haptic Status in UI Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/system-status.md Example of integrating haptic status into a React component. ```typescript function HapticStatusBadge() { const [status, setStatus] = useState(null); useEffect(() => { getSystemHapticStatus().then(setStatus); }, []); if (!status) return null; return ( {status.vibrationEnabled ? 'Haptics ON' : 'Haptics OFF'} {status.ringerMode ? ` · ${status.ringerMode}` : ''} ); } ``` -------------------------------- ### playHaptic(file, pattern) Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/presets.md Plays a haptic pattern with a cross-platform fallback file. ```APIDOC ## playHaptic(file, pattern) ### Description Plays a haptic pattern with a specified fallback file for cross-platform support. ### Parameters #### Request Body - **file** (string) - Required - The fallback file path (e.g., "success.ahap"). - **pattern** (HapticEvent[]) - Required - The pattern preset to trigger. ### Request Example ```ts import { playHaptic, Patterns } from "react-native-haptic-feedback"; await playHaptic("success.ahap", Patterns.success); ``` ``` -------------------------------- ### Build and Run iOS Application Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/example/README.md Execute the build process for the iOS platform using the configured package manager. ```sh # Using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### Build and Run Android Application Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/example/README.md Execute the build process for the Android platform using the configured package manager. ```sh # Using npm npm run android # OR using Yarn yarn android ``` -------------------------------- ### Get System Haptic Status Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/README.md Retrieves the device's haptic availability and, on Android, the current ringer mode. This is useful for adapting haptic feedback based on system settings. ```typescript RNHapticFeedback.getSystemHapticStatus(): Promise interface SystemHapticStatus { vibrationEnabled: boolean; /** Android: 'silent' | 'vibrate' | 'normal'. iOS: null (not exposed by the OS). */ ringerMode: 'silent' | 'vibrate' | 'normal' | null; } ``` -------------------------------- ### useHaptics with Default Options Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/use-haptics.md Shows how to initialize the useHaptics hook with default options that are merged into every haptic call. Per-call options can override these defaults. ```typescript const haptics = useHaptics({ enableVibrateFallback: true, ignoreAndroidSystemSettings: false, }); // All calls automatically use the default options haptics.trigger("impactMedium"); // Per-call options override defaults haptics.trigger("impactHeavy", { ignoreAndroidSystemSettings: true }); ``` -------------------------------- ### AHAP TypeScript type definition Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/ahap.md Defines an AHAP object using the library's exported TypeScript types. This example includes a minimal AHAP structure with a transient haptic event. ```typescript import type { AhapType, AhapEventPattern, AhapParameterCurvePattern, } from "react-native-haptic-feedback"; const ahap: AhapType = { Version: 1.0, Pattern: [ { Event: { EventType: "HapticTransient", Time: 0, EventParameters: [ { ParameterID: "HapticIntensity", ParameterValue: 1.0 }, ], }, }, ], }; ``` -------------------------------- ### Basic useHaptics Hook Usage Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/use-haptics.md Demonstrates the basic usage of the useHaptics hook to trigger a light impact haptic feedback on press. ```typescript import { useHaptics } from 'react-native-haptic-feedback'; function MyComponent() { const haptics = useHaptics(); return ( haptics.trigger('impactLight')}> Press me ); } ``` -------------------------------- ### Utilities Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md Utility functions for working with haptic feedback patterns and playback. ```APIDOC ## Utilities ### Description Utility functions for working with haptic feedback patterns and playback. ### Exports - **`pattern(notation)`** - **Description**: Convert notation string to `HapticEvent[]`. - **`Patterns`** - **Description**: Six named built-in presets. - **`playHaptic(ahap, fallback, options?)`** - **Description**: Cross-platform AHAP/pattern bridge. - **`isRingerSilent(status)`** - **Description**: Helper for `SystemHapticStatus`. ``` -------------------------------- ### Check Device Support Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/getting-started.md Verify if haptic feedback is supported and check the current system status. ```ts import { isSupported, getSystemHapticStatus, isRingerSilent, } from "react-native-haptic-feedback"; if (isSupported()) { const status = await getSystemHapticStatus(); console.log(status.vibrationEnabled); // true/false console.log(status.ringerMode); // 'normal' | 'vibrate' | 'silent' | null if (isRingerSilent(status)) { // Android: device is in silent mode } } ``` -------------------------------- ### Usage Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/v2.md Demonstrates how to use the react-native-haptic-feedback library in your React Native project. ```APIDOC ## Usage ```javascript import ReactNativeHapticFeedback from "react-native-haptic-feedback"; const options = { enableVibrateFallback: true, ignoreAndroidSystemSettings: false, }; ReactNativeHapticFeedback.trigger("impactLight", options); ``` Named export: ```javascript import { trigger } from "react-native-haptic-feedback"; trigger("impactLight", options); ``` ``` -------------------------------- ### Gate haptic calls by platform Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/web.md Use Platform.OS to handle differences in intensity support between mobile and web environments. ```ts import { Platform } from "react-native"; import { impact } from "react-native-haptic-feedback"; if (Platform.OS !== "web") { impact("impactMedium", 0.3); // precise on iOS / Android } else { impact("impactMedium"); // web: fixed duration, intensity ignored } ``` -------------------------------- ### Import HapticFeedback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/migration.md Shows the default import usage which remains unchanged in v3. ```typescript import HapticFeedback from "react-native-haptic-feedback"; HapticFeedback.trigger("impactMedium"); ``` -------------------------------- ### Convert notation strings to HapticEvent arrays Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/pattern.md Use the pattern helper to generate haptic event sequences from compact notation strings. ```ts import { pattern } from "react-native-haptic-feedback"; pattern("oO"); // two pulses: soft then strong pattern("O.O"); // two strong pulses, 250 ms apart pattern("oO--oO"); // heartbeat: double-pulse, pause, double-pulse pattern("o.o.o"); // rapid triple tap ``` -------------------------------- ### Play Haptic with Android Options Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-haptic.md Configure Android haptic feedback with specific options when using `playHaptic` alongside an AHAP file. Imports are necessary. ```typescript import { playHaptic, pattern, Patterns } from "react-native-haptic-feedback"; // With Android options await playHaptic("alert.ahap", pattern("OO.OO"), { ignoreAndroidSystemSettings: true, }); ``` -------------------------------- ### Trigger Haptic Pattern with pattern() Helper Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/trigger-pattern.md Use the pattern() helper to easily create a sequence of HapticEvents from a notation string. This is the recommended approach for defining haptic patterns. ```typescript import HapticFeedback, { pattern } from "react-native-haptic-feedback"; HapticFeedback.triggerPattern(pattern("oO.O")); ``` -------------------------------- ### Basic Usage Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/touchable-haptic.md Use TouchableHaptic as a drop-in replacement for Pressable. ```tsx import { TouchableHaptic } from "react-native-haptic-feedback"; Tap me ; ``` -------------------------------- ### Import Haptic Types Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/types.md Import all available haptic types and related interfaces directly from the package root. ```typescript import type { HapticOptions, HapticEvent, SystemHapticStatus, PatternChar, PatternName, AhapType, // ... } from "react-native-haptic-feedback"; ``` -------------------------------- ### Cross-Platform Fallback with playHaptic Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/presets.md Use `playHaptic` for cross-platform compatibility, providing a file path and a corresponding pattern like `Patterns.success`. ```typescript import { playHaptic, Patterns } from "react-native-haptic-feedback"; await playHaptic("success.ahap", Patterns.success); ``` -------------------------------- ### Import Patterns and Type Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/presets.md Import the `Patterns` object and `PatternName` type from the library to use predefined haptic sequences. ```typescript import { Patterns } from "react-native-haptic-feedback"; import type { PatternName } from "react-native-haptic-feedback"; ``` -------------------------------- ### File placement structure Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-ahap.md Recommended directory structure for AHAP files within an Xcode project. ```text ios/ └── YourApp/ └── haptics/ ← add as folder reference in Xcode └── celebration.ahap ``` -------------------------------- ### SystemHapticStatus Interface Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/types.md Represents the current system haptic and ringer status. ```APIDOC ## SystemHapticStatus ### Description Result object returned by getSystemHapticStatus(). ### Fields - **vibrationEnabled** (boolean) - True when haptics are supported/enabled. - **ringerMode** (string) - 'silent', 'vibrate', 'normal', or null (iOS). ``` -------------------------------- ### AHAP file with continuous event Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/ahap.md An AHAP file demonstrating a continuous haptic event with a specified duration and parameters for intensity and sharpness. ```json { "Event": { "EventType": "HapticContinuous", "Time": 0.0, "EventDuration": 0.5, "EventParameters": [ { "ParameterID": "HapticIntensity", "ParameterValue": 0.6 }, { "ParameterID": "HapticSharpness", "ParameterValue": 0.2 } ] } } ``` -------------------------------- ### HapticOptions Interface Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/types.md Configuration options for haptic feedback triggers. ```APIDOC ## HapticOptions ### Description Options accepted by trigger(), triggerPattern(), and playHaptic() methods. ### Parameters - **enableVibrateFallback** (boolean) - Optional - Default: false. On Android, plays a basic vibration fallback when haptics are unavailable. - **ignoreAndroidSystemSettings** (boolean) - Optional - Default: false. Android only. When true, haptics play even in silent/vibrate mode. ``` -------------------------------- ### Import new v3 features Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/migration.md Demonstrates how to access new features using named imports. ```typescript import { pattern, Patterns, playHaptic, useHaptics, TouchableHaptic, HapticFeedbackTypes, } from "react-native-haptic-feedback"; ``` -------------------------------- ### Import Default Export Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md Import the HapticFeedback object to access all available methods. This is the primary way to use the library's core functionality. ```typescript import HapticFeedback from "react-native-haptic-feedback"; ``` -------------------------------- ### playHaptic Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/README.md A cross-platform wrapper for AHAP playback. It plays the .ahap file on iOS and falls back to a triggerPattern call on Android, making it the recommended approach for cross-platform applications. ```APIDOC ## `playHaptic(ahapFile, fallback, options?)` ### Description Cross-platform wrapper for AHAP playback. Plays the `.ahap` file on iOS and falls back to a `triggerPattern` call on Android. ### Method Signature ```typescript playHaptic(ahapFile: string, fallback: string, options?: any): Promise ``` ### Parameters #### `ahapFile` (string) - Required The name of the `.ahap` file to play on iOS. #### `fallback` (string) - Required A pattern string to use as a fallback on Android. #### `options` (any) - Optional Additional options for playback. ``` -------------------------------- ### Trigger Predefined Haptic Patterns Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/presets.md Use `HapticFeedback.triggerPattern` with imported presets like `Patterns.success` or `Patterns.error` to play common haptic sequences. ```typescript import HapticFeedback, { Patterns } from "react-native-haptic-feedback"; HapticFeedback.triggerPattern(Patterns.success); HapticFeedback.triggerPattern(Patterns.error); ``` -------------------------------- ### Default Export Methods Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md The default export provides an object with methods to trigger haptic feedback. These methods can be imported and used directly. ```APIDOC ## Default Export Methods ### Description Provides an object with methods to trigger haptic feedback. These methods can be imported and used directly. ### Methods - **trigger(type, options?)** - **Description**: Fire a single haptic. - **Returns**: `void` - **impact(type?, intensity?, options?)** - **Description**: Haptic with custom intensity. - **Returns**: `void` - **triggerPattern(events, options?)** - **Description**: Play a `HapticEvent[]` sequence. - **Returns**: `void` - **stop()** - **Description**: Stop ongoing haptics (iOS). - **Returns**: `void` - **isSupported()** - **Description**: Synchronous capability check. - **Returns**: `boolean` - **playAHAP(fileName)** - **Description**: Play an AHAP file — iOS only. - **Returns**: `Promise` - **getSystemHapticStatus()** - **Description**: Query ringer/vibration state. - **Returns**: `Promise` - **setEnabled(value)** - **Description**: Library-wide kill switch. - **Returns**: `void` - **isEnabled()** - **Description**: Read the kill-switch state. - **Returns**: `boolean` ``` -------------------------------- ### isSupported() Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/control.md Synchronously checks whether the device supports haptic feedback. ```APIDOC ## isSupported() ### Description Synchronously check whether the device supports haptic feedback. ### Method boolean ### Endpoint HapticFeedback.isSupported() ### Returns - iOS: true when device supports Core Haptics (iPhone 8 / iOS 13+) - Android: true when Vibrator.hasVibrator() returns true ### Request Example import HapticFeedback from "react-native-haptic-feedback"; if (HapticFeedback.isSupported()) { HapticFeedback.trigger("impactMedium"); } ``` -------------------------------- ### triggerPattern() Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/trigger-pattern.md Plays a sequence of HapticEvent objects with precise timing. ```APIDOC ## triggerPattern(events, options) ### Description Play a sequence of HapticEvent objects with precise timing. ### Parameters - **events** (HapticEvent[]) - Required - Array of timed haptic events - **options** (HapticOptions) - Optional - Platform options ### HapticEvent Fields - **time** (number) - Required - Offset from pattern start in milliseconds - **type** ('transient' | 'continuous') - Optional - Default 'transient' - **duration** (number) - Optional - Duration in ms (only for continuous type) - **intensity** (number) - Optional - 0.0–1.0 - **sharpness** (number) - Optional - 0.0–1.0 ### Request Example ```ts HapticFeedback.triggerPattern([ { time: 0, type: "transient", intensity: 0.5, sharpness: 0.5 }, { time: 100, type: "transient", intensity: 1.0, sharpness: 0.8 }, { time: 200, type: "continuous", duration: 300, intensity: 0.6, sharpness: 0.2, }, ]); ``` ``` -------------------------------- ### Configure Jest module mapping Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/testing.md Map the library to its mock implementation in the Jest configuration file. ```javascript // jest.config.js module.exports = { preset: "react-native", moduleNameMapper: { "react-native-haptic-feedback": "/node_modules/react-native-haptic-feedback/src/__mocks__/react-native-haptic-feedback", }, }; ``` -------------------------------- ### Pattern Conversion Utility Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md The `pattern` utility converts a notation string into a `HapticEvent[]` sequence. This is useful for creating custom haptic patterns programmatically. ```typescript pattern(notation) ``` -------------------------------- ### function pattern(notation) Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/pattern.md Converts a compact notation string into an array of HapticEvent objects. ```APIDOC ## function pattern(notation) ### Description Converts a compact notation string into a `HapticEvent[]` array. The function supports compile-time validation for string literals and runtime validation for dynamic strings. ### Parameters #### Path Parameters - **notation** (string) - Required - A string of pattern characters (o, O, ., -, =). ### Returns - **HapticEvent[]** (array) - An array of objects containing `time`, `type`, `intensity`, and `sharpness` fields. ### Request Example ```ts const events = pattern("oO.O"); ``` ### Response #### Success Response - **HapticEvent[]** (array) - Array of events with calculated timing and haptic properties. ``` -------------------------------- ### TypeScript Integration Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/touchable-haptic.md Extend TouchableHapticProps to create custom components that support haptic feedback. ```ts import type { TouchableHapticProps } from 'react-native-haptic-feedback'; interface MyButtonProps extends TouchableHapticProps { label: string; } function MyButton({ label, ...props }: MyButtonProps) { return ( {label} ); } ``` -------------------------------- ### Trigger Haptic with Options Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/getting-started.md Pass an options object to configure fallback behavior and system setting overrides. ```ts HapticFeedback.trigger("impactHeavy", { enableVibrateFallback: true, // vibrate on unsupported iOS devices ignoreAndroidSystemSettings: false, // respect Android silent/vibrate mode }); ``` -------------------------------- ### Cross-platform wrapper for AHAP and patterns Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/ahap.md Provides a cross-platform way to play haptic feedback. On iOS, it plays the specified AHAP file. On Android, it plays a fallback pattern using `triggerPattern`. ```typescript import { playHaptic, pattern } from "react-native-haptic-feedback"; // iOS → plays celebration.ahap // Android → plays pattern('o.o.o.O') via triggerPattern await playHaptic("celebration.ahap", pattern("o.o.o.O")); ``` -------------------------------- ### Platform Notes Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/v2.md Details on platform-specific behaviors and issues in v2 for iOS and Android. ```APIDOC ## Platform notes **iOS** — v2 used UIKit feedback generators (`UIImpactFeedbackGenerator`, `UINotificationFeedbackGenerator`, `UISelectionFeedbackGenerator`). This caused a [25-second rate-limiting issue](https://github.com/mkuczera/react-native-haptic-feedback/issues/98) and occasional [NSInternalInconsistencyException crashes](https://github.com/mkuczera/react-native-haptic-feedback/issues/65). Both are fixed in v3 via `CHHapticEngine`. **Android** — v2 used `VibrationEffect.createWaveform` (API 26+) or a raw waveform fallback. On API 23–25 (Android 6–7) a plain `Vibrator.vibrate()` call was used. The [Android 8 crash](https://github.com/mkuczera/react-native-haptic-feedback/issues/88) is fixed in v3. ``` -------------------------------- ### Cross-Platform AHAP/Pattern Playback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md The `playHaptic` utility acts as a bridge for playing AHAP files or patterns across different platforms. It accepts an AHAP object, a fallback pattern, and optional configuration. ```typescript playHaptic(ahap, fallback, options?) ``` -------------------------------- ### React Hooks and Components Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md Provides hooks and components for integrating haptic feedback within React components. ```APIDOC ## React Hooks & Components ### Description Provides hooks and components for integrating haptic feedback within React components. ### Exports - **`useHaptics(defaultOptions?)`** - **Description**: Hook with merged default options and stable references. - **`TouchableHaptic`** - **Description**: Pressable wrapper with built-in haptic. ``` -------------------------------- ### Shared useHaptics Hook Instance Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/use-haptics.md Illustrates creating a single instance of the useHaptics hook at the top of a component to share across multiple event handlers for consistent haptic feedback. ```typescript function CheckoutScreen() { const haptics = useHaptics({ enableVibrateFallback: true }); const onAddItem = () => haptics.trigger("impactLight"); const onCheckout = () => haptics.triggerPattern(Patterns.success); const onError = () => haptics.triggerPattern(Patterns.error); // ... } ``` -------------------------------- ### Play Haptic with useHaptics Hook Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-haptic.md Integrate `playHaptic` within the `useHaptics` hook for managing haptic feedback, allowing merged options. Ensure necessary imports. ```typescript const haptics = useHaptics({ enableVibrateFallback: true }); // options are merged: defaultOptions + per-call opts await haptics.playHaptic("celebration.ahap", pattern("o.o.o.O")); ``` -------------------------------- ### Playing AHAP Files and Patterns Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/index.md Play AHAP files on iOS or use pattern notation for cross-platform haptic feedback. The `playHaptic` function handles platform-specific playback. ```typescript import { pattern, playHaptic } from "react-native-haptic-feedback"; // Cross-platform: AHAP on iOS, pattern fallback on Android await playHaptic("celebration.ahap", pattern("o.o.o.O")); ``` -------------------------------- ### Play cross-platform haptic patterns Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/ios.md Executes an AHAP file on iOS and a fallback pattern on Android. ```ts import { playHaptic, pattern } from "react-native-haptic-feedback"; await playHaptic("celebration.ahap", pattern("o.o.o.O")); ``` -------------------------------- ### Import TouchableHaptic Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/touchable-haptic.md Import the component and its props type definition for use in your project. ```ts import { TouchableHaptic } from "react-native-haptic-feedback"; import type { TouchableHapticProps } from "react-native-haptic-feedback"; ``` -------------------------------- ### Cross-platform haptic usage Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-ahap.md Implementation for handling both iOS AHAP files and Android haptic patterns using playHaptic. ```ts import { playHaptic, pattern } from "react-native-haptic-feedback"; await playHaptic("celebration.ahap", pattern("o.o.o.O")); // ↑ iOS plays AHAP ↑ Android plays this pattern ``` -------------------------------- ### Using Haptic Options Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/touchable-haptic.md Pass additional options to the haptic trigger function. ```tsx Click ``` -------------------------------- ### playHaptic() Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-haptic.md Triggers haptic feedback using an AHAP file for iOS and a fallback pattern for Android. ```APIDOC ## playHaptic() ### Description Cross-platform haptic file playback. The recommended way to use AHAP files in a project that targets both iOS and Android. ### Parameters - **ahapFile** (string) - Required - AHAP file name to play on iOS - **fallback** (HapticEvent[]) - Required - Pattern to play on Android - **options** (HapticOptions) - Optional - Applied to the Android fallback path ### Request Example ```ts import { playHaptic, pattern, Patterns } from "react-native-haptic-feedback"; await playHaptic("celebration.ahap", pattern("o.o.o.O")); ``` ### Response - **Promise** - Resolves when the haptic feedback is triggered or immediately if haptics are disabled via setEnabled(). ``` -------------------------------- ### getSystemHapticStatus() Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/system-status.md Queries the device's current vibration and ringer state. ```APIDOC ## getSystemHapticStatus() ### Description Queries the device's current vibration and ringer state. Returns a promise that resolves to a SystemHapticStatus object. ### Response #### Success Response (200) - **vibrationEnabled** (boolean) - true if the device has a vibrator and is not in silent mode. - **ringerMode** (string|null) - Android: 'silent', 'vibrate', or 'normal'. iOS: always null. ### Request Example ```ts import HapticFeedback from "react-native-haptic-feedback"; const status = await HapticFeedback.getSystemHapticStatus(); ``` ``` -------------------------------- ### Types Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md Defines the types used throughout the library for haptic feedback. ```APIDOC ## Types ### Description Defines the types used throughout the library for haptic feedback. ### Available Types - **`HapticFeedbackTypes`** - **Description**: Enum of all 34 haptic type strings. - **`HapticOptions`** - **Description**: `enableVibrateFallback`, `ignoreAndroidSystemSettings`. - **`HapticEvent`** - **Description**: Single event in a pattern sequence. - **`SystemHapticStatus`** - **Description**: Result of `getSystemHapticStatus()`. - **`AhapType`** - **Description**: Full AHAP document — iOS only. - **`PatternChar`** - **Description**: `'o' | 'O' | '.' | '-' | '='`. ``` -------------------------------- ### Triggering Haptic Feedback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/index.md Use the `trigger` method to play standard haptic feedback types. This is the most common way to provide haptic feedback. ```typescript import HapticFeedback, { HapticFeedbackTypes, } from "react-native-haptic-feedback"; // Single impact HapticFeedback.trigger("impactMedium"); // Notification HapticFeedback.trigger(HapticFeedbackTypes.notificationSuccess); ``` -------------------------------- ### Play Haptic with Named Preset Fallback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-haptic.md Utilize `playHaptic` with a predefined named preset for Android fallback when playing an AHAP file on iOS. Imports are required. ```typescript import { playHaptic, pattern, Patterns } from "react-native-haptic-feedback"; // Using a named preset as the fallback await playHaptic("success.ahap", Patterns.success); ``` -------------------------------- ### Feedback Types Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/v2.md Lists the available haptic feedback types supported in v2, indicating platform compatibility. ```APIDOC ## Feedback types Many types were platform-specific in v2. All types work on both platforms in v3. | Type | Android | iOS | | :-------------------: | :-----: | :-: | | `impactLight` | ✅ | ✅ | | `impactMedium` | ✅ | ✅ | | `impactHeavy` | ✅ | ✅ | | `rigid` | ✅ | ✅ | | `soft` | ✅ | ✅ | | `notificationSuccess` | ✅ | ✅ | | `notificationWarning` | ✅ | ✅ | | `notificationError` | ✅ | ✅ | | `selection` | ❌ | ✅ | | `clockTick` | ✅ | ❌ | | `contextClick` | ✅ | ❌ | | `keyboardPress` | ✅ | ❌ | | `keyboardRelease` | ✅ | ❌ | | `keyboardTap` | ✅ | ❌ | | `longPress` | ✅ | ❌ | | `textHandleMove` | ✅ | ❌ | | `virtualKey` | ✅ | ❌ | | `virtualKeyRelease` | ✅ | ❌ | | `effectClick` | ✅ | ❌ | | `effectDoubleClick` | ✅ | ❌ | | `effectHeavyClick` | ✅ | ❌ | | `effectTick` | ✅ | ❌ | ``` -------------------------------- ### Named Export Methods Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md All methods available from the default export are also exposed as named exports for convenience. ```APIDOC ## Named Export Methods ### Description All methods from the default export are also available as named exports. ### Available Named Exports - `trigger` - `impact` - `stop` - `isSupported` - `triggerPattern` - `playAHAP` - `getSystemHapticStatus` - `setEnabled` - `isEnabled` - `playHaptic` - `pattern` - `Patterns` - `useHaptics` - `TouchableHaptic` - `HapticFeedbackTypes` - `isRingerSilent` ``` -------------------------------- ### Trigger Haptic Pattern with Manual Events Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/trigger-pattern.md Define custom haptic sequences by manually creating an array of HapticEvent objects. Each event can specify its time, type, duration, intensity, and sharpness. ```typescript HapticFeedback.triggerPattern([ { time: 0, type: "transient", intensity: 0.5, sharpness: 0.5 }, { time: 100, type: "transient", intensity: 1.0, sharpness: 0.8 }, { time: 200, type: "continuous", duration: 300, intensity: 0.6, sharpness: 0.2, }, ]); ``` -------------------------------- ### Trigger Haptic Pattern with Named Preset Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/trigger-pattern.md Utilize predefined haptic patterns like 'success' from the Patterns object for quick integration. Ensure the Patterns object is imported. ```typescript import HapticFeedback, { Patterns } from "react-native-haptic-feedback"; HapticFeedback.triggerPattern(Patterns.success); ``` -------------------------------- ### Built-in Haptic Patterns Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/index.md The `Patterns` export provides access to six named built-in haptic presets. These can be used directly or as a reference for custom patterns. ```typescript Patterns ``` -------------------------------- ### Using useHaptics Hook Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/enabled.md Demonstrates disabling haptic feedback through the `useHaptics` hook. Calls made via the hook's methods will respect this global setting. ```typescript import { useHaptics } from "react-native-haptic-feedback"; const haptics = useHaptics(); // All calls through haptics.trigger(), haptics.triggerPattern(), etc. // automatically respect the global enabled state. haptics.setEnabled(false); haptics.trigger("impactMedium"); // no-op ``` -------------------------------- ### Check Haptic Feedback Support Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/control.md Use isSupported() to synchronously determine if the device can provide haptic feedback. This is useful for conditionally triggering haptics. ```typescript import HapticFeedback from "react-native-haptic-feedback"; if (HapticFeedback.isSupported()) { HapticFeedback.trigger("impactMedium"); } ``` -------------------------------- ### Trigger Built-in Haptic Presets Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/README.md Utilize the `Patterns` object to easily trigger predefined haptic feedback presets like success, error, warning, heartbeat, triple click, and notification. ```typescript import { Patterns } from "react-native-haptic-feedback"; RNHapticFeedback.triggerPattern(Patterns.success); RNHapticFeedback.triggerPattern(Patterns.error); RNHapticFeedback.triggerPattern(Patterns.warning); RNHapticFeedback.triggerPattern(Patterns.heartbeat); RNHapticFeedback.triggerPattern(Patterns.tripleClick); RNHapticFeedback.triggerPattern(Patterns.notification); ``` -------------------------------- ### AHAP file with parameter curve Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/ahap.md An AHAP file showcasing a parameter curve for HapticIntensityControl, creating a fade-out effect over 0.5 seconds. ```json { "ParameterCurve": { "ParameterID": "HapticIntensityControl", "Time": 0.0, "ParameterCurveControlPoints": [ { "Time": 0.0, "ParameterValue": 1.0 }, { "Time": 0.5, "ParameterValue": 0.0 } ] } } ``` -------------------------------- ### API: trigger Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/v2.md Documentation for the `trigger` method, the primary function for invoking haptic feedback in v2. ```APIDOC ## API ### `trigger(type, options?)` The only method available in v2. | Parameter | Type | Default | Description | | ------------------------------------- | --------- | ------- | --------------------------------------------------------------------- | | `type` | `string` | — | Haptic feedback type (see table below) | | `options.enableVibrateFallback` | `boolean` | `false` | iOS: fall back to system vibration on devices without a Taptic Engine | | `options.ignoreAndroidSystemSettings` | `boolean` | `false` | Android: trigger even if vibration is disabled in system settings | ``` -------------------------------- ### triggerPattern(pattern) Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/presets.md Triggers a specific haptic pattern preset using the HapticFeedback module. ```APIDOC ## triggerPattern(pattern) ### Description Triggers a pre-built haptic feedback pattern. ### Parameters #### Request Body - **pattern** (HapticEvent[]) - Required - The pattern preset to trigger (e.g., Patterns.success, Patterns.error). ### Request Example ```ts import HapticFeedback, { Patterns } from "react-native-haptic-feedback"; HapticFeedback.triggerPattern(Patterns.success); ``` ``` -------------------------------- ### Dynamic Preset Lookup Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/presets.md Dynamically trigger a haptic pattern by looking it up in the `Patterns` object using a variable `name` of type `PatternName`. ```typescript import { Patterns } from "react-native-haptic-feedback"; import type { PatternName } from "react-native-haptic-feedback"; function playPreset(name: PatternName) { HapticFeedback.triggerPattern(Patterns[name]); } playPreset("heartbeat"); ``` -------------------------------- ### Play Haptic with Pattern Fallback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-haptic.md Use `playHaptic` to play an AHAP file on iOS and a custom pattern on Android. Ensure `react-native-haptic-feedback` is imported. ```typescript import { playHaptic, pattern, Patterns } from "react-native-haptic-feedback"; // Using pattern notation for the fallback await playHaptic("celebration.ahap", pattern("o.o.o.O")); ``` -------------------------------- ### Check for Vibration API support Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/web.md Use the isSupported function to verify if the browser supports the Vibration API before triggering haptics. ```ts import { isSupported } from "react-native-haptic-feedback"; if (isSupported()) { // navigator.vibrate is available } ``` -------------------------------- ### playAHAP() - iOS Haptic Feedback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/play-ahap.md This method plays an Apple Haptic and Audio Pattern (AHAP) file by name. It is an iOS-only feature. On Android, it resolves immediately without any action. For cross-platform compatibility, consider using playHaptic(). ```APIDOC ## POST /playAHAP ### Description Plays an Apple Haptic and Audio Pattern (AHAP) file by name. This method is specific to iOS. ### Method POST ### Endpoint /playAHAP ### Parameters #### Query Parameters - **fileName** (string) - Required - The name of the AHAP file (e.g., 'celebration.ahap') or a path relative to the bundle. ### Request Body This endpoint does not require a request body. Parameters are passed via query. ### Response #### Success Response (200) - **void** (void) - The promise resolves immediately upon completion or if the method is called on an unsupported platform (Android). #### Response Example (No response body for success, promise resolves) ### Error Handling Native errors are caught internally. The `playAHAP()` method always resolves and never rejects. ``` -------------------------------- ### Configure Expo Plugin Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/getting-started.md Add the library to the plugins array in your app.config.js for Expo managed workflows. ```js export default { plugins: ["react-native-haptic-feedback"], }; ``` -------------------------------- ### Play AHAP file Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/ahap.md Plays an AHAP file from the app bundle. The library searches for the file in `/haptics/` and then `/`. This is an iOS-only feature. ```typescript import HapticFeedback from "react-native-haptic-feedback"; // plays ios/YourApp/haptics/celebration.ahap await HapticFeedback.playAHAP("celebration.ahap"); ``` -------------------------------- ### HapticOptions Interface Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/types.md Defines options for triggering haptic feedback. `enableVibrateFallback` provides a vibration fallback on Android when haptics are unavailable. `ignoreAndroidSystemSettings` allows haptics to play even in silent/vibrate mode on Android. ```typescript interface HapticOptions { enableVibrateFallback?: boolean; ignoreAndroidSystemSettings?: boolean; } ``` -------------------------------- ### Trigger Haptic Patterns with useHaptics Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/presets.md When using the `useHaptics` hook, call `triggerPattern` on the returned haptics object with predefined patterns like `Patterns.heartbeat`. ```typescript const haptics = useHaptics(); haptics.triggerPattern(Patterns.heartbeat); ``` -------------------------------- ### TouchableHaptic Component Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/touchable-haptic.md A drop-in replacement for Pressable that fires haptic feedback automatically based on user interaction. ```APIDOC ## TouchableHaptic Component ### Description A drop-in `Pressable` replacement that fires haptic feedback automatically. All standard `Pressable` props are forwarded. ### Props - **hapticType** (HapticFeedbackTypes) - Optional - Which haptic to fire. Default: 'impactMedium'. - **hapticTrigger** ('onPressIn' | 'onPress' | 'onLongPress') - Optional - When to fire the haptic. Default: 'onPressIn'. - **hapticOptions** (HapticOptions) - Optional - Options forwarded to the trigger() function. ### Usage Example ```tsx Submit ``` ``` -------------------------------- ### Test useHaptics hook Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/testing.md Verify the behavior of the useHaptics hook using renderHook. ```typescript import { useHaptics } from "react-native-haptic-feedback"; jest.mock("react-native-haptic-feedback"); test("hook trigger is called", () => { const { result } = renderHook(() => useHaptics()); act(() => result.current.trigger("impactLight")); expect(result.current.trigger).toHaveBeenCalledWith("impactLight"); }); ``` -------------------------------- ### trigger() Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/api/trigger.md Triggers a haptic feedback event based on the specified type and optional platform settings. ```APIDOC ## trigger() ### Description Fire a single haptic event on the device. ### Parameters #### Arguments - **type** (HapticFeedbackTypes | string) - Required - The haptic type to play (e.g., 'impactMedium', 'notificationSuccess'). - **options** (HapticOptions) - Optional - Platform-specific configuration. ### HapticOptions - **enableVibrateFallback** (boolean) - Optional - No-op on iOS. On Android, plays a fallback vibration when haptics are not available. Default: false. - **ignoreAndroidSystemSettings** (boolean) - Optional - Android only. When true, plays haptics even in silent/vibrate mode. Default: false. ### Request Example ```javascript HapticFeedback.trigger("notificationSuccess", { enableVibrateFallback: true, ignoreAndroidSystemSettings: false }); ``` ### Response - **void** - This method does not return a value and catches native errors internally. ``` -------------------------------- ### Check Haptic Support Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/README.md Synchronously check if haptic feedback is supported on the current device. Returns true on Android if a vibrator is present. ```typescript RNHapticFeedback.isSupported(): boolean ``` -------------------------------- ### Trigger haptic feedback Source: https://github.com/mkuczera/react-native-haptic-feedback/blob/main/docs/guide/v2.md Use the default export or the named trigger function to initiate haptic feedback with specific options. ```javascript import ReactNativeHapticFeedback from "react-native-haptic-feedback"; const options = { enableVibrateFallback: true, ignoreAndroidSystemSettings: false, }; ReactNativeHapticFeedback.trigger("impactLight", options); ``` ```javascript import { trigger } from "react-native-haptic-feedback"; trigger("impactLight", options); ```