Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swipe up/down not working on Ionic 2

How can I use swipe up or swipe down with Ionic 2?

I've tried the Gestures API but it only fires on horizontal swipe.

<ion-card (swipe)="swipePage($event)">
</ion-card>
like image 588
brians69 Avatar asked Nov 25 '25 12:11

brians69


1 Answers

In the HammerJS official document, bottom line says :

When calling Hammer() to create a simple instance, the pan and swipe recognizers are configured to only detect horizontal gestures.

For additional config, you must tweak your hammer instance, try this :

First run npm install hammerjs --save && npm install @types/hammerjs --save-dev

import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import * as Hammer from 'hammerjs';

// create a class that overrides hammer default config

export class MyHammerConfig extends HammerGestureConfig  {
  overrides = <any>{
    'swipe': { direction: Hammer.DIRECTION_ALL } // override default settings
  }
}

// In your module providers, add this :

providers: [{ 
  provide: HAMMER_GESTURE_CONFIG, 
  useClass: MyHammerConfig 
}]
like image 138
kfa Avatar answered Nov 28 '25 03:11

kfa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!