@@ -351,6 +351,81 @@ describe("useSwipeable", () => {
351
351
expect ( onSwipedRight ) . not . toHaveBeenCalled ( ) ;
352
352
} ) ;
353
353
354
+ it ( "allows different delta for each side" , ( ) => {
355
+ const onSwipedRight = jest . fn ( ) ;
356
+ const onSwipedLeft = jest . fn ( ) ;
357
+ const onSwipedUp = jest . fn ( ) ;
358
+ const onSwipedDown = jest . fn ( ) ;
359
+ const { getByText } = render (
360
+ < SwipeableUsingHook
361
+ onSwipedRight = { onSwipedRight }
362
+ onSwipedLeft = { onSwipedLeft }
363
+ onSwipedUp = { onSwipedUp }
364
+ onSwipedDown = { onSwipedDown }
365
+ delta = { {
366
+ right : 10 ,
367
+ left : 20 ,
368
+ up : 30 ,
369
+ down : 40 ,
370
+ } }
371
+ />
372
+ ) ;
373
+
374
+ const touchArea = getByText ( TESTING_TEXT ) ;
375
+
376
+ // check right
377
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
378
+ fireEvent [ TM ] ( touchArea , cte ( { x : 105 , y : 100 } ) ) ;
379
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
380
+
381
+ expect ( onSwipedRight ) . not . toHaveBeenCalled ( ) ;
382
+
383
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
384
+ fireEvent [ TM ] ( touchArea , cte ( { x : 110 , y : 100 } ) ) ;
385
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
386
+
387
+ expect ( onSwipedRight ) . toHaveBeenCalledTimes ( 1 ) ;
388
+
389
+ // check left
390
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
391
+ fireEvent [ TM ] ( touchArea , cte ( { x : 90 , y : 100 } ) ) ;
392
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
393
+
394
+ expect ( onSwipedLeft ) . not . toHaveBeenCalled ( ) ;
395
+
396
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
397
+ fireEvent [ TM ] ( touchArea , cte ( { x : 80 , y : 100 } ) ) ;
398
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
399
+
400
+ expect ( onSwipedLeft ) . toHaveBeenCalledTimes ( 1 ) ;
401
+
402
+ // check up
403
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
404
+ fireEvent [ TM ] ( touchArea , cte ( { x : 100 , y : 80 } ) ) ;
405
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
406
+
407
+ expect ( onSwipedUp ) . not . toHaveBeenCalled ( ) ;
408
+
409
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
410
+ fireEvent [ TM ] ( touchArea , cte ( { x : 100 , y : 70 } ) ) ;
411
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
412
+
413
+ expect ( onSwipedUp ) . toHaveBeenCalledTimes ( 1 ) ;
414
+
415
+ // check down
416
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
417
+ fireEvent [ TM ] ( touchArea , cte ( { x : 100 , y : 130 } ) ) ;
418
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
419
+
420
+ expect ( onSwipedDown ) . not . toHaveBeenCalled ( ) ;
421
+
422
+ fireEvent [ TS ] ( touchArea , cte ( { x : 100 , y : 100 } ) ) ;
423
+ fireEvent [ TM ] ( touchArea , cte ( { x : 100 , y : 140 } ) ) ;
424
+ fireEvent [ TE ] ( touchArea , cte ( { } ) ) ;
425
+
426
+ expect ( onSwipedDown ) . toHaveBeenCalledTimes ( 1 ) ;
427
+ } ) ;
428
+
354
429
it ( "Handle Rotation by 90 degree" , ( ) => {
355
430
const swipeFuncsRight = getMockedSwipeFunctions ( ) ;
356
431
const { getByText, rerender } = render (
0 commit comments