@@ -19,6 +19,8 @@ export default class Rect extends PureComponent {
1919 styles : PropTypes . object ,
2020 zoomable : PropTypes . string ,
2121 rotatable : PropTypes . bool ,
22+ dragStartThreshold : PropTypes . number ,
23+ dragStartTimeThreshold : PropTypes . number ,
2224 onResizeStart : PropTypes . func ,
2325 onResize : PropTypes . func ,
2426 onResizeEnd : PropTypes . func ,
@@ -35,24 +37,48 @@ export default class Rect extends PureComponent {
3537
3638 // Drag
3739 startDrag = ( e ) => {
38- let { clientX : startX , clientY : startY } = e
39- this . props . onDragStart && this . props . onDragStart ( )
40+ let { clientX : lastX , clientY : lastY } = e
4041 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+
4151 const onMove = ( e ) => {
4252 if ( ! this . _isMouseDown ) return // patch: fix windows press win key during mouseup issue
4353 e . stopImmediatePropagation ( )
4454 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+
4771 this . props . onDrag ( deltaX , deltaY )
48- startX = clientX
49- startY = clientY
5072 }
5173 const onUp = ( ) => {
5274 document . removeEventListener ( 'mousemove' , onMove )
5375 document . removeEventListener ( 'mouseup' , onUp )
5476 if ( ! this . _isMouseDown ) return
5577 this . _isMouseDown = false
78+ if ( ! dragStarted ) {
79+ clearTimeout ( startDragTimer )
80+ return
81+ }
5682 this . props . onDragEnd && this . props . onDragEnd ( )
5783 }
5884 document . addEventListener ( 'mousemove' , onMove )
0 commit comments