Skip to content

Commit 37c1223

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 a6fbaa4 commit 37c1223

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

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

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

118118
_reset = () => {

0 commit comments

Comments
 (0)