DEV Community

Discussion on: Solution working Hammer.js after upgrading to angular 9

 
adri4no profile image
Adriano Valadares

Hi! Anand, how's going?
Yes, for a workaround i just use swipe for left and right directions and use pan action for up and down directions to simulate swipe, like this:

export class HammerConfig extends HammerGestureConfig {
overrides = {
swipe: { enable: true, direction: Hammer.DIRECTION_HORIZONTAL },
pan: { enable: true, direction: Hammer.DIRECTION_VERTICAL },
pinch: { enable: false },
rotate: { enable: false },
};
}

I do not know if there's a colateral effect but work's fine for me.

Thread Thread
 
manandkumaar profile image
Anand Kumar

Hi Jesus, Adriano,

Do we still need hammer.js for the modules have custom gesture config ?. After removing the imports of hammer.js, swipe event is not working. I am not sure what i am missing.

I am seeing this warning in chrome console -
The "swipe" event cannot be bound because Hammer.JS is not loaded and no custom loader has been specified.

Steps i have done :-

  1. uninstalled hammer.js from package.json
  2. Remove all the hammer.js imports manually
  3. imported HammerModule in app module
  4. Provided custom config in one of the lazy loaded module.
  5. Swipe not working

Any help is appreciated?.

P.S - I have removed hammer.js from the dependency and all the imports.

Thread Thread
 
adri4no profile image
Adriano Valadares • Edited

Hi Anand,

Did you import hammer.js in main.ts in your project? like this:

import "hammerjs";

You have to provide the custom config on the app.module of your project for your whole project be able to see it.

Thread Thread
 
manandkumaar profile image
Anand Kumar

Thank you Adriano.
I only removed it as i thought which is optional and not required anymore :D.

Thread Thread
 
adri4no profile image
Adriano Valadares

so... did work's?

Thread Thread
 
manandkumaar profile image
Anand Kumar

Yes, it works. Thanks for the input 👍