useHaptics
A React Native hook for touch feedback with tap, success, warning and error patterns that you can switch off.
Touch feedback built on React Native's Vibration, so it needs no extra package. Pass enabled false, for example from a settings switch, and every call does nothing. Android follows the patterns exactly; iOS only offers a single fixed buzz for any pattern, so for finer iOS feedback swap the bodies for expo-haptics. Works in React and in React Native with no extra packages.
Installation
CLI
npx @modus-ui/cli add use-hapticsManual
- Copy the code from the code tab, using the React or React Native switch for your project.
- Create a file at
components/ui/use-haptics.ts. - Paste the code.
The CLI installs the React Native version in an Expo or React Native app and the React version everywhere else. In a project that targets both, keep the React file use-haptics.ts and the React Native file use-haptics.native.ts side by side and import ./use-haptics; Metro picks the .native file on its own.
Usage
API
| Part | Type | Default | Description |
|---|---|---|---|
enabled | boolean | true | Pass false to turn every call into a no-op. |
| Returns | Haptics | - | An object with tap, success, warning and error. |
Comments