suiss/uim · React Native Component

Haptics

A provider that connects components to your haptics library, with a hook to trigger feedback.

Haptics is an open-source mobile component from suiss/uim for React Native and Expo, with SwiftUI and Jetpack Compose versions built from the same design tokens. The @esuiss/uim CLI copies its source into your project, so you own the code.

iOS
Haptics on iOS in light mode

Components such as Amount Input, Chart and Context Menu play haptic feedback through useHaptics(). By default nothing happens: HapticsProvider lets you plug in an adapter that calls the haptics library of your choice, so the components stay free of a native dependency.

The adapter has three methods: impact(style) with light, medium, heavy, soft or rigid; selection(); and notification(type) with success, warning or error.

Installation

$ pnpm dlx @esuiss/uim@latest add haptics

Manual

  1. Add the pieces it builds on: the primitives components/primitives/haptics.tsx.

  2. Copy the source into components/ui/haptics.tsx:

uniwind/components/ui/haptics.tsx
import * as React from "react"
import {
  type HapticsAdapter,
  HapticsContext,
  type HapticsContextValue,
  type HapticsImpactStyle,
  type HapticsNotificationType,
  NOOP_HAPTICS_ADAPTER,
  useHaptics,
} from "@/components/primitives/haptics"

function HapticsProvider({
  adapter,
  enabled = true,
  children,
}: {
  1. Update the import paths to match your project.

Usage

import { HapticsProvider } from "@/components/ui/haptics"
<ControlsDemo />

Wrap your app in HapticsProvider and pass an adapter object that implements impact, selection and notification. Set enabled={false} to turn all feedback off, for example from a user setting.

Call useHaptics() in your own components to get the same methods. Without a provider, or when disabled, they do nothing.

Examples

Feedback

Buttons for each impact, selection and notification type.

iOS
Haptics (feedback) on iOS in light mode

Reorder

Feedback while dragging items in a reorder list.

iOS
Haptics (reorder) on iOS in light mode

Disabled

The same controls with haptics turned off.

iOS
Haptics (disabled) on iOS in light mode

API Reference

HapticsProvider

Supplies the adapter to every component below it.

PropType
About
Object with impact, selection and notification methods.
Type
HapticsAdapternull
Default
—
About
Turns feedback on or off. Defaults to true.
Type
boolean
Default
true
Type
React.ReactNode
Default
—

Notes

  • The types HapticsAdapter, HapticsImpactStyle and HapticsNotificationType are exported for typing your adapter.
  • Haptics have no visual output; pair important feedback with a visible change.