Skip to content

feat(gestures): allow override of Hammer defaults#7924

Closed
kara wants to merge 1 commit into
angular:masterfrom
kara:gestures
Closed

feat(gestures): allow override of Hammer defaults#7924
kara wants to merge 1 commit into
angular:masterfrom
kara:gestures

Conversation

@kara
Copy link
Copy Markdown
Contributor

@kara kara commented Apr 6, 2016

WIP: not ready for review

  • Please check if the PR fulfills these requirements
  • The commit message follows our guidelines: https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit-message-format
  • What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
    This PR enables the overriding of Hammer default thresholds when using gestures.
  • What is the current behavior? (You can also link to an open issue here)
    If you want to listen to Hammer gestures, you have to either keep the existing configuration or create your own Hammer event plugin with the configuration you want. This requires quite a bit of extra work if you just want to tweak a distance threshold.
  • What is the new behavior (if this is a feature change)?
    You can now override the default Hammer config by defining your own HammerGestureConfig and adding it as a provider.

main.ts

bootstrap(MyApp, [
   provide(HAMMER_GESTURE_CONFIG, {useClass: MyHammerConfig})
])

Then, in your class, set an overrides object with the event names and your changes:

MyHammerConfig.ts

export class MyHammerConfig extends HammerGestureConfig  {
   overrides = {
      'pan': {threshold: 5},
      'swipe': {velocity: 0.5}
   }
}

If you want more control, you can instantiate Hammer any way you like by defining a buildHammer method that returns a Hammer instance instead (ignoring overrides object):

MyHammerConfig.ts

export class MyHammerConfig {
   buildHammer(element: HTMLElement): Object {
      var mc = new Hammer(element);

      // custom configuration
      mc.get('pan').set({threshold: 5});

      return mc;
   }
}
  • Does this PR introduce a breaking change?

No, existing code should not have to change.

@kara kara added the state: WIP label Apr 6, 2016
@kara kara force-pushed the gestures branch 7 times, most recently from 2885efa to 917e654 Compare April 7, 2016 18:56
@kara kara added action: review The PR is still awaiting reviews from at least one requested reviewer and removed state: WIP labels Apr 7, 2016
@mhevery mhevery added pr_state: LGTM and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Apr 7, 2016
@mhevery mhevery assigned kara and unassigned mhevery Apr 7, 2016
@kara kara added the action: merge The PR is ready for merge by the caretaker label Apr 7, 2016
@mary-poppins
Copy link
Copy Markdown

Merging PR #7924 on behalf of @alxhub to branch presubmit-alxhub-pr-7924.

@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker cla: yes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants