@@ -19,6 +19,8 @@ export default class Rect extends PureComponent {
19
19
styles : PropTypes . object ,
20
20
zoomable : PropTypes . string ,
21
21
rotatable : PropTypes . bool ,
22
+ dragStartThreshold : PropTypes . number ,
23
+ dragStartTimeThreshold : PropTypes . number ,
22
24
onResizeStart : PropTypes . func ,
23
25
onResize : PropTypes . func ,
24
26
onResizeEnd : PropTypes . func ,
@@ -35,24 +37,48 @@ export default class Rect extends PureComponent {
35
37
36
38
// Drag
37
39
startDrag = ( e ) => {
38
- let { clientX : startX , clientY : startY } = e
39
- this . props . onDragStart && this . props . onDragStart ( )
40
+ let { clientX : lastX , clientY : lastY } = e
40
41
this . _isMouseDown = true
42
+
43
+ let dragStarted = false
44
+ const { dragStartThreshold, dragStartTimeThreshold } = this . props
45
+ const startDragTimer = setTimeout ( ( ) => {
46
+ dragStarted = true
47
+ this . props . onDragStart && this . props . onDragStart ( )
48
+ this . props . onDrag ( 0 , 0 )
49
+ } , dragStartTimeThreshold )
50
+
41
51
const onMove = ( e ) => {
42
52
if ( ! this . _isMouseDown ) return // patch: fix windows press win key during mouseup issue
43
53
e . stopImmediatePropagation ( )
44
54
const { clientX, clientY } = e
45
- const deltaX = clientX - startX
46
- const deltaY = clientY - startY
55
+ const deltaX = clientX - lastX
56
+ const deltaY = clientY - lastY
57
+ lastX = clientX
58
+ lastY = clientY
59
+
60
+ if ( ! dragStarted ) {
61
+ if (
62
+ Math . abs ( deltaX ) < dragStartThreshold &&
63
+ Math . abs ( deltaY ) < dragStartThreshold
64
+ ) {
65
+ return
66
+ }
67
+ dragStarted = true
68
+ this . props . onDragStart && this . props . onDragStart ( )
69
+ }
70
+
47
71
this . props . onDrag ( deltaX , deltaY )
48
- startX = clientX
49
- startY = clientY
50
72
}
51
73
const onUp = ( ) => {
52
74
document . removeEventListener ( 'mousemove' , onMove )
53
75
document . removeEventListener ( 'mouseup' , onUp )
54
76
if ( ! this . _isMouseDown ) return
55
77
this . _isMouseDown = false
78
+ if ( ! dragStarted ) {
79
+ clearTimeout ( startDragTimer )
80
+ return
81
+ }
56
82
this . props . onDragEnd && this . props . onDragEnd ( )
57
83
}
58
84
document . addEventListener ( 'mousemove' , onMove )
0 commit comments