# nativescript-drawingpad

> A NativeScript plugin to provide a way to capture any drawing (signatures are a common use case) from the device screen.

Latest version **3.1.0** (published 2019-06-17) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install nativescript-drawingpad
pnpm add nativescript-drawingpad
yarn add nativescript-drawingpad
bun add nativescript-drawingpad
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.0 |
| Published | 2019-06-17 |
| First published | 2016-05-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 30 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 92 |
| Author | Brad Martin |
| Maintainers | bradmartin |
| Keywords | NativeScript, native, script, signature, drawing, drawing pad, bradmartin, nStudio |

## Links

- npm: https://www.npmjs.com/package/nativescript-drawingpad
- Repository: https://github.com/bradmartin/nativescript-drawingpad
- Issues: https://github.com/bradmartin/nativescript-drawingpad/issues
- npm.io page: https://npm.io/package/nativescript-drawingpad

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 3.1.0 (latest) — 2019-06-17
- 3.0.4 — 2018-12-12
- 3.0.3 — 2018-05-14
- 3.0.2 — 2018-05-07
- 3.0.0 — 2018-04-16
- 2.1.1 — 2017-11-28
- 2.1.0 — 2017-05-25
- 2.0.1 — 2017-05-23
- 2.0.0 — 2017-05-22
- 1.1.2 — 2016-12-05
- 1.1.1 — 2016-08-06
- 1.1.0 — 2016-08-02
- 1.0.4 — 2016-07-13
- 1.0.3 — 2016-06-20
- 1.0.2 — 2016-05-23
- … 2 more at https://npm.io/package/nativescript-drawingpad/versions

## README

<a align="center" href="https://www.npmjs.com/package/nativescript-drawingpad">
    <h3 align="center">NativeScript DrawingPad</h3>
</a>
<h5 align="center">
NativeScript plugin to provide a way to capture any drawing (signatures are a common use case) from the device. You can use this component to capture really anything you want that can be drawn on the screen.</h4>

<p align="center">
    <a href="https://www.npmjs.com/package/nativescript-drawingpad">
        <img src="https://img.shields.io/npm/v/nativescript-drawingpad.svg" alt="npm">
    </a>
    <a href="https://www.npmjs.com/package/nativescript-drawingpad">
        <img src="https://img.shields.io/npm/dt/nativescript-drawingpad.svg?label=npm%20downloads" alt="npm">
    </a>
     <a href="https://travis-ci.org/bradmartin/nativescript-drawingpad">
        <img src="https://travis-ci.org/bradmartin/nativescript-drawingpad.svg?branch=master" alt="build status">
    </a>
    <a href="https://github.com/bradmartin/nativescript-drawingpad/stargazers">
        <img src="https://img.shields.io/github/stars/bradmartin/nativescript-drawingpad.svg" alt="stars">
    </a>
    <a href="https://paypal.me/bradwayne88">
        <img src="https://img.shields.io/badge/Donate-PayPal-green.svg" alt="donate">
    </a>
    <a href="https://nstudio.io">
      <img src="https://github.com/nstudio/media/blob/master/images/nstudio-banner.png" alt="nStudio banner">
    </a>
    <h5 align="center">Do you need assistance on your project or plugin? Contact the nStudio team anytime at <a href="mailto:team@nstudio.io">team@nstudio.io</a> to get up to speed with the best practices in mobile and web app development.
    </h5>
</p>

---

## Installation

From your command prompt/termial go to your app's root folder and execute:

#### NativeScript

`tns plugin add nativescript-drawingpad`

## Samples

| Android                               | iOS                               |
| ------------------------------------- | --------------------------------- |
| ![Sample1](images/androidDrawing.gif) | ![Sample2](images/iosDrawing.gif) |

#### Native Libraries:

| Android                                                                         | iOS                                                       |
| ------------------------------------------------------------------------------- | --------------------------------------------------------- |
| [gcacace/android-signaturepad](https://github.com/gcacace/android-signaturepad) | [SignatureView](https://cocoapods.org/pods/SignatureView) |

## Video Tutorial

[Egghead lesson - https://egghead.io/lessons/javascript-capture-drawings-and-signatures-in-a-nativescript-app](https://egghead.io/lessons/javascript-capture-drawings-and-signatures-in-a-nativescript-app)

## Written Tutorial

[Blog post using Angular - http://tylerablake.com/nativescript/2019/05/02/capturing-signatures.html](http://tylerablake.com/nativescript/2019/05/02/capturing-signatures.html)

## Usage

#### XML:

```XML
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:DrawingPad="nativescript-drawingpad" loaded="pageLoaded">
    <ActionBar title="NativeScript-DrawingPad" />
    <ScrollView>
        <StackLayout>

            <DrawingPad:DrawingPad
            height="400"
            id="drawingPad"
            penColor="{{ penColor }}" penWidth="{{ penWidth }}" />

        </StackLayout>
    </ScrollView>
</Page>
```

### TS:

```TS
import { topmost } from 'ui/frame';
import { DrawingPad } from 'nativescript-drawingpad';

// To get the drawing...

  public getMyDrawing() {
      const drawingPad = topmost().getViewById('myDrawingPad');
      drawingPad.getDrawing().then((res) => {
          console.log(res);
       });
    }


// If you want to clear the signature/drawing...
public clearMyDrawing() {
    const drawingPad = topmost().getViewById('myDrawingPad');
    drawingPad.clearDrawing();
}
```

## Angular:

```javascript
import { Component, ElementRef, ViewChild } from '@angular/core';
import { registerElement } from 'nativescript-angular/element-registry';

registerElement(
  'DrawingPad',
  () => require('nativescript-drawingpad').DrawingPad
);

@Component({
  selector: 'drawing-pad-example',
  template: `
    <ScrollView>
        <StackLayout>
            <DrawingPad #DrawingPad 
            height="400" 
            id="drawingPad" 
            penColor="#ff4081" penWidth="3">
            </DrawingPad>

            <StackLayout orientation="horizontal">
                <Button text="Get Drawing" (tap)="getMyDrawing()"></Button>
                <Button text="Clear Drawing" (tap)="clearMyDrawing()"></Button>
            </StackLayout>
        </StackLayout>
    </ScrollView>
    `
})
export class DrawingPadExample {
  @ViewChild('DrawingPad') DrawingPad: ElementRef;

  getMyDrawing(args) {
    // get reference to the drawing pad
    const pad = this.DrawingPad.nativeElement;

    // then get the drawing (Bitmap on Android) of the drawingpad
    let drawingImage;
    pad.getDrawing().then(
      data => {
        console.log(data);
        drawingImage = data;
      },
      err => {
        console.log(err);
      }
    );
  }

  clearMyDrawing(args) {
    const pad = this.DrawingPad.nativeElement;
    pad.clearDrawing();
  }
}
```

## Properties

**penColor - (Color)** - _optional_
Property to specify the pen (stroke) color to use.

**penWidth - (int)** - _optional_
Property to specify the pen (stroke) width to use.

**clearOnLongPress - (boolean = true)** - _optional_ **_iOS Only_**
Gets/sets whether a long press will clear the view.

## Methods

**getDrawing()** - Promise _(returns image if successful)_

**clearDrawing()** - clears the drawing from the DrawingPad view.

**getDrawingSvg()** - Promise (returns a Scalable Vector Graphics document)

#### _Android Only_

- **getTransparentDrawing()** - Promise (returns a bitmap with a transparent background)

---
_Source: https://npm.io/package/nativescript-drawingpad · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
