@@ -112,13 +112,21 @@ export default class Swipeable extends Component<PropType, StateType> {
112
112
_handleDrag = ( e ) => {
113
113
const { onToggleSwipeLeft} = this . props ;
114
114
115
- if ( onToggleSwipeLeft && ! this . dragThresholdReached ) {
115
+ if ( onToggleSwipeLeft ) {
116
+ // Drag left toggle
116
117
const { rowWidth, leftWidth} = this . state ;
117
118
const x = e . nativeEvent . translationX ;
118
119
const threshold = rowWidth * LEFT_TOGGLE_THRESHOLD ;
119
- if ( x >= threshold && x < threshold + 10 ) {
120
+
121
+ if ( ! this . dragThresholdReached && x >= threshold && x < threshold + 10 ) {
122
+ // move item right
120
123
this . dragThresholdReached = true ;
121
- onToggleSwipeLeft ( { rowWidth, leftWidth, dragX : x } ) ;
124
+ onToggleSwipeLeft ( { rowWidth, leftWidth, dragX : x , triggerHaptic : true } ) ;
125
+ }
126
+ if ( this . dragThresholdReached && x < threshold - 10 ) {
127
+ // move item left
128
+ this . dragThresholdReached = false ;
129
+ onToggleSwipeLeft ( { rowWidth, leftWidth, dragX : x , resetItemPosition : true } ) ;
122
130
}
123
131
}
124
132
}
@@ -215,23 +223,32 @@ export default class Swipeable extends Component<PropType, StateType> {
215
223
const { leftWidth = 0 , rowWidth = 0 } = this . state ;
216
224
const { rightOffset = rowWidth } = this . state ;
217
225
const rightWidth = rowWidth - rightOffset ;
218
- const { fullSwipeLeft, fullSwipeRight, friction, leftThreshold = leftWidth / 2 , rightThreshold = rightWidth / 2 , fullLeftThreshold, fullRightThreshold, onToggleSwipeLeft} = this . props ;
219
-
226
+ const {
227
+ fullSwipeLeft,
228
+ fullSwipeRight,
229
+ friction,
230
+ leftThreshold = leftWidth / 2 ,
231
+ rightThreshold = rightWidth / 2 ,
232
+ fullLeftThreshold,
233
+ fullRightThreshold,
234
+ onToggleSwipeLeft
235
+ } = this . props ;
220
236
const startOffsetX = this . _currentOffset ( ) + dragX / friction ;
221
237
const translationX = ( dragX + DRAG_TOSS * velocityX ) / friction ;
222
238
223
239
let toValue = 0 ;
224
240
if ( this . rowState === 0 ) {
225
- if ( onToggleSwipeLeft && translationX > leftWidth ) {
226
- if ( ! this . dragThresholdReached ) {
227
- toValue = rowWidth * LEFT_TOGGLE_THRESHOLD ;
228
- }
229
- } else if ( fullSwipeLeft && translationX > rowWidth * fullLeftThreshold ) {
241
+ if ( onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && ! this . dragThresholdReached ) {
242
+ // Swipe left toggle
243
+ toValue = rowWidth * LEFT_TOGGLE_THRESHOLD ;
244
+ } else if ( ! onToggleSwipeLeft && fullSwipeLeft && translationX > rowWidth * fullLeftThreshold ) {
230
245
toValue = rowWidth ;
231
246
} else if ( fullSwipeRight && translationX < - rowWidth * fullRightThreshold ) {
232
247
toValue = - rowWidth ;
233
248
} else if ( translationX > leftThreshold ) {
234
- toValue = leftWidth ;
249
+ if ( ! onToggleSwipeLeft || onToggleSwipeLeft && translationX < rowWidth * LEFT_TOGGLE_THRESHOLD ) {
250
+ toValue = leftWidth ;
251
+ }
235
252
} else if ( translationX < - rightThreshold ) {
236
253
toValue = - rightWidth ;
237
254
}
@@ -264,7 +281,6 @@ export default class Swipeable extends Component<PropType, StateType> {
264
281
onSwipeableWillClose,
265
282
onSwipeableWillOpen,
266
283
onFullSwipeLeft,
267
- fullSwipeLeft,
268
284
onToggleSwipeLeft,
269
285
onWillFullSwipeLeft,
270
286
onFullSwipeRight,
@@ -274,13 +290,13 @@ export default class Swipeable extends Component<PropType, StateType> {
274
290
dragX . setValue ( 0 ) ;
275
291
rowTranslation . setValue ( fromValue ) ;
276
292
this . rowState = Math . sign ( toValue ) ;
277
-
293
+
278
294
Animated . spring ( rowTranslation , {
295
+ toValue,
279
296
restSpeedThreshold : 1.7 ,
280
297
restDisplacementThreshold : 0.4 ,
281
298
velocity : velocityX ,
282
299
bounciness : 0 ,
283
- toValue,
284
300
useNativeDriver : useNativeAnimations ,
285
301
...animationOptions
286
302
} ) . start ( ( { finished} ) => {
@@ -304,7 +320,8 @@ export default class Swipeable extends Component<PropType, StateType> {
304
320
} ) ;
305
321
306
322
if ( ( toValue === rowWidth * LEFT_TOGGLE_THRESHOLD || this . dragThresholdReached ) && onToggleSwipeLeft ) {
307
- onToggleSwipeLeft ( { rowWidth, leftWidth, released : true } ) ;
323
+ onToggleSwipeLeft ( { rowWidth, leftWidth, released : true , triggerHaptic : ! this . dragThresholdReached } ) ;
324
+ this . dragThresholdReached = false ;
308
325
} else if ( toValue === rowWidth && onWillFullSwipeLeft ) {
309
326
onWillFullSwipeLeft ( )
310
327
} else if ( toValue === - rowWidth && onWillFullSwipeRight ) {
@@ -350,6 +367,7 @@ export default class Swipeable extends Component<PropType, StateType> {
350
367
} ;
351
368
352
369
toggleLeft = ( ) => {
370
+ // Programmatically left toggle
353
371
const { rowWidth} = this . state ;
354
372
this . _animateRow ( this . _currentOffset ( ) , rowWidth * LEFT_TOGGLE_THRESHOLD ) ;
355
373
} ;
0 commit comments