11var content = ( penColor , backgroundColor , dataURL , penMinWidth , penMaxWidth , useFont , name , height , width ) => `
22
33 var showSignaturePad = function (signaturePadCanvas, bodyWidth, bodyHeight) {
4- /*We're rotating by 90% -> Flip X and Y*/
5- /*var width = bodyHeight;
6- var height = bodyWidth;*/
7-
84 var width = bodyWidth;
95 var height = bodyHeight;
106
@@ -17,22 +13,12 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
1713 signaturePadCanvas.getContext("2d").scale(devicePixelRatio, devicePixelRatio);
1814 };
1915
20- var finishedStroke = function(base64DataUrl) {
21- executeNativeFunction("finishedStroke", {base64DataUrl: base64DataUrl});
22- };
23-
2416 var enableSignaturePadFunctionality = function () {
2517 var signaturePad = new SignaturePad(signaturePadCanvas, {
2618 penColor: "${ penColor || "black" } ",
2719 backgroundColor: "${ backgroundColor || "white" } ",
2820 onEnd: function() { finishedStroke(signaturePad.toDataURL()); }
2921 });
30- /* signaturePad.translateMouseCoordinates = function (point) {
31- var translatedY = point.x;
32- var translatedX = width - point.y;
33- point.x = translatedX;
34- point.y = translatedY;
35- }; */
3622 signaturePad.minWidth = ${ penMinWidth || 1 } ;
3723 signaturePad.maxWidth = ${ penMaxWidth || 4 } ;
3824 if ("${ dataURL } ") {
@@ -55,6 +41,10 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
5541
5642 var canvasElement = document.querySelector("canvas");
5743
44+ var finishedStroke = function(base64DataUrl) {
45+ window.postMessage(JSON.stringify({ base64DataUrl: base64DataUrl }));
46+ };
47+
5848 if (${ useFont } ) {
5949 var context = canvasElement.getContext("2d");
6050 var devicePixelRatio = 1; /* window.devicePixelRatio || 1; */
@@ -85,7 +75,9 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
8575 context.fillText("${ name } ", textPosition.x, textPosition.y);
8676
8777 /* Fire a finishedStroke function to update the state */
88- executeNativeFunction("finishedStroke", {base64DataUrl: canvasElement.toDataURL()});
78+ setTimeout(function () {
79+ finishedStroke(canvasElement.toDataURL());
80+ }, 75);
8981 } else {
9082 showSignaturePad(canvasElement, bodyWidth / 2, bodyHeight / 2);
9183 }
0 commit comments