Skip to content

Commit e3b37fb

Browse files
authored
Merge pull request #21 from PeterStaev/ios-svg-support
iOS svg support
2 parents 0364832 + eab9cca commit e3b37fb

10 files changed

+42
-13
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export class DrawingPadExample {
124124

125125

126126
## Attributes
127-
**penColor - (color string)** - *optional*
127+
**penColor - (Color)** - *optional*
128128

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

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

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

141+
**getDrawingSvg()** - Promise (returns a Scalable Vector Graphics document)
142+
141143
#### *Android Only*
142144

143145
- **getTransparentDrawing()** - Promise (returns a bitmap with a transparent background)
144-
- **getDrawingSvg()** - Promise (returns a Scalable Vector Graphics document)
145146

demo/app/app.css

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
Button {
88
horizontal-align: center;
9+
font-size: 18;
10+
margin-left: 5
911
}
1012

1113
.red {

demo/app/main-page.xml

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
<StackLayout>
77
<DrawingPad:DrawingPad backgroundColor="#222" id="drawingPad" margin="10" height="280" penColor="{{ penColor }}" penWidth="{{ penWidth }}" />
88
<StackLayout orientation="horizontal">
9-
<Button text="Get Drawing" tap="{{ getMyDrawing }}" />
9+
<Button text="Get Image" tap="{{ getMyDrawing }}" />
10+
<Button text="Get SVG" tap="{{ getMyDrawingSvg }}" />
11+
</StackLayout>
12+
<StackLayout orientation="horizontal">
1013
<Button text="Clear" tap="{{ clearMyDrawing }}" />
1114
<Button text="Pick Color" tap="{{ openColorPicker }}" />
1215
</StackLayout>

demo/app/main-view-model.ts

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export class HelloWorldModel extends Observable {
2727
console.log(res);
2828
});
2929
}
30+
31+
public getMyDrawingSvg() {
32+
this._myDrawingPad.getDrawingSvg().then((res) => {
33+
console.log(res);
34+
});
35+
}
3036

3137
public clearMyDrawing() {
3238
this._myDrawingPad.clearDrawing();

drawingpad-common.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ export abstract class DrawingPadBase extends View implements DrawingPadDefinitio
1414
public getTransparentDrawing(): Promise<any> {
1515
return new Promise<any>((resolve, reject) => { resolve(); });
1616
}
17-
public getDrawingSvg(): Promise<any> {
18-
return new Promise<any>((resolve, reject) => { resolve(); });
19-
}
17+
public abstract getDrawingSvg(): Promise<string>;
2018

2119
}
2220

drawingpad.android.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,15 @@ export class DrawingPad extends DrawingPadBase {
7171
})
7272
}
7373

74-
public getDrawingSvg(): Promise<any> {
74+
public getDrawingSvg(): Promise<string> {
7575
return new Promise((resolve, reject) => {
7676
try {
7777
if (!this.nativeView.isEmpty()) {
78-
let data = this.nativeView.getSignatureSvg();
79-
resolve(data);
78+
let data: string = this.nativeView.getSignatureSvg();
79+
80+
// Append viewbox to the svg for correct scaling
81+
const svgHeaderRegEx = /<svg (.*) height="(\d+)" width="(\d+)"(.*)>/i
82+
resolve(data.replace(svgHeaderRegEx, `<svg $1 viewBox="0, 0, $3, $2" height="$2" width="$3"$4>`));
8083
} else {
8184
reject("DrawingPad is empty.");
8285
}

drawingpad.ios.ts

+16
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ export class DrawingPad extends DrawingPadBase {
5959
})
6060
}
6161

62+
public getDrawingSvg(): Promise<string> {
63+
return new Promise((resolve, reject) => {
64+
try {
65+
let isSigned = this.nativeView.isSigned();
66+
if (isSigned === true) {
67+
let data = this.nativeView.signatureSvg();
68+
resolve(data);
69+
} else {
70+
reject("DrawingPad is empty.");
71+
}
72+
} catch (err) {
73+
reject(err);
74+
}
75+
})
76+
}
77+
6278
public clearDrawing(): void {
6379
try {
6480
if (this.backgroundColor) {

index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ export class DrawingPad extends View {
2424
getTransparentDrawing(): Promise<any>;
2525

2626
/**
27-
* Returns a Scalable Vector Graphics document *** ANDROID ONLY ***
27+
* Returns a Scalable Vector Graphics document
2828
*/
29-
getDrawingSvg(): Promise<any>;
29+
getDrawingSvg(): Promise<string>;
3030

3131
/**
3232
* Clears the drawing from the DrawingPad.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nativescript-drawingpad",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"main": "drawingpad",
55
"typings": "index.d.ts",
66
"description": "A NativeScript plugin to provide a way to capture any drawing (signatures are a common use case) from the device screen.",

platforms/ios/Podfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pod 'SignatureView', '~> 1.1'
1+
pod 'SignatureView', :git => 'https://github.com/PeterStaev/SignatureView.git', :branch => 'svg-support'

0 commit comments

Comments
 (0)