react-native-signature-canvas 4.2.0 → 4.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -14
- package/h5/js/app.js +7 -5
- package/h5/js/signature_pad.js +48 -79
- package/index.d.ts +7 -5
- package/index.js +13 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -55,10 +55,10 @@ import SignatureScreen from 'react-native-signature-canvas';
|
|
|
55
55
|
| backgroundColor | `string` | default is "rgba(255,255,255,0)" (_transparent_), background color of the canvas |
|
|
56
56
|
| bgHeight | `number` | height of the background image |
|
|
57
57
|
| bgWidth | `number` | width of the background image |
|
|
58
|
-
| bgSrc | `string` | background image source uri (
|
|
58
|
+
| bgSrc | `string` | background image source uri (_url_) |
|
|
59
59
|
| clearText | `string` | clear button text |
|
|
60
60
|
| confirmText | `string` | save button text |
|
|
61
|
-
| customHtml | `
|
|
61
|
+
| customHtml | `(injectedJavaScript: string) => string` | html string that lets you modify things like the layout or elements |
|
|
62
62
|
| dataURL | `string` | default is "", Base64 string, draws saved signature from dataURL. |
|
|
63
63
|
| descriptionText | `string` | description text for signature |
|
|
64
64
|
| dotSize | `number` | radius of a single dot _(not stroke width)_ |
|
|
@@ -68,6 +68,7 @@ import SignatureScreen from 'react-native-signature-canvas';
|
|
|
68
68
|
| onOK | `function` | callback function after saving non-empty signature |
|
|
69
69
|
| onEmpty | `function` | callback function after trying to save an empty signature |
|
|
70
70
|
| onClear | `function` | callback function after clearing the signature |
|
|
71
|
+
|onGetData|`function`|callback function when getData() is called
|
|
71
72
|
| onBegin | `function` | callback function when a new stroke is started |
|
|
72
73
|
| onEnd | `function` | callback function when the stroke has ended |
|
|
73
74
|
| onUndo | `function` | callback function when undo() is called |
|
|
@@ -75,9 +76,10 @@ import SignatureScreen from 'react-native-signature-canvas';
|
|
|
75
76
|
| onDraw | `function` | callback function when drawing is enabled |
|
|
76
77
|
| onErase | `function` | callback function when erasing is enabled |
|
|
77
78
|
| onChangePenColor | `function` | callback function after changing the pen color |
|
|
79
|
+
| onChangePenSize | `function` | callback function after changing the pen size
|
|
78
80
|
|overlayHeight|`number`|height of the overlay image|
|
|
79
81
|
|overlayWidth|`number`|width of the overlay image|
|
|
80
|
-
|overlaySrc|`string`|overlay image source uri (
|
|
82
|
+
|overlaySrc|`string`|overlay image source uri (url) _must be .png with a transparent background_
|
|
81
83
|
| penColor | `string` | default is "black", color of pen |
|
|
82
84
|
| rotated | `boolean` | rotate signature pad 90 degrees |
|
|
83
85
|
| style | `object` | style of wrapper view |
|
|
@@ -88,15 +90,17 @@ import SignatureScreen from 'react-native-signature-canvas';
|
|
|
88
90
|
|
|
89
91
|
---
|
|
90
92
|
|
|
91
|
-
| Function
|
|
92
|
-
| :--------------------
|
|
93
|
-
| clearSignature()
|
|
94
|
-
| changePenColor(color)
|
|
95
|
-
|
|
|
96
|
-
|
|
|
97
|
-
|
|
|
98
|
-
|
|
|
99
|
-
|
|
|
93
|
+
| Function | Description |
|
|
94
|
+
| :-------------------- | :-----------------------------------------------------------------------------------------------|
|
|
95
|
+
| clearSignature() | Clear the current signature |
|
|
96
|
+
| changePenColor(color) | Change pen color |
|
|
97
|
+
| changePenSize(minW, maxW) | Change pen size |
|
|
98
|
+
| draw() | Enable drawing signature |
|
|
99
|
+
| erase() | Enable erasing signature |
|
|
100
|
+
| getData() | Triggers the `onGetData` callback with a single `data` JSON string |
|
|
101
|
+
| readSignature() | Reads the current signature on the canvas and triggers either the `onOK` or `onEmpty` callbacks |
|
|
102
|
+
| undo() | Undo last stroke |
|
|
103
|
+
| redo() | Redo last stroke |
|
|
100
104
|
|
|
101
105
|
To call the methods use the `useRef` hook:
|
|
102
106
|
|
|
@@ -127,6 +131,11 @@ const Sign = ({ text, onOK }) => {
|
|
|
127
131
|
ref.current.readSignature();
|
|
128
132
|
};
|
|
129
133
|
|
|
134
|
+
// Called after ref.current.getData()
|
|
135
|
+
const handleData = (data) => {
|
|
136
|
+
console.log(data);
|
|
137
|
+
};
|
|
138
|
+
|
|
130
139
|
return (
|
|
131
140
|
<SignatureScreen
|
|
132
141
|
ref={ref}
|
|
@@ -134,6 +143,7 @@ const Sign = ({ text, onOK }) => {
|
|
|
134
143
|
onOK={handleOK}
|
|
135
144
|
onEmpty={handleEmpty}
|
|
136
145
|
onClear={handleClear}
|
|
146
|
+
onGetData={handleData}
|
|
137
147
|
autoClear={true}
|
|
138
148
|
descriptionText={text}
|
|
139
149
|
/>
|
|
@@ -167,7 +177,7 @@ const style = `.m-signature-pad {box-shadow: none; border: none; }
|
|
|
167
177
|
```
|
|
168
178
|
|
|
169
179
|
## Using an overlay image
|
|
170
|
-
An overlay is a non-erasable image that can be used
|
|
180
|
+
An overlay is a non-erasable image that can be used as a guideline similar to a colouring book. Make sure the image format is .png and that it has a transparent background. Also, don't forget to provide the width and height of the image.
|
|
171
181
|
Use the `overlaySrc` prop to provide the link.
|
|
172
182
|
|
|
173
183
|
```js
|
|
@@ -193,7 +203,7 @@ const style = `.m-signature-pad {box-shadow: none; border: none; }
|
|
|
193
203
|
|
|
194
204
|
## Save Base64 Image as File
|
|
195
205
|
|
|
196
|
-
If you
|
|
206
|
+
If you're using expo, you can use **expo-file-system** to save the base64 image as a local file; if you're working with react-native-cli, use **react-native-fs**.
|
|
197
207
|
|
|
198
208
|
```js
|
|
199
209
|
import * as FileSystem from "expo-file-system";
|
package/h5/js/app.js
CHANGED
|
@@ -50,10 +50,16 @@ export default `
|
|
|
50
50
|
window.ReactNativeWebView.postMessage("REDO");
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
function changePenColor(color){
|
|
53
|
+
function changePenColor(color) {
|
|
54
54
|
signaturePad.penColor = color;
|
|
55
55
|
window.ReactNativeWebView.postMessage("CHANGE_PEN");
|
|
56
56
|
}
|
|
57
|
+
|
|
58
|
+
function changePenSize(minW, maxW) {
|
|
59
|
+
signaturePad.minWidth = minW;
|
|
60
|
+
signaturePad.maxWidth = maxW;
|
|
61
|
+
window.ReactNativeWebView.postMessage("CHANGE_PEN_SIZE");
|
|
62
|
+
}
|
|
57
63
|
|
|
58
64
|
function getData () {
|
|
59
65
|
var data = signaturePad.toData();
|
|
@@ -61,15 +67,11 @@ export default `
|
|
|
61
67
|
}
|
|
62
68
|
|
|
63
69
|
function draw() {
|
|
64
|
-
//signaturePad.minWidth= 0.5;
|
|
65
|
-
//signaturePad.maxWidth= 2.5;
|
|
66
70
|
signaturePad.draw();
|
|
67
71
|
window.ReactNativeWebView.postMessage("DRAW");
|
|
68
72
|
}
|
|
69
73
|
|
|
70
74
|
function erase() {
|
|
71
|
-
//signaturePad.minWidth= 5;
|
|
72
|
-
//signaturePad.maxWidth= 10;
|
|
73
75
|
signaturePad.erase();
|
|
74
76
|
window.ReactNativeWebView.postMessage("ERASE");
|
|
75
77
|
}
|
package/h5/js/signature_pad.js
CHANGED
|
@@ -193,7 +193,7 @@ export default `
|
|
|
193
193
|
this.throttle
|
|
194
194
|
))
|
|
195
195
|
: SignaturePad.prototype._strokeUpdate;
|
|
196
|
-
this.dotSize = options.dotSize || (this.minWidth + this.maxWidth) / 2;
|
|
196
|
+
this.dotSize = options.dotSize || function dotSize() {return (this.minWidth + this.maxWidth) / 2;};
|
|
197
197
|
this.penColor = options.penColor || "black";
|
|
198
198
|
this.backgroundColor = options.backgroundColor || "rgba(255,255,255,0)";
|
|
199
199
|
this.onBegin = options.onBegin;
|
|
@@ -270,14 +270,8 @@ export default `
|
|
|
270
270
|
this._isEmpty = false;
|
|
271
271
|
if (!this._startingSignature) this._startingSignature = dataUrl;
|
|
272
272
|
};
|
|
273
|
-
SignaturePad.prototype.toDataURL = function (type, encoderOptions) {
|
|
274
|
-
|
|
275
|
-
switch (type) {
|
|
276
|
-
case 'image/svg+xml':
|
|
277
|
-
return this._toSVG();
|
|
278
|
-
default:
|
|
279
|
-
return this.canvas.toDataURL(type, encoderOptions);
|
|
280
|
-
}
|
|
273
|
+
SignaturePad.prototype.toDataURL = function (type = "image/png", encoderOptions) {
|
|
274
|
+
return type === "image/svg+xml" ? this._toSVG() : this.canvas.toDataURL(type, encoderOptions);
|
|
281
275
|
};
|
|
282
276
|
SignaturePad.prototype.on = function () {
|
|
283
277
|
this.canvas.style.touchAction = 'none';
|
|
@@ -315,7 +309,7 @@ export default `
|
|
|
315
309
|
this._fromData(
|
|
316
310
|
pointGroups,
|
|
317
311
|
({ color, curve }) => _this._drawCurve({ color, curve }),
|
|
318
|
-
({ color, point }) => _this._drawDot({ color, point })
|
|
312
|
+
({ color, point, dotSize }) => _this._drawDot({ color, point, dotSize })
|
|
319
313
|
);
|
|
320
314
|
this._data = pointGroups;
|
|
321
315
|
}
|
|
@@ -326,10 +320,10 @@ export default `
|
|
|
326
320
|
SignaturePad.prototype._strokeBegin = function (event) {
|
|
327
321
|
var newPointGroup = {
|
|
328
322
|
color: this.penColor,
|
|
329
|
-
dotSize: this.dotSize
|
|
330
|
-
minWidth: this.minWidth,
|
|
331
|
-
maxWidth: this.maxWidth,
|
|
332
|
-
compositeOperation: this._ctx.globalCompositeOperation,
|
|
323
|
+
dotSize: typeof this.dotSize === 'function' ? this.dotSize() : this.dotSize,
|
|
324
|
+
minWidth: this.minWidth,
|
|
325
|
+
maxWidth: this.maxWidth,
|
|
326
|
+
compositeOperation: this._ctx.globalCompositeOperation,
|
|
333
327
|
points: [],
|
|
334
328
|
};
|
|
335
329
|
if (typeof this.onBegin === "function") {
|
|
@@ -392,7 +386,7 @@ export default `
|
|
|
392
386
|
SignaturePad.prototype._reset = function () {
|
|
393
387
|
this._lastPoints = [];
|
|
394
388
|
this._lastVelocity = 0;
|
|
395
|
-
this._lastWidth =
|
|
389
|
+
this._lastWidth = typeof this.dotSize === 'function' ? this.dotSize() : this.dotSize;
|
|
396
390
|
this._ctx.fillStyle = this.penColor;
|
|
397
391
|
};
|
|
398
392
|
SignaturePad.prototype._createPoint = function (x, y) {
|
|
@@ -403,24 +397,24 @@ export default `
|
|
|
403
397
|
return new Point(x - rect.left, y - rect.top, new Date().getTime());
|
|
404
398
|
}
|
|
405
399
|
};
|
|
406
|
-
SignaturePad.prototype._addPoint = function (point) {
|
|
400
|
+
SignaturePad.prototype._addPoint = function (point, minWidth = this.minWidth, maxWidth = this.maxWidth) {
|
|
407
401
|
var _lastPoints = this._lastPoints;
|
|
408
402
|
_lastPoints.push(point);
|
|
409
403
|
if (_lastPoints.length > 2) {
|
|
410
404
|
if (_lastPoints.length === 3) {
|
|
411
405
|
_lastPoints.unshift(_lastPoints[0]);
|
|
412
406
|
}
|
|
413
|
-
var widths = this._calculateCurveWidths(_lastPoints[1], _lastPoints[2]);
|
|
407
|
+
var widths = this._calculateCurveWidths(_lastPoints[1], _lastPoints[2], minWidth, maxWidth);
|
|
414
408
|
var curve = Bezier.fromPoints(_lastPoints, widths);
|
|
415
409
|
_lastPoints.shift();
|
|
416
410
|
return curve;
|
|
417
411
|
}
|
|
418
412
|
return null;
|
|
419
413
|
};
|
|
420
|
-
SignaturePad.prototype._calculateCurveWidths = function (startPoint, endPoint) {
|
|
414
|
+
SignaturePad.prototype._calculateCurveWidths = function (startPoint, endPoint, minWidth = this.minWidth, maxWidth = this.maxWidth) {
|
|
421
415
|
var velocity = this.velocityFilterWeight * endPoint.velocityFrom(startPoint) +
|
|
422
416
|
(1 - this.velocityFilterWeight) * this._lastVelocity;
|
|
423
|
-
var newWidth = this._strokeWidth(velocity);
|
|
417
|
+
var newWidth = this._strokeWidth(velocity, minWidth, maxWidth);
|
|
424
418
|
var widths = {
|
|
425
419
|
end: newWidth,
|
|
426
420
|
start: this._lastWidth
|
|
@@ -429,8 +423,8 @@ export default `
|
|
|
429
423
|
this._lastWidth = newWidth;
|
|
430
424
|
return widths;
|
|
431
425
|
};
|
|
432
|
-
SignaturePad.prototype._strokeWidth = function (velocity) {
|
|
433
|
-
return Math.max(
|
|
426
|
+
SignaturePad.prototype._strokeWidth = function (velocity, minWidth = this.minWidth, maxWidth = this.maxWidth) {
|
|
427
|
+
return Math.max(maxWidth / (velocity + 1), minWidth);
|
|
434
428
|
};
|
|
435
429
|
SignaturePad.prototype._drawCurveSegment = function (x, y, width) {
|
|
436
430
|
var ctx = this._ctx;
|
|
@@ -467,15 +461,9 @@ export default `
|
|
|
467
461
|
ctx.fill();
|
|
468
462
|
};
|
|
469
463
|
SignaturePad.prototype._drawDot = function (_a) {
|
|
470
|
-
var color = _a.color,
|
|
471
|
-
point = _a.point;
|
|
464
|
+
var color = _a.color, point = _a.point;
|
|
472
465
|
var ctx = this._ctx;
|
|
473
|
-
|
|
474
|
-
var width = typeof _a.dotSize
|
|
475
|
-
? _a.dotSize
|
|
476
|
-
: typeof this.dotSize === "function"
|
|
477
|
-
? this.dotSize()
|
|
478
|
-
: this.dotSize; // Enhance undo
|
|
466
|
+
var width = _a.dotSize ? _a.dotSize : typeof this.dotSize === "function" ? this.dotSize() : this.dotSize;
|
|
479
467
|
ctx.beginPath();
|
|
480
468
|
this._drawCurveSegment(point.x, point.y, width);
|
|
481
469
|
ctx.closePath();
|
|
@@ -485,29 +473,20 @@ export default `
|
|
|
485
473
|
SignaturePad.prototype._fromData = function (pointGroups, drawCurve, drawDot) {
|
|
486
474
|
for (var i = 0; i < pointGroups.length; i++) {
|
|
487
475
|
var group = pointGroups[i];
|
|
488
|
-
var color = group.color,
|
|
489
|
-
|
|
490
|
-
var
|
|
491
|
-
maxWidth = group.maxWidth; // Enhance undo
|
|
492
|
-
var compositeOperation = group.compositeOperation; // Fix undo problem
|
|
476
|
+
var color = group.color, points = group.points;
|
|
477
|
+
var minWidth = group.minWidth, maxWidth = group.maxWidth, dotSize = group.dotSize;
|
|
478
|
+
var compositeOperation = group.compositeOperation;
|
|
493
479
|
this._reset();
|
|
480
|
+
this._lastWidth = dotSize;
|
|
494
481
|
if (points.length > 1) {
|
|
495
482
|
for (var j = 0; j < points.length; j++) {
|
|
496
|
-
var
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
basicPoint.y,
|
|
500
|
-
basicPoint.time
|
|
501
|
-
);
|
|
502
|
-
// this.penColor = color;
|
|
503
|
-
this.minWidth = minWidth; // Enhance undo
|
|
504
|
-
this.maxWidth = maxWidth; // Enhance undo
|
|
505
|
-
this._ctx.globalCompositeOperation = compositeOperation; // Fix undo problem
|
|
506
|
-
var curve = this._addPoint(point);
|
|
483
|
+
var point = new Point(points[j].x, points[j].y, points[j].time);
|
|
484
|
+
this._ctx.globalCompositeOperation = compositeOperation;
|
|
485
|
+
var curve = this._addPoint(point, minWidth, maxWidth);
|
|
507
486
|
if (curve) drawCurve({ color, curve });
|
|
508
|
-
}
|
|
509
|
-
} else drawDot({ color, point: points[0] });
|
|
510
|
-
}
|
|
487
|
+
};
|
|
488
|
+
} else drawDot({ color, point: points[0], dotSize });
|
|
489
|
+
};
|
|
511
490
|
this._ctx.globalCompositeOperation = this._isDrawing ? "source-over" : "destination-out";
|
|
512
491
|
};
|
|
513
492
|
SignaturePad.prototype._toSVG = function () {
|
|
@@ -523,38 +502,28 @@ export default `
|
|
|
523
502
|
svg.setAttribute('height', this.canvas.height.toString());
|
|
524
503
|
this._fromData(pointGroups, function (_a) {
|
|
525
504
|
var color = _a.color, curve = _a.curve;
|
|
526
|
-
var path = document.createElement(
|
|
527
|
-
if (!isNaN(curve.control1.x) &&
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
path.setAttribute('d', attr);
|
|
536
|
-
path.setAttribute('stroke-width', (curve.endWidth * 2.25).toFixed(3));
|
|
537
|
-
path.setAttribute('stroke', color);
|
|
538
|
-
path.setAttribute('fill', 'none');
|
|
539
|
-
path.setAttribute('stroke-linecap', 'round');
|
|
540
|
-
svg.appendChild(path);
|
|
505
|
+
var path = document.createElement("path");
|
|
506
|
+
if (!isNaN(curve.control1.x) && !isNaN(curve.control1.y) && !isNaN(curve.control2.x) && !isNaN(curve.control2.y)) {
|
|
507
|
+
var attr = "M " + curve.startPoint.x.toFixed(3) + "," + curve.startPoint.y.toFixed(3) + " " + ("C " + curve.control1.x.toFixed(3) + "," + curve.control1.y.toFixed(3) + " ") + (curve.control2.x.toFixed(3) + "," + curve.control2.y.toFixed(3) + " ") + (curve.endPoint.x.toFixed(3) + "," + curve.endPoint.y.toFixed(3));
|
|
508
|
+
path.setAttribute("d", attr);
|
|
509
|
+
path.setAttribute("stroke-width", (curve.endWidth * 2.25).toFixed(3));
|
|
510
|
+
path.setAttribute("stroke", color);
|
|
511
|
+
path.setAttribute("fill", "none");
|
|
512
|
+
path.setAttribute("stroke-linecap", "round");
|
|
513
|
+
svg.appendChild(path);
|
|
541
514
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
point = _a.point;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
circle.setAttribute("cy", point.y.toString());
|
|
555
|
-
circle.setAttribute("fill", color);
|
|
556
|
-
svg.appendChild(circle);
|
|
557
|
-
});
|
|
515
|
+
},
|
|
516
|
+
function (_a) {
|
|
517
|
+
var color = _a.color,point = _a.point;
|
|
518
|
+
var circle = document.createElement("circle");
|
|
519
|
+
var dotSize = _a.dotSize ? _a.dotSize : typeof _this.dotSize === "function" ? _this.dotSize() : _this.dotSize;
|
|
520
|
+
circle.setAttribute("r", dotSize.toString());
|
|
521
|
+
circle.setAttribute("cx", point.x.toString());
|
|
522
|
+
circle.setAttribute("cy", point.y.toString());
|
|
523
|
+
circle.setAttribute("fill", color);
|
|
524
|
+
svg.appendChild(circle);
|
|
525
|
+
}
|
|
526
|
+
);
|
|
558
527
|
var prefix = 'data:image/svg+xml;base64,';
|
|
559
528
|
var header = '<svg' +
|
|
560
529
|
' xmlns="http://www.w3.org/2000/svg"' +
|
package/index.d.ts
CHANGED
|
@@ -2,9 +2,9 @@ declare module "react-native-signature-canvas" {
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import {StyleProp, ViewStyle} from "react-native";
|
|
4
4
|
|
|
5
|
-
type ImageType = "image/jpeg" | "image/svg+xml";
|
|
5
|
+
type ImageType = "image/png" | "image/jpeg" | "image/svg+xml";
|
|
6
6
|
|
|
7
|
-
type DataURL = "Base64";
|
|
7
|
+
type DataURL = "Base64" | string;
|
|
8
8
|
|
|
9
9
|
type ForwardRef<T, P> = React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
|
|
10
10
|
|
|
@@ -17,7 +17,7 @@ declare module "react-native-signature-canvas" {
|
|
|
17
17
|
bgSrc?: string;
|
|
18
18
|
clearText?: string;
|
|
19
19
|
confirmText?: string;
|
|
20
|
-
customHtml?: string
|
|
20
|
+
customHtml?: (injectedJavaScript: string) => string;
|
|
21
21
|
dataURL?: DataURL;
|
|
22
22
|
descriptionText?: string;
|
|
23
23
|
dotSize?: number;
|
|
@@ -32,7 +32,8 @@ declare module "react-native-signature-canvas" {
|
|
|
32
32
|
onDraw?: () => void;
|
|
33
33
|
onErase?: () => void;
|
|
34
34
|
onGetData?: () => void;
|
|
35
|
-
|
|
35
|
+
onChangePenColor?: () => void;
|
|
36
|
+
onChangePenSize?: () => void;
|
|
36
37
|
onBegin?: () => void;
|
|
37
38
|
onEnd?: () => void;
|
|
38
39
|
overlayHeight?: number;
|
|
@@ -49,6 +50,7 @@ declare module "react-native-signature-canvas" {
|
|
|
49
50
|
|
|
50
51
|
export type SignatureViewRef = {
|
|
51
52
|
changePenColor: (color: string) => void;
|
|
53
|
+
changePenSize: (minW: number, maxW: number) => void;
|
|
52
54
|
clearSignature: () => void;
|
|
53
55
|
cropWhitespace: (url: string) => void;
|
|
54
56
|
draw: () => void;
|
|
@@ -61,4 +63,4 @@ declare module "react-native-signature-canvas" {
|
|
|
61
63
|
|
|
62
64
|
const SignatureView: ForwardRef<SignatureViewRef, SignatureViewProps>
|
|
63
65
|
export default SignatureView;
|
|
64
|
-
}
|
|
66
|
+
}
|
package/index.js
CHANGED
|
@@ -28,7 +28,7 @@ const SignatureView = forwardRef(({
|
|
|
28
28
|
customHtml = null,
|
|
29
29
|
dataURL = "",
|
|
30
30
|
descriptionText = "Sign above",
|
|
31
|
-
dotSize =
|
|
31
|
+
dotSize = null,
|
|
32
32
|
imageType = "",
|
|
33
33
|
minWidth = 0.5,
|
|
34
34
|
maxWidth = 2.5,
|
|
@@ -41,6 +41,7 @@ const SignatureView = forwardRef(({
|
|
|
41
41
|
onErase=()=>{},
|
|
42
42
|
onGetData=()=>{},
|
|
43
43
|
onChangePenColor=()=>{},
|
|
44
|
+
onChangePenSize=()=>{},
|
|
44
45
|
onBegin = () => {},
|
|
45
46
|
onEnd = () => {},
|
|
46
47
|
overlayHeight = 0,
|
|
@@ -68,7 +69,7 @@ const SignatureView = forwardRef(({
|
|
|
68
69
|
injectedJavaScript = injectedJavaScript.replace(/<%dotSize%>/g, dotSize);
|
|
69
70
|
injectedJavaScript = injectedJavaScript.replace(/<%minWidth%>/g, minWidth);
|
|
70
71
|
injectedJavaScript = injectedJavaScript.replace(/<%maxWidth%>/g, maxWidth);
|
|
71
|
-
|
|
72
|
+
|
|
72
73
|
let html = htmlContentValue(injectedJavaScript);
|
|
73
74
|
html = html.replace(/<%bgWidth%>/g, bgWidth);
|
|
74
75
|
html = html.replace(/<%bgHeight%>/g, bgHeight);
|
|
@@ -83,8 +84,8 @@ const SignatureView = forwardRef(({
|
|
|
83
84
|
html = html.replace(/<%orientation%>/g, rotated);
|
|
84
85
|
|
|
85
86
|
return { html };
|
|
86
|
-
}, [customHtml, autoClear, trimWhitespace, rotated, imageType, webStyle, descriptionText, confirmText, clearText, dataURL])
|
|
87
|
-
|
|
87
|
+
}, [customHtml, autoClear, trimWhitespace, rotated, imageType, webStyle, descriptionText, confirmText, clearText, dataURL, bgSrc, bgWidth, bgHeight])
|
|
88
|
+
|
|
88
89
|
const isJson = (str)=> {
|
|
89
90
|
try {
|
|
90
91
|
JSON.parse(str);
|
|
@@ -123,6 +124,9 @@ const SignatureView = forwardRef(({
|
|
|
123
124
|
case "CHANGE_PEN":
|
|
124
125
|
onChangePenColor();
|
|
125
126
|
break;
|
|
127
|
+
case "CHANGE_PEN_SIZE":
|
|
128
|
+
onChangePenSize();
|
|
129
|
+
break;
|
|
126
130
|
default:
|
|
127
131
|
isJson(e.nativeEvent.data)? onGetData(e.nativeEvent.data): onOK(e.nativeEvent.data);
|
|
128
132
|
}
|
|
@@ -164,6 +168,11 @@ const SignatureView = forwardRef(({
|
|
|
164
168
|
webViewRef.current.injectJavaScript("changePenColor('"+color+"');true;");
|
|
165
169
|
}
|
|
166
170
|
},
|
|
171
|
+
changePenSize: (minW, maxW) => {
|
|
172
|
+
if (webViewRef.current) {
|
|
173
|
+
webViewRef.current.injectJavaScript("changePenSize("+minW+','+maxW+");true;");
|
|
174
|
+
}
|
|
175
|
+
},
|
|
167
176
|
getData: () => {
|
|
168
177
|
if (webViewRef.current) {
|
|
169
178
|
webViewRef.current.injectJavaScript("getData();true;");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-signature-canvas",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"description": "React Native Signature Component based Canvas for Android && IOS && expo",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -29,9 +29,9 @@
|
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://github.com/YanYuanFE/react-native-signature-canvas#readme",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"react-native-webview": "^11.0
|
|
32
|
+
"react-native-webview": "^11.17.0"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"react-native-webview": "
|
|
35
|
+
"react-native-webview": "11"
|
|
36
36
|
}
|
|
37
37
|
}
|