Signature pad
A pad you sign with a finger: ink that thins with speed, undo and clear, strokes as data, one SVG path and an image through your own capture adapter.
npx @swipeui/cli add signature-padWhen to use it
- Collecting a signature for a delivery, a consent form, a contract or a receipt.
- Any short freehand mark you want back as data or as one SVG path.
When not to use it
- Typing a name as agreement: use Text field with a checkbox.
- A full drawing canvas with colours, layers or an eraser.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add signature-pad- Adds
components/swipeui/special/signature-pad.tsx,components/swipeui/special/use-signature-pad.ts,components/swipeui/special/signature-ink.tsand 6 shared helpers. - Installs react-native-gesture-handler, react-native-reanimated, react-native-svg, react-native-worklets, uniwind, clsx, tailwind-merge, class-variance-authority, expo-haptics. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { useRef } from 'react';
import { SignaturePad } from '@/components/swipeui/special/signature-pad';
import type { SignaturePadHandle } from '@/components/swipeui/special/signature-pad';
const pad = useRef<SignaturePadHandle>(null);
<SignaturePad ref={pad} onChange={setStrokes} />;
<Button onPress={() => pad.current?.clear()}>Clear</Button>;A stroke is { points: { x, y, t }[] }: positions in the pad's own points, and milliseconds since the pen landed. Keep the strokes, or call toSvgPath() for one path you can store and draw anywhere.
Examples
- Sign: a pad in a card, with Undo and Clear buttons outside it that call the ref.
- Thin ink: a wider range (
minWidth={1},maxWidth={6}), andthinningswitched on and off. - Read-only:
readOnlywith stored strokes indefaultValue.
Signature pad settings
| Prop | Does | Default |
|---|---|---|
| value, defaultValue | The strokes | [] |
| onChange | A stroke ended, or the pad was cleared or undone | — |
| onBegin, onEnd | The pen landed; the pen lifted, with its stroke | — |
| minWidth, maxWidth | The ink's width at speed and at rest, in points | 1.5, 4.5 |
| thinning | Thin the ink as the pen speeds up | true |
| guide | The baseline and the "Sign here" hint | true |
| height | The pad's height in points | 180 |
| inkColor | The ink's colour | Foreground token |
| surface | The filled surface behind the ink | true |
| readOnly | Show the signature and take no ink | false |
| disabled | Dim the pad and take no ink | false |
| captureAdapter | Makes the image for capture() | — |
| haptics | A switch, or { start, clear } | true |
| messages | Built-in strings | English |
| motion | Local motion feel | App feel |
Ref
| Method | Does |
|---|---|
| clear() | Removes every stroke |
| undo() | Removes the last stroke |
| isEmpty() | True when there is no ink |
| toSvgPath() | The whole signature as one SVG path to fill |
| capture(options) | An image through captureAdapter; rejects without one |
Composition and behavior
The ink is a filled outline, not a stroked line: its width follows the pen's speed between maxWidth at rest and minWidth at speed, eased so it never jumps. A tap leaves a dot. The hint fades when the first ink lands and returns when the pad is cleared.
toSvgPath() returns path data in the pad's own points. Draw it with <Path d={path} fill="black" /> inside a viewBox the size of the pad, and it scales to any size. The same function is exported on its own: toSvgPath(strokes, { minWidth, maxWidth, thinning }).
The pad adds no image dependency. To get an image, pass a captureAdapter:
import { captureRef } from 'react-native-view-shot';
<SignaturePad ref={pad} captureAdapter={(target, options) => captureRef(target, options)} />;
const uri = await pad.current?.capture({ format: 'png' });Screen readers get one image named Signature that says "Not signed" or "Signed", with Clear signature and Undo last stroke as actions once there is ink. Offer a typed alternative for people who can't draw. Wrap the app in GestureHandlerRootView, and put the pad on a screen that doesn't scroll under it.
Behavior and gestures
- Draw with a finger. The ink thins as the pen speeds up and thickens as it slows.
- A tap leaves a dot. The hint fades when the first ink lands and returns when the pad is cleared.
- Clear and undo come from a ref, so the buttons can sit anywhere outside the pad.
Accessibility
- The pad is one image named Signature, with the value Not signed or Signed.
- Once there is ink, Clear signature and Undo last stroke are accessibility actions; each is announced once.
- The baseline and the hint are hidden from screen readers. Offer a typed alternative for people who cannot draw.
Motion
- Uses the
overlaymotion role, so it follows your app's feel. Passmotionto tune this one instance. - The ink follows the finger directly, with no animation.
- The hint fades on the overlay role; under Reduce Motion it swaps.
Performance
- The pen's points are gathered and drawn on the UI thread; React hears about every 24th point and the finished stroke.
- Finished strokes are static paths that never re-render while drawing.
Notes for AI
- Wrap the screen in GestureHandlerRootView. Put the pad on a screen that does not scroll under it, or turn scrolling off while signing.
- A stroke is { points: { x, y, t }[] } with t in milliseconds since the pen landed. toSvgPath(strokes) returns a path to fill, not stroke.
- capture() needs captureAdapter, for example (target, options) => captureRef(target, options) with react-native-view-shot.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.