@@ -26,38 +26,37 @@ class SwipeableListItem extends PureComponent {
26
26
}
27
27
28
28
componentDidMount ( ) {
29
- window . addEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
30
- window . addEventListener ( 'touchend' , this . handleDragEndTouch ) ;
31
- window . addEventListener ( 'mousemove' , this . handleMouseMove ) ;
32
-
33
29
this . wrapper . addEventListener ( 'mousedown' , this . handleDragStartMouse ) ;
34
30
this . wrapper . addEventListener ( 'touchstart' , this . handleDragStartTouch ) ;
35
- this . wrapper . addEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
36
- this . wrapper . addEventListener ( 'touchend' , this . handleDragEndTouch ) ;
37
31
}
38
32
39
33
componentWillUnmount ( ) {
40
- window . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
41
- window . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
42
- window . removeEventListener ( 'mousemove' , this . handleMouseMove ) ;
43
-
44
34
this . wrapper . removeEventListener ( 'mousedown' , this . handleDragStartMouse ) ;
45
35
this . wrapper . removeEventListener ( 'touchstart' , this . handleDragStartTouch ) ;
46
- this . wrapper . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
47
- this . wrapper . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
48
36
}
49
37
50
38
handleDragStartMouse = event => {
51
39
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 ) ;
53
45
this . wrapper . addEventListener ( 'mousemove' , this . handleMouseMove ) ;
46
+
47
+ this . handleDragStart ( event ) ;
54
48
} ;
55
49
56
50
handleDragStartTouch = event => {
57
51
// 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
+
58
58
const touch = event . targetTouches [ 0 ] ;
59
59
this . handleDragStart ( touch ) ;
60
- this . wrapper . addEventListener ( 'touchmove' , this . handleTouchMove ) ;
61
60
} ;
62
61
63
62
handleDragStart = ( { clientX } ) => {
@@ -75,12 +74,21 @@ class SwipeableListItem extends PureComponent {
75
74
} ;
76
75
77
76
handleDragEndMouse = ( ) => {
77
+ window . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
78
+ window . removeEventListener ( 'mousemove' , this . handleMouseMove ) ;
79
+
80
+ this . wrapper . removeEventListener ( 'mouseup' , this . handleDragEndMouse ) ;
78
81
this . wrapper . removeEventListener ( 'mousemove' , this . handleMouseMove ) ;
82
+
79
83
this . handleDragEnd ( ) ;
80
84
} ;
81
85
82
86
handleDragEndTouch = ( ) => {
87
+ window . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
88
+
89
+ this . wrapper . removeEventListener ( 'touchend' , this . handleDragEndTouch ) ;
83
90
this . wrapper . removeEventListener ( 'touchmove' , this . handleTouchMove ) ;
91
+
84
92
this . handleDragEnd ( ) ;
85
93
} ;
86
94
0 commit comments