Skip to content

Commit 6bd4fa8

Browse files
committed
(refactor): move ifs around in resize
backport of v1.0.1 addition from 46b86d5 - no logic changes, just reorganizing the code
1 parent 0056e56 commit 6bd4fa8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,25 @@ export default class SignatureCanvas extends Component {
8686
_resizeCanvas = () => {
8787
let canvasProps = this.props.canvasProps || {}
8888
let {width, height} = canvasProps
89+
// don't resize if the canvas has fixed width and height
90+
if (width && height) {
91+
return
92+
}
8993

90-
let ctx = this._ctx
9194
let canvas = this._canvas
9295
/* When zoomed out to less than 100%, for some very strange reason,
9396
some browsers report devicePixelRatio as less than 1
9497
and only part of the canvas is cleared then. */
9598
let ratio = Math.max(window.devicePixelRatio || 1, 1)
9699

97-
// only change width/height if none has been passed in as a prop
98100
if (!width) {
99101
canvas.width = canvas.offsetWidth * ratio
100102
}
101103
if (!height) {
102104
canvas.height = canvas.offsetHeight * ratio
103105
}
104-
if (!width || !height) {
105-
ctx.scale(ratio, ratio)
106-
this.clear()
107-
}
106+
canvas.getContext('2d').scale(ratio, ratio)
107+
this.clear()
108108
}
109109

110110
_reset = () => {

0 commit comments

Comments
 (0)