isFirst is never true. I have to create my own isFirst to make it work.
The same with me. The ev.isFinal flag triggers but the ev.isFirst never triggers. So far thought of a workaround to create a tap event where is set a flag variable to true and on ev.isFinal set the flag to false.
var gallery = document.getElementById('gallery');
var mc = new Hammer(gallery);
mc.get('pan').set({ direction: Hammer.DIRECTION_HORIZONTAL, threshold: 0});
mc.on('panleft panright', function(ev) {
if(ev.isFirst)
console.log('first');
if(ev.isFinal)
console.log('final');
});
EDIT
Found in issues a way of getting the first one, but it will trigger on every event on that element.
mc.on("hammer.input", function(ev) {
if(ev.isFirst) {
console.log('triggers first');
}
if(ev.eventType === Hammer.INPUT_START) {
console.log('also tirggers firstt');
}
});
So you know what? These are internal and probably shouldn't be used. what you want to do is
mc.on('panstart panend panleft panright', function(ev) ...
drag, pan and pinch all have these events. I just started using that and it works like a charm.
Oooo god, how didn't i see that there is "panstart panend".
Thanks for helping! :+1:
That kind of works, but you can't just subscribe to 'pan' and get the 'panstart', so they all have to be called out individually. It works, but isFirst would certainly be nice to have.
I would disagree. A simple switch statement could tell you what is going on. The whole idea here is to subscribe to multiple events and let your handler sort it out. Could you give an example of why you would need to subscribe to only one event per handler?
switch(event.type) {
case "panstart" :
// do pan start things
break;
default:
// do the rest..
break;
}
Yeah, the issue I was having is that if you init with pan, you never get panstart event types. Like this:
hammertime.on('pan panstart'...)
I just resolved this by doing a hammer.on('pan') and hammer.on('panstart')
I wonder if the order matters. but yeah that works too.
Why closed? The first problem about ev.isFirst remains unfixed…
I think because no one has posted a legitimate use case where ev.isFirst is needed over ev.type == 'panstart'
The need set apart, a useless variable is still hanging around there probably offending some perfectionists :). The issue is about the variable, not the use of it.
@pr1ntr If those variables shouldn't be used, maybe it would be a good idea to make a note of it in the docs or not mention them altogether.
(I just spent a good 20 minutes trying to debug some code that relied on isFirst, I can imagine other people going through that too.)
EDIT: Ooops, for some reason I thought you were one of the devs for this - will open a separate issue for this.
that is why i started this thread ;). You can submit a pull request for the docs? I don't know I am not the author.
Just to drive me a little nuttier -- I just noticed that isFirst===true on...... the panend event...
This must be a little bug somewhere where true is being set on the wrong thing.
Hit the same problem with pinch. event.isFirst never true ever.
Same problem here, event.isFirst is never true, event.isFinal is often false even at last event in the chain.
Please remove them from the docs/event, they are very misleading.
Hi guys,
Ran into same issue. Wheter it's used internally or not, if it doesn't work, what's the point ?
Either fix it or delete the var...
Ran into the same issue very confused why it was never triggered. Agree with @AdamSGit that if it doesn't work, remove it.
Personally I like the simplicity of having isFirst & isFinal in one tap event.
@sebmor frankly, the project just isn't being maintained.
isFirst does get called, even when just listening to the single pan event.
However I'm not seeing it get triggered a second time until the Y axis is moved. So it's as if it's saying isFirst time panning this object at all.
HOWEVER isFinal gets called every end. So it seems like a bug.
I'm using RxJS to get the events like this
const pan$ = fromEvent<HammerInput>(hammerPan, 'pan');
const panStart$ = fromEvent<HammerInput>(hammerPan, 'panstart');
const panEnd$ = pan$.pipe(filter((e) => e.isFinal);
I'm seeing bigger issues though when trying to use
Most helpful comment
Same problem here, event.isFirst is never true, event.isFinal is often false even at last event in the chain.
Please remove them from the docs/event, they are very misleading.