Skip to content

Commit 36b4b95

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 f356172 commit 36b4b95

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
@@ -95,25 +95,25 @@ export default class SignatureCanvas extends Component {
9595
_resizeCanvas = () => {
9696
let canvasProps = this.props.canvasProps || {}
9797
let {width, height} = canvasProps
98+
// don't resize if the canvas has fixed width and height
99+
if (width && height) {
100+
return
101+
}
98102

99-
let ctx = this._ctx
100103
let canvas = this._canvas
101104
/* When zoomed out to less than 100%, for some very strange reason,
102105
some browsers report devicePixelRatio as less than 1
103106
and only part of the canvas is cleared then. */
104107
let ratio = Math.max(window.devicePixelRatio || 1, 1)
105108

106-
// only change width/height if none has been passed in as a prop
107109
if (!width) {
108110
canvas.width = canvas.offsetWidth * ratio
109111
}
110112
if (!height) {
111113
canvas.height = canvas.offsetHeight * ratio
112114
}
113-
if (!width || !height) {
114-
ctx.scale(ratio, ratio)
115-
this.clear()
116-
}
115+
canvas.getContext('2d').scale(ratio, ratio)
116+
this.clear()
117117
}
118118

119119
_reset = () => {

0 commit comments

Comments
 (0)