@@ -275,42 +275,39 @@ export default class extends PureComponent {
275
275
} ) ;
276
276
} ;
277
277
278
- handleTouchStart = e => {
279
- const { x, y } = this . getPointerPos ( e ) ;
280
- this . lazy . update ( { x, y } , { both : true } ) ;
281
- this . handleMouseDown ( e ) ;
278
+ handleDrawStart = e => {
279
+ e . preventDefault ( ) ;
282
280
283
- this . mouseHasMoved = true ;
284
- } ;
281
+ // Start drawing
282
+ this . isPressing = true ;
285
283
286
- handleTouchMove = e => {
287
- e . preventDefault ( ) ;
288
284
const { x, y } = this . getPointerPos ( e ) ;
289
- this . handlePointerMove ( x , y ) ;
290
- } ;
291
285
292
- handleTouchEnd = e => {
293
- this . handleMouseUp ( e ) ;
294
- const brush = this . lazy . getBrushCoordinates ( ) ;
295
- this . lazy . update ( { x : brush . x , y : brush . y } , { both : true } ) ;
296
- this . mouseHasMoved = true ;
286
+ if ( e . touches && e . touches . length > 0 ) {
287
+ // on touch, set catenary position to touch pos
288
+ this . lazy . update ( { x, y } , { both : true } ) ;
289
+ }
290
+
291
+ // Ensure the initial down position gets added to our line
292
+ this . handlePointerMove ( x , y ) ;
297
293
} ;
298
294
299
- handleMouseDown = e => {
295
+ handleDrawMove = e => {
300
296
e . preventDefault ( ) ;
301
- this . isPressing = true ;
302
- } ;
303
297
304
- handleMouseMove = e => {
305
298
const { x, y } = this . getPointerPos ( e ) ;
306
299
this . handlePointerMove ( x , y ) ;
307
300
} ;
308
301
309
- handleMouseUp = e => {
302
+ handleDrawEnd = e => {
310
303
e . preventDefault ( ) ;
304
+
305
+ // Draw to this end pos
306
+ this . handleDrawMove ( e ) ;
307
+
308
+ // Stop drawing & save the drawn line
311
309
this . isDrawing = false ;
312
310
this . isPressing = false ;
313
-
314
311
this . saveLine ( ) ;
315
312
} ;
316
313
@@ -359,19 +356,19 @@ export default class extends PureComponent {
359
356
handlePointerMove = ( x , y ) => {
360
357
if ( this . props . disabled ) return ;
361
358
362
- const hasChanged = this . lazy . update ( { x, y } ) ;
359
+ this . lazy . update ( { x, y } ) ;
363
360
const isDisabled = ! this . lazy . isEnabled ( ) ;
364
361
365
362
if (
366
- ( this . isPressing && hasChanged && ! this . isDrawing ) ||
363
+ ( this . isPressing && ! this . isDrawing ) ||
367
364
( isDisabled && this . isPressing )
368
365
) {
369
366
// Start drawing and add point
370
367
this . isDrawing = true ;
371
368
this . points . push ( this . lazy . brush . toObject ( ) ) ;
372
369
}
373
370
374
- if ( this . isDrawing && ( this . lazy . brushHasMoved ( ) || isDisabled ) ) {
371
+ if ( this . isDrawing ) {
375
372
// Add new point
376
373
this . points . push ( this . lazy . brush . toObject ( ) ) ;
377
374
@@ -583,14 +580,14 @@ export default class extends PureComponent {
583
580
}
584
581
} }
585
582
style = { { ...canvasStyle , zIndex } }
586
- onMouseDown = { isInterface ? this . handleMouseDown : undefined }
587
- onMouseMove = { isInterface ? this . handleMouseMove : undefined }
588
- onMouseUp = { isInterface ? this . handleMouseUp : undefined }
589
- onMouseOut = { isInterface ? this . handleMouseUp : undefined }
590
- onTouchStart = { isInterface ? this . handleTouchStart : undefined }
591
- onTouchMove = { isInterface ? this . handleTouchMove : undefined }
592
- onTouchEnd = { isInterface ? this . handleTouchEnd : undefined }
593
- onTouchCancel = { isInterface ? this . handleTouchEnd : undefined }
583
+ onMouseDown = { isInterface ? this . handleDrawStart : undefined }
584
+ onMouseMove = { isInterface ? this . handleDrawMove : undefined }
585
+ onMouseUp = { isInterface ? this . handleDrawEnd : undefined }
586
+ onMouseOut = { isInterface ? this . handleDrawEnd : undefined }
587
+ onTouchStart = { isInterface ? this . handleDrawStart : undefined }
588
+ onTouchMove = { isInterface ? this . handleDrawMove : undefined }
589
+ onTouchEnd = { isInterface ? this . handleDrawEnd : undefined }
590
+ onTouchCancel = { isInterface ? this . handleDrawEnd : undefined }
594
591
/>
595
592
) ;
596
593
} ) }
0 commit comments