@@ -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+ } , dragStartTimeThreshold )
49+
4150 const onMove = ( e ) => {
4251 if ( ! this . _isMouseDown ) return // patch: fix windows press win key during mouseup issue
4352 e . stopImmediatePropagation ( )
4453 const { clientX, clientY } = e
45- const deltaX = clientX - startX
46- const deltaY = clientY - startY
54+ const deltaX = clientX - lastX
55+ const deltaY = clientY - lastY
56+ lastX = clientX
57+ lastY = clientY
58+
59+ if ( ! dragStarted ) {
60+ if (
61+ Math . abs ( deltaX ) < dragStartThreshold &&
62+ Math . abs ( deltaY ) < dragStartThreshold
63+ ) {
64+ return
65+ }
66+ dragStarted = true
67+ clearTimeout ( startDragTimer )
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