# React Native Signature Pad

> A signature pad for React Native on iOS, Android and the web with no WebView, SVG or native code: sign with a finger, pen or mouse, then export the strokes as an SVG or a path to save or upload. Replaces react-native-signature-canvas.

# SignaturePad

A pad to sign with a finger, a pen or the mouse. It's drawn with plain views, so it needs no WebView, canvas or SVG library. Its `value` is the strokes as points; turn them into an SVG with `signatureToSvg` to save or upload, or into a path with `signatureToPath`.

```tsx
import { SignaturePad, signatureToSvg } from 'patine-ui';
```

```tsx live
import { useState } from 'react';
import { Button, SignaturePad, Text, VStack, signatureToSvg } from 'patine-ui';

export default function Example() {
  const [strokes, setStrokes] = useState([]);
  const [saved, setSaved] = useState('');
  return (
    <VStack gap="md" style={{ width: 340 }}>
      <SignaturePad value={strokes} onValueChange={setStrokes} />
      <Button disabled={!strokes.length} onPress={() => setSaved(signatureToSvg(strokes, { width: 340, height: 200 }))}>
        Save
      </Button>
      {saved ? <Text size="xs" color="textSecondary">{`SVG, ${saved.length} characters`}</Text> : null}
    </VStack>
  );
}
```

## Example: sign for a delivery

A courier app's handover screen: the recipient's name and signature are both needed before Confirm, and Clear starts the signature again.

```tsx live
import { useState } from 'react';
import { Box, Button, SignaturePad, Text, TextField, VStack, signatureToSvg } from 'patine-ui';

export default function Example() {
  const [name, setName] = useState('');
  const [strokes, setStrokes] = useState([]);
  const [done, setDone] = useState<string | null>(null);
  if (done)
    return (
      <Box border radius="lg" padding="lg" gap="xs" style={{ width: '100%', maxWidth: 380 }}>
        <Text weight="semibold">Delivered to {name}</Text>
        <Text size="sm" color="textSecondary">Parcel 3 of 3 · signature saved ({done.length} bytes of SVG)</Text>
      </Box>
    );
  return (
    <Box border radius="lg" padding="lg" gap="md" style={{ width: '100%', maxWidth: 380 }}>
      <VStack gap="xs">
        <Text weight="semibold">Parcel 3 of 3 · 2.4 kg</Text>
        <Text size="sm" color="textSecondary">Keizersgracht 120, 2nd floor</Text>
      </VStack>
      <TextField label="Received by" placeholder="Full name" value={name} onChangeText={setName} />
      <SignaturePad value={strokes} onValueChange={setStrokes} height={160} />
      <Button disabled={!name.trim() || !strokes.length} onPress={() => setDone(signatureToSvg(strokes, { width: 340, height: 160 }))}>
        Confirm delivery
      </Button>
    </Box>
  );
}
```

## Saving the signature

- `signatureToSvg(strokes, { width, height, color, strokeWidth, backgroundColor })` returns a standalone SVG document: upload it, store it, or show it in an `<img>` with a `data:image/svg+xml` URL.
- `signatureToPath(strokes)` returns the path's `d`, to draw with `react-native-svg`'s `<Path>` or in a browser `<svg>`.
- `isSignatureEmpty(strokes)` tells you whether anything was drawn.

Points are in the pad's own coordinates, from its top left, so use the pad's size as the SVG's `width` and `height`.

## In a scroll view or sheet

The pad claims the touch as soon as the pen lands, so a `ScrollView` or `BottomSheet` around it doesn't scroll while you sign. On iOS, pass `onBegin` and `onEnd` to turn the ScrollView's `scrollEnabled` off and on if the native scroll still moves.

## Accessibility

The pad is named "Signature" and reads "Signed" or "Empty". Screen readers get a Clear action, and the Clear button is a 44pt target. Drawing needs a pointer; if a signature is required, offer another way to confirm, such as typing the name.

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value` | `SignatureStroke[]` | — | The strokes; `[]` clears it. |
| `defaultValue` | `SignatureStroke[]` | `[]` | When uncontrolled. |
| `onValueChange` | `(strokes) => void` | — | A stroke is finished, or the pad is cleared. |
| `onBegin` / `onEnd` | `() => void` | — | The pen lands and lifts. |
| `strokeColor` | `string` | the theme's text colour | |
| `strokeWidth` | `number` | `3` | |
| `height` | `number` | `200` | |
| `showClear` | `boolean` | `true` | A Clear button once something's drawn. |
| `disabled` | `boolean` | `false` | |
| `labels` | `Partial<SignatureLabels>` | English | `placeholder`, `clear`, `label`, `signed`, `empty`. |
| `style` | `StyleProp<ViewStyle>` | — | |
| `theme` / `design` | | provider's | A gray card on iOS, an outlined field in Material, a dashed border on the web and brand. |
