2

I'm trying to launch pinch gestures without launch rotate gestures also. My purpose is launch both gestures separately.

I have built hammer configuration in my module, as below:

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

export class HammerConfig extends HammerGestureConfig{

    buildHammer(element: HTMLElement)
    {
        const hammerManager = new Hammer(element);
        let rotate = new Hammer.Rotate({enable: true});
        let pinch = new Hammer.Pinch({enable: true});
        let pan = new Hammer.Pan();

        pan.requireFailure([rotate, pinch]);
        pinch.recognizeWith(rotate);
        hammerManager.add([rotate, pan, pinch]);

        return hammerManager;
    }
}

I am trying with:

pinch.dropRecognizeWith(rotate);

and

rotate.dropRecognizeWith(pinch);

This changes doesn't work. Only rotate gestures are launched...

If I add:

pinch.recognizeWith(rotate);

It launches both events...

Are there any way to launch them separately? I will appreciate any kind of help

3
  • Can you add more code for this problem? How you init hammer.js?
    – kris_IV
    Commented Jan 29, 2019 at 20:50
  • I have already update my post with hammer configuration, thanks in advance Commented Jan 30, 2019 at 9:29
  • 1
    I will look at it in the evening
    – kris_IV
    Commented Jan 30, 2019 at 9:48

1 Answer 1

1

I look into my projects where I use HammerJS in Angular 5, 6 and 7 apps, and I use different way to config HammerJS.

Your idea to disable rotate/pinch/pan in specific situation is correct and in accordance with documentation it's OK.

Hire is my sample config without requireFailure and recognizeWith:

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

@NgModule({
    imports: [
        AppModule
    ],
    providers: [{
        provide: HAMMER_GESTURE_CONFIG,
        useClass: MyHammerConfig
    }],
    bootstrap: [AppComponent]
})
export class AppBrowserModule {
}

In this way your config should look like:

export class MyHammerConfig extends HammerGestureConfig {
    overrides = <any>{
        'rotate': {
            direction: Hammer.DIRECTION_ALL,
            enable: true
        }, // override default settings
        'pinch': {
            direction: Hammer.DIRECTION_ALL,
            enable: true,
            recognizeWidth: 'rotate'
        },
        'pan': {
            direction: Hammer.DIRECTION_ALL,
            requireFailure: ['rotate, pinch']
        }
    };
}

If this is not work for you, let me know. I will try solve your problem tomorrow because I don't have more time today.

Look also to Angular docs about overriding according with HammerJS documentation hire.

5
  • Hi Kris. First of all, thanks for giving a soon response. I have changed hammer configuration as you proposed in your post, but unfortunately it doesn't works because rotate and pinch events are launched simultaneusly yet... Commented Jan 31, 2019 at 9:03
  • 1
    Thanks for response - I will look for this at this evening and give you know where is a problem. In accordance with documentation this should work, so we have an error :)
    – kris_IV
    Commented Jan 31, 2019 at 9:05
  • 1
    At this moment I don't have any result... I try with singleTap and doubleTap and a ready part of code from docs doesn't work as expected...
    – kris_IV
    Commented Jan 31, 2019 at 21:22
  • I will try again ;)
    – kris_IV
    Commented Feb 1, 2019 at 7:42
  • Today I have a lot of work, so I can't promise you that I will look for a solutions, but I can try in a weekend back to Hammer.js
    – kris_IV
    Commented Feb 7, 2019 at 14:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.