Skip to content

Commit 51870ca

Browse files
author
David Khuu
committed
Increase resolution of signature pad
Increase the resolution by doubling the canvas but containing it in the WebView and increasing the device pixel ratio to match the device. rpmsoftware#10
1 parent 1010d15 commit 51870ca

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

index.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class SignaturePad extends Component {
2020
style: View.propTypes.style,
2121
penColor: PropTypes.string,
2222
dataURL: PropTypes.string,
23+
height: PropTypes.number,
24+
width: PropTypes.number,
2325
penMinWidth: PropTypes.number,
2426
penMaxWidth: PropTypes.number,
2527
useFont: PropTypes.bool,
@@ -49,7 +51,9 @@ class SignaturePad extends Component {
4951
props.penMinWidth,
5052
props.penMaxWidth,
5153
props.useFont,
52-
escapedName
54+
escapedName,
55+
props.height,
56+
props.width
5357
);
5458
var html = htmlContent(injectedJavaScript, props.fontStyle);
5559
this.source = { html };
@@ -75,7 +79,9 @@ class SignaturePad extends Component {
7579
this.props.penMinWidth,
7680
this.props.penMaxWidth,
7781
this.props.useFont,
78-
escapedName
82+
escapedName,
83+
this.props.height,
84+
this.props.width
7985
);
8086
var html = htmlContent(injectedJavaScript, this.props.fontStyle);
8187
this.source = { html };
@@ -166,7 +172,6 @@ class SignaturePad extends Component {
166172
scrollEnabled={false}
167173
javaScriptEnabled={true}
168174
style={this.props.style}
169-
scalesPageToFit={true}
170175
/>
171176
);
172177
};

injectedHtml/index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ var content = (script, fontStyle) =>
1616
-ms-transform:rotate(-90deg) translate(-100%, 0px);
1717
-webkit-transform:rotate(-90deg) translate(-100%, 0px);*/
1818
}
19+
20+
html, body {
21+
height: 100%;
22+
width: 100%;
23+
margin: 0;
24+
}
1925
</style>
2026
2127
<style type="text/css">
2228
${fontStyle}
2329
</style>
2430
2531
<body>
26-
<canvas style="margin-left: 0; margin-top: 0;"></canvas>
32+
<div><canvas style="margin-left: 0; margin-top: 0; width: 100%; height: 100%;"></canvas></div>
2733
<script>
2834
${script}
2935
</script>

injectedJavaScript/application.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, useFont, name) => `
1+
var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, useFont, name, height, width) => `
22
33
var showSignaturePad = function (signaturePadCanvas, bodyWidth, bodyHeight) {
44
/*We're rotating by 90% -> Flip X and Y*/
@@ -9,7 +9,7 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
99
var height = bodyHeight;
1010
1111
var sizeSignaturePad = function () {
12-
var devicePixelRatio = 1; /*window.devicePixelRatio || 1;*/
12+
var devicePixelRatio = window.devicePixelRatio || 1;
1313
var canvasWidth = width * devicePixelRatio;
1414
var canvasHeight = height * devicePixelRatio;
1515
signaturePadCanvas.width = canvasWidth;
@@ -44,13 +44,13 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
4444
enableSignaturePadFunctionality();
4545
};
4646
47-
var bodyWidth = document.body.clientWidth;
48-
var bodyHeight = document.body.clientHeight;
47+
var bodyWidth = document.body.clientWidth * 2;
48+
var bodyHeight = document.body.clientHeight * 2;
4949
if(!bodyWidth) {
50-
bodyWidth = window.innerWidth;
50+
bodyWidth = window.innerWidth ? window.innerWidth : ${width};
5151
}
5252
if(!bodyHeight) {
53-
bodyHeight = window.innerHeight;
53+
bodyHeight = window.innerHeight ? window.innerHeight : ${height};
5454
}
5555
5656
var canvasElement = document.querySelector("canvas");
@@ -65,8 +65,8 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
6565
var oldHeight = canvasElement.offsetHeight;
6666
var w = bodyWidth;
6767
var h = bodyHeight;
68-
canvasElement.width = oldWidth;
69-
canvasElement.height = oldHeight;
68+
canvasElement.width = oldWidth * 2;
69+
canvasElement.height = oldHeight * 2;
7070
7171
var ratio = (bodyWidth/bodyHeight);
7272
var fontSize = 45 * ratio;
@@ -89,7 +89,7 @@ var content = (penColor, backgroundColor, dataURL, penMinWidth, penMaxWidth, use
8989
/* Fire a finishedStroke function to update the state */
9090
executeNativeFunction("finishedStroke", {base64DataUrl: canvasElement.toDataURL()});
9191
} else {
92-
showSignaturePad(canvasElement, bodyWidth, bodyHeight);
92+
showSignaturePad(canvasElement, bodyWidth / 2, bodyHeight / 2);
9393
}
9494
`;
9595

0 commit comments

Comments
 (0)