|
| 1 | +# v2 Reference |
| 2 | + |
| 3 | +This page documents the **v2.x** API for users who have not yet migrated to v3. |
| 4 | +The latest stable release is **v3** — see the [Migration guide](./migration) for upgrade steps. |
| 5 | + |
| 6 | +::: warning End of life |
| 7 | +v2 is no longer maintained. Bug fixes and new features are only added to v3. |
| 8 | +::: |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```bash |
| 15 | +npm install react-native-haptic-feedback@2 |
| 16 | +# or |
| 17 | +yarn add react-native-haptic-feedback@2 |
| 18 | +``` |
| 19 | + |
| 20 | +React Native 0.60+ uses auto-linking — no extra steps needed. For older versions, run `react-native link react-native-haptic-feedback`. |
| 21 | + |
| 22 | +--- |
| 23 | + |
| 24 | +## Usage |
| 25 | + |
| 26 | +```javascript |
| 27 | +import ReactNativeHapticFeedback from "react-native-haptic-feedback"; |
| 28 | + |
| 29 | +const options = { |
| 30 | + enableVibrateFallback: true, |
| 31 | + ignoreAndroidSystemSettings: false, |
| 32 | +}; |
| 33 | + |
| 34 | +ReactNativeHapticFeedback.trigger("impactLight", options); |
| 35 | +``` |
| 36 | + |
| 37 | +Named export: |
| 38 | + |
| 39 | +```javascript |
| 40 | +import { trigger } from "react-native-haptic-feedback"; |
| 41 | + |
| 42 | +trigger("impactLight", options); |
| 43 | +``` |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## API |
| 48 | + |
| 49 | +### `trigger(type, options?)` |
| 50 | + |
| 51 | +The only method available in v2. |
| 52 | + |
| 53 | +| Parameter | Type | Default | Description | |
| 54 | +| ------------------------------------- | --------- | ------- | --------------------------------------------------------------------- | |
| 55 | +| `type` | `string` | — | Haptic feedback type (see table below) | |
| 56 | +| `options.enableVibrateFallback` | `boolean` | `false` | iOS: fall back to system vibration on devices without a Taptic Engine | |
| 57 | +| `options.ignoreAndroidSystemSettings` | `boolean` | `false` | Android: trigger even if vibration is disabled in system settings | |
| 58 | + |
| 59 | +--- |
| 60 | + |
| 61 | +## Feedback types |
| 62 | + |
| 63 | +Many types were platform-specific in v2. All types work on both platforms in v3. |
| 64 | + |
| 65 | +| Type | Android | iOS | |
| 66 | +| :-------------------: | :-----: | :-: | |
| 67 | +| `impactLight` | ✅ | ✅ | |
| 68 | +| `impactMedium` | ✅ | ✅ | |
| 69 | +| `impactHeavy` | ✅ | ✅ | |
| 70 | +| `rigid` | ✅ | ✅ | |
| 71 | +| `soft` | ✅ | ✅ | |
| 72 | +| `notificationSuccess` | ✅ | ✅ | |
| 73 | +| `notificationWarning` | ✅ | ✅ | |
| 74 | +| `notificationError` | ✅ | ✅ | |
| 75 | +| `selection` | ❌ | ✅ | |
| 76 | +| `clockTick` | ✅ | ❌ | |
| 77 | +| `contextClick` | ✅ | ❌ | |
| 78 | +| `keyboardPress` | ✅ | ❌ | |
| 79 | +| `keyboardRelease` | ✅ | ❌ | |
| 80 | +| `keyboardTap` | ✅ | ❌ | |
| 81 | +| `longPress` | ✅ | ❌ | |
| 82 | +| `textHandleMove` | ✅ | ❌ | |
| 83 | +| `virtualKey` | ✅ | ❌ | |
| 84 | +| `virtualKeyRelease` | ✅ | ❌ | |
| 85 | +| `effectClick` | ✅ | ❌ | |
| 86 | +| `effectDoubleClick` | ✅ | ❌ | |
| 87 | +| `effectHeavyClick` | ✅ | ❌ | |
| 88 | +| `effectTick` | ✅ | ❌ | |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## Platform notes |
| 93 | + |
| 94 | +**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`. |
| 95 | + |
| 96 | +**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. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## What's new in v3 |
| 101 | + |
| 102 | +v3 adds full cross-platform type support, Core Haptics on iOS, richer Android Composition API, and several new APIs: |
| 103 | + |
| 104 | +- `triggerPattern()` — custom multi-event sequences |
| 105 | +- `pattern()` — compact notation helper (`"oO.O"`) |
| 106 | +- `playAHAP()` / `playHaptic()` — AHAP file playback |
| 107 | +- `getSystemHapticStatus()` — ringer mode and vibration availability |
| 108 | +- `isSupported()` — runtime Core Haptics check |
| 109 | +- `stop()` — cancel active haptics |
| 110 | +- `useHaptics` hook and `TouchableHaptic` component |
| 111 | +- 15 new haptic types |
| 112 | + |
| 113 | +See the [Migration guide](./migration) for the full list of changes and upgrade steps. |
0 commit comments