bsdfzzzy / vue2-hammer

Hammer.js wrapper for Vue 2.x to support some touching operation in the mobile.
MIT License
253 stars 48 forks source link

Using Custom Events #10

Open Zag42 opened 6 years ago

Zag42 commented 6 years ago

Hello,

First of all, thanks for this wrapper!

I am trying to add two custom events (single and double tap gestures) by using the "customEvents" property of VueHammer, but i have the following error:

[Vue warn]: Error in directive hammer bind hook: "TypeError: __WEBPACK_IMPORTED_MODULE_0_hammerjs___default.a[that.capitalize(...)] is not a constructor"

found in

---> <PdfPageView> at src/components/pdf/PdfPageView.vue

This property is not documented in your readme, is it supported/working? Or am i doing this all wrong ? Thanks

Here is what i have:

// ... my other  imports
import { VueHammer } from 'vue2-hammer'
import Hammer from 'hammerjs'
// ...
var singleTap = new Hammer.Tap({event: 'singletap'})
var doubleTap = new Hammer.Tap({event: 'doubletap', taps: 2})
VueHammer.customEvents = {
  'singletap': singleTap,
  'doubletap': doubleTap
}
Vue.use(VueHammer)

In my template:

<template>
<div class="adr_fullpagecontainer" :id="this.fullpageId">
  <transition v-bind:name="transitionName" id="adr_slide_transition" style="height:100%">
    <canvas 
    v-hammer:pinch="onPinch"
    v-hammer:pinchend="onPinchEnd"
    v-hammer:pinchstart="onPinchStart"
    v-hammer:panstart="onPanStart"
    v-hammer:pan.all="onPanMove"
    v-hammer:panend="onPanEnd"
    v-hammer:singletap="onTap"
    v-hammer:doubletap="onDoubleTap"
    class="adr_fullcanvas" :id="this.canvasId" height="100%" ></canvas>
  </transition>
</div>
</template>

And in my component methods :

onTap(e) {
      console.log('onTap count: ' + e.tapCount)
    },
    onDoubleTap(e) {
      console.log('onDoubleTap count: ' + e.tapCount)
    },
vesper8 commented 6 years ago

having similar issue.. did you figure it out by any chance?

bsdfzzzy commented 6 years ago

Yes, for now, this is not supported. But I'll add it into next big version.

inspirity commented 5 years ago

missing double tap too...

lzx-cvte commented 2 years ago
// just like that
import { VueHammer } from 'vue2-hammer'
// ...
const doubleTap = { type: 'Tap', event: 'doubletap', taps: 2 };
VueHammer.customEvents = {
  'doubletap': doubleTap
}
Vue.use(VueHammer)

// Use
<div v-hammer:doubletap="onDoubleTap"></div>
bapman81 commented 2 years ago

Big thanks to @lzx-cvte, this should be part of the official doc!