react-signature-canvas vs react-native-signature-canvas
Signature Capture Libraries Comparison
1 Year
react-signature-canvasreact-native-signature-canvasSimilar Packages:
What's Signature Capture Libraries?

Signature capture libraries are essential tools for applications that require users to provide handwritten signatures digitally. These libraries facilitate the creation of signature pads, allowing users to draw their signatures using touch or mouse input. They are particularly useful in scenarios such as forms, contracts, and agreements where digital signatures are needed. By leveraging these libraries, developers can enhance user experience and streamline processes that require signature verification.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-signature-canvas326,81555942 kB817 days agoApache-2.0
react-native-signature-canvas35,83343387.8 kB113a year agoMIT
Feature Comparison: react-signature-canvas vs react-native-signature-canvas

Platform Compatibility

  • react-signature-canvas:

    This package is tailored for web applications built with React. It works across various web browsers, ensuring that users can easily capture signatures on desktops, tablets, and mobile browsers.

  • react-native-signature-canvas:

    This package is specifically designed for React Native applications, making it ideal for mobile platforms such as iOS and Android. It leverages native components to ensure optimal performance and user experience on mobile devices.

User Experience

  • react-signature-canvas:

    Provides a smooth drawing experience using mouse or touch input on web browsers. It includes features such as undo/redo functionality and the ability to clear the canvas, making it user-friendly for web applications.

  • react-native-signature-canvas:

    Offers a touch-friendly interface that allows users to draw their signatures naturally on mobile devices. The library provides features like adjustable stroke width and color, enhancing the signature capture experience.

Customization Options

  • react-signature-canvas:

    Offers customization options for the signature pad, including canvas size, background color, and stroke properties. This flexibility allows developers to create a signature capture experience that aligns with their web application's design.

  • react-native-signature-canvas:

    Allows for extensive customization of the signature canvas, including background color, stroke color, and width. Developers can easily adjust these settings to match the branding of their mobile application.

Integration

  • react-signature-canvas:

    Easily integrates into existing React web applications, making it straightforward to add signature functionality to forms and other components without significant overhead.

  • react-native-signature-canvas:

    Integrates seamlessly with React Native, allowing developers to incorporate signature capture into their mobile applications without extensive setup. It works well with other React Native components and libraries.

Performance

  • react-signature-canvas:

    Designed for efficient rendering in web applications, ensuring that signature capture remains responsive even with complex UI components. It handles browser-specific performance optimizations to provide a fluid user experience.

  • react-native-signature-canvas:

    Optimized for mobile performance, ensuring that signature capture is smooth and responsive even on lower-end devices. The library minimizes lag and provides a native feel to the signature drawing experience.

How to Choose: react-signature-canvas vs react-native-signature-canvas
  • react-signature-canvas:

    Choose react-signature-canvas if you are building a web application and require a signature capture solution that works well in a browser environment. This package is designed for web use, offering flexibility and ease of integration with existing React applications.

  • react-native-signature-canvas:

    Choose react-native-signature-canvas if you are developing a mobile application using React Native and need a signature capture solution that integrates seamlessly with mobile touch interfaces. This package is optimized for mobile devices, providing a smooth and responsive experience for users signing on touch screens.

README for react-signature-canvas

react-signature-canvas

package-json releases commits
dt dy dm dw
typings build status code coverage

A React wrapper component around signature_pad.

Originally, this was just an unopinionated fork of react-signature-pad that did not impose any styling or wrap any other unwanted elements around your canvas -- it's just a wrapper around a single canvas element! Hence the naming difference. Nowadays, this repo / library has significantly evolved, introducing new features, fixing various bugs, and now wrapping the upstream signature_pad to have its updates and bugfixes baked in.

This fork also allows you to directly pass props to the underlying canvas element, has new, documented API methods you can use, has new, documented props you can pass to it, has a live demo, has a CodeSandbox playground, has 100% test coverage, and is written in TypeScript.

Installation

npm i -S react-signature-canvas

Usage

import React from 'react'
import { createRoot } from 'react-dom/client'
import SignatureCanvas from 'react-signature-canvas'

createRoot(
  document.getElementById('my-react-container')
).render(
  <SignatureCanvas penColor='green'
    canvasProps={{width: 500, height: 200, className: 'sigCanvas'}} />,
)

Props

The props of SignatureCanvas mainly control the properties of the pen stroke used in drawing. All props are optional.

  • velocityFilterWeight : number, default: 0.7
  • minWidth : number, default: 0.5
  • maxWidth : number, default: 2.5
  • minDistance: number, default: 5
  • dotSize : number or function, default: () => (this.minWidth + this.maxWidth) / 2
  • penColor : string, default: 'black'
  • throttle: number, default: 16

There are also two callbacks that will be called when a stroke ends and one begins, respectively.

  • onEnd : function
  • onBegin : function

Additional props are used to control the canvas element.

  • canvasProps: object
    • directly passed to the underlying <canvas /> element
  • backgroundColor : string, default: 'rgba(0,0,0,0)'
    • used in the API's clear convenience method (which itself is called internally during resizes)
  • clearOnResize: bool, default: true
    • whether or not the canvas should be cleared when the window resizes

Of these props, all, except for canvasProps and clearOnResize, are passed through to signature_pad as its options. signature_pad's internal state is automatically kept in sync with prop updates for you (via a componentDidUpdate hook).

API

All API methods require a ref to the SignatureCanvas in order to use and are instance methods of the ref.

import React, { useRef } from 'react'
import SignatureCanvas from 'react-signature-canvas'

function MyApp() {
  const sigCanvas = useRef(null);

  return <SignatureCanvas ref={sigCanvas} />
}
  • isEmpty() : boolean, self-explanatory
  • clear() : void, clears the canvas using the backgroundColor prop
  • fromDataURL(base64String, options) : void, writes a base64 image to canvas
  • toDataURL(mimetype, encoderOptions): base64string, returns the signature image as a data URL
  • fromData(pointGroupArray): void, draws signature image from an array of point groups
  • toData(): pointGroupArray, returns signature image as an array of point groups
  • off(): void, unbinds all event handlers
  • on(): void, rebinds all event handlers
  • getCanvas(): canvas, returns the underlying canvas ref. Allows you to modify the canvas however you want or call methods such as toDataURL()
  • getTrimmedCanvas(): canvas, creates a copy of the canvas and returns a trimmed version of it, with all whitespace removed.
  • getSignaturePad(): SignaturePad, returns the underlying SignaturePad reference.

The API methods are mostly just wrappers around signature_pad's API. on() and off() will, in addition, bind/unbind the window resize event handler. getCanvas(), getTrimmedCanvas(), and getSignaturePad() are new.

Example

You can interact with the example in a few different ways:

  1. Run npm start and navigate to http://localhost:1234/.
    Hosted locally via the example/ directory

  2. View the live demo here.
    Hosted via the gh-pages branch, a standalone version of the code in example/

  3. Play with the CodeSandbox here.
    Hosted via the codesandbox-example branch, a slightly modified version of the above.