@@ -29,13 +29,16 @@ class SwipeableListItem extends PureComponent {
29
29
30
30
this . startTime = null ;
31
31
32
+ this . prevSwipeDistancePercent = 0 ;
33
+
32
34
this . resetState ( ) ;
33
35
}
34
36
35
37
resetState = ( ) => {
36
38
this . dragStartPoint = { x : - 1 , y : - 1 } ;
37
39
this . dragDirection = DragDirection . UNKNOWN ;
38
40
this . left = 0 ;
41
+ this . prevSwipeDistancePercent = 0 ;
39
42
} ;
40
43
41
44
get dragHorizontalDirectionThreshold ( ) {
@@ -169,6 +172,10 @@ class SwipeableListItem extends PureComponent {
169
172
} else if ( this . left > this . listElement . offsetWidth * threshold ) {
170
173
this . handleSwipedRight ( ) ;
171
174
}
175
+
176
+ if ( this . props . onSwipeEnd ) {
177
+ this . props . onSwipeEnd ( ) ;
178
+ }
172
179
}
173
180
174
181
this . resetState ( ) ;
@@ -250,6 +257,14 @@ class SwipeableListItem extends PureComponent {
250
257
}
251
258
break ;
252
259
}
260
+
261
+ if (
262
+ this . props . onSwipeStart &&
263
+ ( this . dragDirection === DragDirection . LEFT ||
264
+ this . dragDirection === DragDirection . RIGHT )
265
+ ) {
266
+ this . props . onSwipeStart ( ) ;
267
+ }
253
268
}
254
269
} ;
255
270
@@ -279,6 +294,24 @@ class SwipeableListItem extends PureComponent {
279
294
280
295
const opacity = ( Math . abs ( this . left ) / 100 ) . toFixed ( 2 ) ;
281
296
297
+ if ( this . props . onSwipeStateChange ) {
298
+ const swipeDistance = Math . max (
299
+ 0 ,
300
+ this . listElement . offsetWidth - Math . abs ( this . left )
301
+ ) ;
302
+
303
+ const swipeDistancePercent =
304
+ 100 -
305
+ Math . round ( ( 100 * swipeDistance ) / this . listElement . offsetWidth ) ;
306
+
307
+ if ( this . prevSwipeDistancePercent !== swipeDistancePercent ) {
308
+ this . props . onSwipeStateChange ( {
309
+ swipeDistancePercent
310
+ } ) ;
311
+ this . prevSwipeDistancePercent = swipeDistancePercent ;
312
+ }
313
+ }
314
+
282
315
if ( opacity < 1 && opacity . toString ( ) !== contentToShow . style . opacity ) {
283
316
contentToShow . style . opacity = opacity . toString ( ) ;
284
317
@@ -361,7 +394,11 @@ SwipeableListItem.propTypes = {
361
394
swipeRight : SwipeActionPropType ,
362
395
scrollStartThreshold : PropTypes . number ,
363
396
swipeStartThreshold : PropTypes . number ,
364
- threshold : PropTypes . number
397
+ threshold : PropTypes . number ,
398
+
399
+ onSwipeStart : PropTypes . func ,
400
+ onSwipeEnd : PropTypes . func ,
401
+ onSwipeStateChange : PropTypes . func
365
402
} ;
366
403
367
404
export default SwipeableListItem ;
0 commit comments