Skip to content

Commit afce58f

Browse files
committed
(fix): void _resizeCanvas if width/height are props
- the previous behavior of automatically editing the width and height resulted in multiple unintended problems - particularly, it would cause the width/height to be 0 if the canvas were under a display: none element, and therefore unusable until the window were resized - now it conditionally sets width/height only if canvasProps' did not have a width/height inside of it - push v0.1.3
1 parent ad11e53 commit afce58f

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-signature-canvas",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "A signature pad implementation in React",
55
"main": "build/index.js",
66
"scripts": {

src/index.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,26 @@ export default class SignatureCanvas extends Component {
8484
isEmpty = () => this._isEmpty
8585

8686
_resizeCanvas = () => {
87-
var ctx = this._ctx,
88-
canvas = this._canvas;
89-
// When zoomed out to less than 100%, for some very strange reason,
90-
// some browsers report devicePixelRatio as less than 1
91-
// and only part of the canvas is cleared then.
92-
var ratio = Math.max(window.devicePixelRatio || 1, 1);
93-
canvas.width = canvas.offsetWidth * ratio;
94-
canvas.height = canvas.offsetHeight * ratio;
95-
ctx.scale(ratio, ratio);
87+
let canvasProps = this.props.canvasProps || {}
88+
let {width, height} = canvasProps
89+
90+
let ctx = this._ctx
91+
let canvas = this._canvas
92+
/* When zoomed out to less than 100%, for some very strange reason,
93+
some browsers report devicePixelRatio as less than 1
94+
and only part of the canvas is cleared then. */
95+
let ratio = Math.max(window.devicePixelRatio || 1, 1)
96+
97+
// only change width/height if none has been passed in as a prop
98+
if (!width) {
99+
canvas.width = canvas.offsetWidth * ratio
100+
}
101+
if (!height) {
102+
canvas.height = canvas.offsetHeight * ratio
103+
}
104+
if(!width || !height) {
105+
ctx.scale(ratio, ratio)
106+
}
96107
}
97108

98109
_reset = () => {

0 commit comments

Comments
 (0)