@@ -243,6 +243,10 @@ export default class Swipeable extends Component<Props, StateType> {
243
243
}
244
244
} ;
245
245
246
+ _hasLeftActions = this . props . renderLeftActions !== undefined ;
247
+
248
+ _hasRightActions = this . props . renderRightActions !== undefined ;
249
+
246
250
_handleRelease = nativeEvent => {
247
251
const { velocityX, translationX : dragX } = nativeEvent ;
248
252
const { leftWidth = 0 , rowWidth = 0 } = this . state ;
@@ -263,34 +267,38 @@ export default class Swipeable extends Component<Props, StateType> {
263
267
264
268
let toValue = 0 ;
265
269
if ( this . rowState === 0 ) {
266
- if ( onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && ! this . dragThresholdReached ) {
270
+ if ( this . _hasLeftActions && onToggleSwipeLeft && translationX > rowWidth * LEFT_TOGGLE_THRESHOLD && ! this . dragThresholdReached ) {
267
271
// Swipe left toggle
268
272
toValue = rowWidth * LEFT_TOGGLE_THRESHOLD ;
269
273
} else if ( ! onToggleSwipeLeft && fullSwipeLeft && translationX > rowWidth * fullLeftThreshold ) {
274
+ // Full left swipe
270
275
this . _triggerHaptic ( ) ;
271
276
toValue = rowWidth ;
272
- } else if ( fullSwipeRight && translationX < - rowWidth * fullRightThreshold ) {
277
+ } else if ( this . _hasRightActions && fullSwipeRight && translationX < - rowWidth * fullRightThreshold ) {
278
+ // Full right swipe
273
279
this . _triggerHaptic ( ) ;
274
280
toValue = - rowWidth ;
275
- } else if ( translationX > leftThreshold ) {
281
+ } else if ( this . _hasLeftActions && translationX > leftThreshold ) {
282
+ // left swipe
276
283
if ( ! onToggleSwipeLeft || onToggleSwipeLeft && translationX < rowWidth * LEFT_TOGGLE_THRESHOLD ) {
284
+ // left swipe with toggle
277
285
toValue = leftWidth ;
278
286
}
279
- } else if ( translationX < - rightThreshold ) {
287
+ } else if ( this . _hasRightActions && translationX < - rightThreshold ) {
288
+ // right swipe
280
289
toValue = - rightWidth ;
281
290
}
282
291
} else if ( this . rowState === 1 ) {
283
- // swiped to left
292
+ // swiped to the right ( left swipe)
284
293
if ( translationX > - leftThreshold ) {
285
294
toValue = leftWidth ;
286
295
}
287
296
} else {
288
- // swiped to right
297
+ // swiped to the left ( right swipe)
289
298
if ( translationX < rightThreshold ) {
290
299
toValue = - rightWidth ;
291
300
}
292
301
}
293
-
294
302
this . _animateRow ( startOffsetX , toValue , velocityX / friction ) ;
295
303
} ;
296
304
@@ -389,14 +397,18 @@ export default class Swipeable extends Component<Props, StateType> {
389
397
} ;
390
398
391
399
openLeftFull = ( ) => {
392
- const { rowWidth} = this . state ;
393
- this . _animateRow ( this . _currentOffset ( ) , rowWidth ) ;
400
+ if ( this . _hasLeftActions ) {
401
+ const { rowWidth} = this . state ;
402
+ this . _animateRow ( this . _currentOffset ( ) , rowWidth ) ;
403
+ }
394
404
} ;
395
405
396
406
toggleLeft = ( ) => {
397
407
// Programmatically left toggle
398
- const { rowWidth} = this . state ;
399
- this . _animateRow ( this . _currentOffset ( ) , rowWidth * LEFT_TOGGLE_THRESHOLD ) ;
408
+ if ( this . _hasLeftActions ) {
409
+ const { rowWidth} = this . state ;
410
+ this . _animateRow ( this . _currentOffset ( ) , rowWidth * LEFT_TOGGLE_THRESHOLD ) ;
411
+ }
400
412
} ;
401
413
402
414
openRight = ( ) => {
@@ -407,8 +419,10 @@ export default class Swipeable extends Component<Props, StateType> {
407
419
} ;
408
420
409
421
openRightFull = ( ) => {
410
- const { rowWidth} = this . state ;
411
- this . _animateRow ( this . _currentOffset ( ) , - rowWidth ) ;
422
+ if ( this . _hasRightActions ) {
423
+ const { rowWidth} = this . state ;
424
+ this . _animateRow ( this . _currentOffset ( ) , - rowWidth ) ;
425
+ }
412
426
} ;
413
427
414
428
_onRowLayout = ( { nativeEvent} ) => this . handleMeasure ( 'rowWidth' , nativeEvent ) ;
@@ -432,8 +446,8 @@ export default class Swipeable extends Component<Props, StateType> {
432
446
break ;
433
447
}
434
448
435
- const leftRender = this . props . renderLeftActions ? this . leftWidth : true ;
436
- const rightRender = this . props . renderRightActions ? this . rightOffset : true ;
449
+ const leftRender = this . _hasLeftActions ? this . leftWidth : true ;
450
+ const rightRender = this . _hasRightActions ? this . rightOffset : true ;
437
451
438
452
if ( this . rowWidth && leftRender && rightRender ) {
439
453
this . setState ( {
@@ -457,7 +471,7 @@ export default class Swipeable extends Component<Props, StateType> {
457
471
testID
458
472
} = this . props ;
459
473
460
- const left = renderLeftActions && (
474
+ const left = this . _hasLeftActions && (
461
475
< Animated . View
462
476
style = { [
463
477
styles . leftActions ,
@@ -470,7 +484,7 @@ export default class Swipeable extends Component<Props, StateType> {
470
484
</ Animated . View >
471
485
) ;
472
486
473
- const right = renderRightActions && (
487
+ const right = this . _hasRightActions && (
474
488
< Animated . View
475
489
style = { [
476
490
styles . rightActions ,
0 commit comments