@@ -3,6 +3,11 @@ import PropTypes from 'prop-types';
3
3
4
4
import './SwipeableListItem.css' ;
5
5
6
+ const SwipeActionPropType = PropTypes . shape ( {
7
+ action : PropTypes . func . isRequired ,
8
+ background : PropTypes . node . isRequired
9
+ } ) ;
10
+
6
11
class SwipeableListItem extends PureComponent {
7
12
constructor ( props ) {
8
13
super ( props ) ;
@@ -21,24 +26,24 @@ class SwipeableListItem extends PureComponent {
21
26
}
22
27
23
28
componentDidMount ( ) {
24
- window . addEventListener ( 'mouseup' , this . onDragEndMouse ) ;
25
- window . addEventListener ( 'touchend' , this . onDragEndTouch ) ;
29
+ this . wrapper . addEventListener ( 'mouseup' , this . onDragEndMouse ) ;
30
+ this . wrapper . addEventListener ( 'touchend' , this . onDragEndTouch ) ;
26
31
}
27
32
28
33
componentWillUnmount ( ) {
29
- window . removeEventListener ( 'mouseup' , this . onDragEndMouse ) ;
30
- window . removeEventListener ( 'touchend' , this . onDragEndTouch ) ;
34
+ this . wrapper . removeEventListener ( 'mouseup' , this . onDragEndMouse ) ;
35
+ this . wrapper . removeEventListener ( 'touchend' , this . onDragEndTouch ) ;
31
36
}
32
37
33
- onDragStartMouse = evt => {
34
- this . onDragStart ( evt ) ;
35
- window . addEventListener ( 'mousemove' , this . onMouseMove ) ;
38
+ onDragStartMouse = event => {
39
+ this . onDragStart ( event ) ;
40
+ this . wrapper . addEventListener ( 'mousemove' , this . onMouseMove ) ;
36
41
} ;
37
42
38
- onDragStartTouch = evt => {
39
- const touch = evt . targetTouches [ 0 ] ;
43
+ onDragStartTouch = event => {
44
+ const touch = event . targetTouches [ 0 ] ;
40
45
this . onDragStart ( touch ) ;
41
- window . addEventListener ( 'touchmove' , this . onTouchMove ) ;
46
+ this . wrapper . addEventListener ( 'touchmove' , this . onTouchMove ) ;
42
47
} ;
43
48
44
49
onDragStart = ( { clientX } ) => {
@@ -56,12 +61,12 @@ class SwipeableListItem extends PureComponent {
56
61
} ;
57
62
58
63
onDragEndMouse = ( ) => {
59
- window . removeEventListener ( 'mousemove' , this . onMouseMove ) ;
64
+ this . wrapper . removeEventListener ( 'mousemove' , this . onMouseMove ) ;
60
65
this . onDragEnd ( ) ;
61
66
} ;
62
67
63
68
onDragEndTouch = ( ) => {
64
- window . removeEventListener ( 'touchmove' , this . onTouchMove ) ;
69
+ this . wrapper . removeEventListener ( 'touchmove' , this . onTouchMove ) ;
65
70
this . onDragEnd ( ) ;
66
71
} ;
67
72
@@ -117,8 +122,8 @@ class SwipeableListItem extends PureComponent {
117
122
}
118
123
} ;
119
124
120
- onTouchMove = evt => {
121
- const touch = evt . targetTouches [ 0 ] ;
125
+ onTouchMove = event => {
126
+ const touch = event . targetTouches [ 0 ] ;
122
127
const delta = touch . clientX - this . dragStartX ;
123
128
124
129
if ( this . shouldMoveItem ( delta ) ) {
@@ -224,14 +229,8 @@ class SwipeableListItem extends PureComponent {
224
229
SwipeableListItem . propTypes = {
225
230
blockSwipe : PropTypes . bool ,
226
231
children : PropTypes . node . isRequired ,
227
- swipeLeft : PropTypes . shape ( {
228
- action : PropTypes . func . isRequired ,
229
- background : PropTypes . node . isRequired
230
- } ) ,
231
- swipeRight : PropTypes . shape ( {
232
- action : PropTypes . func . isRequired ,
233
- background : PropTypes . node . isRequired
234
- } ) ,
232
+ swipeLeft : SwipeActionPropType ,
233
+ swipeRight : SwipeActionPropType ,
235
234
threshold : PropTypes . number
236
235
} ;
237
236
0 commit comments