@@ -14,7 +14,8 @@ export default class SignatureCanvas extends Component {
14
14
penColor : PropTypes . string ,
15
15
onEnd : PropTypes . func ,
16
16
onBegin : PropTypes . func ,
17
- canvasProps : PropTypes . object
17
+ canvasProps : PropTypes . object ,
18
+ clearOnResize : PropTypes . bool
18
19
}
19
20
20
21
static defaultProps = {
@@ -27,7 +28,8 @@ export default class SignatureCanvas extends Component {
27
28
penColor : 'black' ,
28
29
backgroundColor : 'rgba(0,0,0,0)' ,
29
30
onEnd : ( ) => { } ,
30
- onBegin : ( ) => { }
31
+ onBegin : ( ) => { } ,
32
+ clearOnResize : true
31
33
}
32
34
33
35
componentDidMount ( ) {
@@ -83,6 +85,13 @@ export default class SignatureCanvas extends Component {
83
85
84
86
isEmpty = ( ) => this . _isEmpty
85
87
88
+ _checkClearOnResize = ( ) => {
89
+ if ( ! this . props . clearOnResize ) {
90
+ return
91
+ }
92
+ this . _resizeCanvas ( )
93
+ }
94
+
86
95
_resizeCanvas = ( ) => {
87
96
let canvasProps = this . props . canvasProps || { }
88
97
let { width, height} = canvasProps
@@ -120,7 +129,8 @@ export default class SignatureCanvas extends Component {
120
129
this . _canvas . addEventListener ( 'mousedown' , this . _handleMouseDown )
121
130
this . _canvas . addEventListener ( 'mousemove' , this . _handleMouseMove )
122
131
document . addEventListener ( 'mouseup' , this . _handleMouseUp )
123
- window . addEventListener ( 'resize' , this . _resizeCanvas )
132
+
133
+ window . addEventListener ( 'resize' , this . _checkClearOnResize )
124
134
}
125
135
126
136
_handleTouchEvents = ( ) => {
@@ -141,7 +151,7 @@ export default class SignatureCanvas extends Component {
141
151
this . _canvas . removeEventListener ( "touchmove" , this . _handleTouchMove )
142
152
document . removeEventListener ( "touchend" , this . _handleTouchEnd )
143
153
144
- window . removeEventListener ( " resize" , this . _resizeCanvas )
154
+ window . addEventListener ( ' resize' , this . _checkClearOnResize )
145
155
}
146
156
147
157
_handleMouseDown = ( ev ) => {
0 commit comments