@@ -26,38 +26,37 @@ class SwipeableListItem extends PureComponent {
2626 }
2727
2828 componentDidMount ( ) {
29- window . addEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
30- window . addEventListener ( 'touchend' , this . handleDragEndTouch ) ;
31- window . addEventListener ( 'mousemove' , this . handleMouseMove ) ;
32-
3329 this . wrapper . addEventListener ( 'mousedown' , this . handleDragStartMouse ) ;
3430 this . wrapper . addEventListener ( 'touchstart' , this . handleDragStartTouch ) ;
35- this . wrapper . addEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
36- this . wrapper . addEventListener ( 'touchend' , this . handleDragEndTouch ) ;
3731 }
3832
3933 componentWillUnmount ( ) {
40- window . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
41- window . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
42- window . removeEventListener ( 'mousemove' , this . handleMouseMove ) ;
43-
4434 this . wrapper . removeEventListener ( 'mousedown' , this . handleDragStartMouse ) ;
4535 this . wrapper . removeEventListener ( 'touchstart' , this . handleDragStartTouch ) ;
46- this . wrapper . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
47- this . wrapper . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
4836 }
4937
5038 handleDragStartMouse = event => {
5139 event . stopPropagation ( ) ;
52- this . handleDragStart ( event ) ;
40+
41+ window . addEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
42+ window . addEventListener ( 'mousemove' , this . handleMouseMove ) ;
43+
44+ this . wrapper . addEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
5345 this . wrapper . addEventListener ( 'mousemove' , this . handleMouseMove ) ;
46+
47+ this . handleDragStart ( event ) ;
5448 } ;
5549
5650 handleDragStartTouch = event => {
5751 // do not stop propagation here as it can be handled by parent to start scrolling
52+
53+ window . addEventListener ( 'touchend' , this . handleDragEndTouch ) ;
54+
55+ this . wrapper . addEventListener ( 'touchend' , this . handleDragEndTouch ) ;
56+ this . wrapper . addEventListener ( 'touchmove' , this . handleTouchMove ) ;
57+
5858 const touch = event . targetTouches [ 0 ] ;
5959 this . handleDragStart ( touch ) ;
60- this . wrapper . addEventListener ( 'touchmove' , this . handleTouchMove ) ;
6160 } ;
6261
6362 handleDragStart = ( { clientX } ) => {
@@ -75,12 +74,21 @@ class SwipeableListItem extends PureComponent {
7574 } ;
7675
7776 handleDragEndMouse = ( ) => {
77+ window . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
78+ window . removeEventListener ( 'mousemove' , this . handleMouseMove ) ;
79+
80+ this . wrapper . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
7881 this . wrapper . removeEventListener ( 'mousemove' , this . handleMouseMove ) ;
82+
7983 this . handleDragEnd ( ) ;
8084 } ;
8185
8286 handleDragEndTouch = ( ) => {
87+ window . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
88+
89+ this . wrapper . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
8390 this . wrapper . removeEventListener ( 'touchmove' , this . handleTouchMove ) ;
91+
8492 this . handleDragEnd ( ) ;
8593 } ;
8694
0 commit comments