SwipeUI

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-pad
Variant
Preset
Material
Scheme
Feel
Real free component with a browser animation bridge. Native motion, haptics and materials need a device.

When 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.ts and 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 install so 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}), and thinning switched on and off.
  • Read-only: readOnly with stored strokes in defaultValue.

Signature pad settings

PropDoesDefault
value, defaultValueThe strokes[]
onChangeA stroke ended, or the pad was cleared or undone—
onBegin, onEndThe pen landed; the pen lifted, with its stroke—
minWidth, maxWidthThe ink's width at speed and at rest, in points1.5, 4.5
thinningThin the ink as the pen speeds uptrue
guideThe baseline and the "Sign here" hinttrue
heightThe pad's height in points180
inkColorThe ink's colourForeground token
surfaceThe filled surface behind the inktrue
readOnlyShow the signature and take no inkfalse
disabledDim the pad and take no inkfalse
captureAdapterMakes the image for capture()—
hapticsA switch, or { start, clear }true
messagesBuilt-in stringsEnglish
motionLocal motion feelApp feel

Ref

MethodDoes
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 overlay motion role, so it follows your app's feel. Pass motion to 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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

Related items