nativescript-community / nativescript-drawingpad

:pencil: NativeScript plugin to provide a way to capture any drawing (signatures are a common use case) from the device
Apache License 2.0
90 stars 32 forks source link

Example with Angular 2 and {N} #2

Closed leocaseiro closed 8 years ago

leocaseiro commented 8 years ago

Hi, thanks for this plugin. It's really easy to implement.

Here's an example for who is interested in try with Angular:


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
        let pad = this.DrawingPad.nativeElement;

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

    clearMyDrawing(args) {
        var pad = this.DrawingPad.nativeElement;
        pad.clearDrawing();
    }
}
bradmartin commented 8 years ago

Awesome. If you want you can submit a PR with this example to the readme file. I can add it if you'd rather me do it. No worries.

leocaseiro commented 8 years ago

Either way, I'm happy 😄

How about readme and an example angular app inside demo folder as well?

I can do tonight(Australia), but if you have some free time and would like to update...no worries 🍺

bradmartin commented 8 years ago

Go for it. I'll add you to the contributors on npm when done and you add yourself to the package.json in the contributors block. If you aren't familiar check some of the other plugins for that in the package.json :) thanks.

On Tue, Jun 14, 2016, 7:51 PM Leo Caseiro notifications@github.com wrote:

Either way, I'm happy 😄

How about readme and an example angular app inside demo folder as well?

I can do tonight(Australia), but if you have some free time and would like to update...no worries 🍺

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/bradmartin/nativescript-drawingpad/issues/2#issuecomment-226059465, or mute the thread https://github.com/notifications/unsubscribe/AFulhGGjnJAA0JTJYStqGxmg0v7JP-dpks5qL0yYgaJpZM4I15bw .

leocaseiro commented 8 years ago

Thanks...Will do it. Really appreciate it.