Skip to content

Commit

Permalink
Merge pull request #21 from PeterStaev/ios-svg-support
Browse files Browse the repository at this point in the history
iOS svg support
  • Loading branch information
bradmartin authored May 25, 2017
2 parents 0364832 + eab9cca commit e3b37fb
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 13 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class DrawingPadExample {


## Attributes
**penColor - (color string)** - *optional*
**penColor - (Color)** - *optional*

Attribute to specify the pen (stroke) color to use.

Expand All @@ -138,8 +138,9 @@ Attribute to specify the pen (stroke) width to use.

**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)
- **getDrawingSvg()** - Promise (returns a Scalable Vector Graphics document)

2 changes: 2 additions & 0 deletions demo/app/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

Button {
horizontal-align: center;
font-size: 18;
margin-left: 5
}

.red {
Expand Down
5 changes: 4 additions & 1 deletion demo/app/main-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<StackLayout>
<DrawingPad:DrawingPad backgroundColor="#222" id="drawingPad" margin="10" height="280" penColor="{{ penColor }}" penWidth="{{ penWidth }}" />
<StackLayout orientation="horizontal">
<Button text="Get Drawing" tap="{{ getMyDrawing }}" />
<Button text="Get Image" tap="{{ getMyDrawing }}" />
<Button text="Get SVG" tap="{{ getMyDrawingSvg }}" />
</StackLayout>
<StackLayout orientation="horizontal">
<Button text="Clear" tap="{{ clearMyDrawing }}" />
<Button text="Pick Color" tap="{{ openColorPicker }}" />
</StackLayout>
Expand Down
6 changes: 6 additions & 0 deletions demo/app/main-view-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export class HelloWorldModel extends Observable {
console.log(res);
});
}

public getMyDrawingSvg() {
this._myDrawingPad.getDrawingSvg().then((res) => {
console.log(res);
});
}

public clearMyDrawing() {
this._myDrawingPad.clearDrawing();
Expand Down
4 changes: 1 addition & 3 deletions drawingpad-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ export abstract class DrawingPadBase extends View implements DrawingPadDefinitio
public getTransparentDrawing(): Promise<any> {
return new Promise<any>((resolve, reject) => { resolve(); });
}
public getDrawingSvg(): Promise<any> {
return new Promise<any>((resolve, reject) => { resolve(); });
}
public abstract getDrawingSvg(): Promise<string>;

}

Expand Down
9 changes: 6 additions & 3 deletions drawingpad.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ export class DrawingPad extends DrawingPadBase {
})
}

public getDrawingSvg(): Promise<any> {
public getDrawingSvg(): Promise<string> {
return new Promise((resolve, reject) => {
try {
if (!this.nativeView.isEmpty()) {
let data = this.nativeView.getSignatureSvg();
resolve(data);
let data: string = this.nativeView.getSignatureSvg();

// Append viewbox to the svg for correct scaling
const svgHeaderRegEx = /<svg (.*) height="(\d+)" width="(\d+)"(.*)>/i
resolve(data.replace(svgHeaderRegEx, `<svg $1 viewBox="0, 0, $3, $2" height="$2" width="$3"$4>`));
} else {
reject("DrawingPad is empty.");
}
Expand Down
16 changes: 16 additions & 0 deletions drawingpad.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ export class DrawingPad extends DrawingPadBase {
})
}

public getDrawingSvg(): Promise<string> {
return new Promise((resolve, reject) => {
try {
let isSigned = this.nativeView.isSigned();
if (isSigned === true) {
let data = this.nativeView.signatureSvg();
resolve(data);
} else {
reject("DrawingPad is empty.");
}
} catch (err) {
reject(err);
}
})
}

public clearDrawing(): void {
try {
if (this.backgroundColor) {
Expand Down
4 changes: 2 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export class DrawingPad extends View {
getTransparentDrawing(): Promise<any>;

/**
* Returns a Scalable Vector Graphics document *** ANDROID ONLY ***
* Returns a Scalable Vector Graphics document
*/
getDrawingSvg(): Promise<any>;
getDrawingSvg(): Promise<string>;

/**
* Clears the drawing from the DrawingPad.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-drawingpad",
"version": "2.0.1",
"version": "2.1.0",
"main": "drawingpad",
"typings": "index.d.ts",
"description": "A NativeScript plugin to provide a way to capture any drawing (signatures are a common use case) from the device screen.",
Expand Down
2 changes: 1 addition & 1 deletion platforms/ios/Podfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pod 'SignatureView', '~> 1.1'
pod 'SignatureView', :git => 'https://github.com/PeterStaev/SignatureView.git', :branch => 'svg-support'

0 comments on commit e3b37fb

Please sign in to comment.