Haptics
The platform’s own feedback, named for what happened: UIKit’s feedback generators on iOS, the system’s haptic feedback constants on Android — never a raw vibration. Both follow the user’s system setting, and every call is synchronous.
Usage
import {haptics, useHapticFeedback} from '@hzblj/kara-ui'
haptics.success() // a name you know: one function per haptic
haptics.play(haptic) // a name that arrives as data
haptics.light({intensity: 0.6}) // impacts scale on iOS
haptics.prepare('selection') // iOS: warm the Taptic Engine as a gesture begins
haptics.setEnabled(userPreference) // silences every kara haptic, the components' own too
// Plays on every change of a value, never on mount.
useHapticFeedback(selectedIndex, 'selection')
useHapticFeedback(count, (previous, next) => (next > previous ? 'tick' : false))Haptics are felt, not seen — the simulator and the emulator play nothing. Check them on a device.
Haptics
| Name | For |
|---|---|
selection | A choice changed: a segment, a chip, a picker row. |
tick | One step of a continuous gesture: a slider detent, a scrubbed value. |
toggleOn, toggleOff | A switch flipped. |
success, warning, error | How a task ended. Android has no warning of its own and plays a rejection. |
longPress, dragStart | A long press was recognised; an item lifted to be dragged. |
thresholdActivate, thresholdDeactivate | A gesture crossed its commit point, or went back over it. |
keyPress | A key of the app’s own keypad. |
soft, light, medium, rigid, heavy | A collision none of the names above describes. intensity scales them on iOS. |
On Android the names that came with Android 14 fall back to the nearest older feedback, so every name plays on every version.
In the components
A component plays a haptic only where the platform’s own control would and kara’s does not. Compose’s Material controls play none, so on Android Switch plays toggleOn and toggleOff, a stepped Slider ticks at every stop, SegmentedControl plays selection and ContextMenu its long press. iOS’s controls keep their own feedback. Chip plays selection, and Pressable plays whatever its haptic names.