Skip to content

Commit

Permalink
Move recognizer reset into start of event flow
Browse files Browse the repository at this point in the history
Add "event flow" metadata to each recognizer, list of start/end events
Normalize state reset function names

flow.start is an array, not an object

Make sure to reset state in a seperate loop

Otherwise prevent on 'down' breaks
  • Loading branch information
dfreedm committed Jul 20, 2015
1 parent 8134fbf commit a7495f7
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/standard/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@
return;
}
var recognizers = Gestures.recognizers;
// reset recognizer state
for (var i = 0, r; i < recognizers.length; i++) {
r = recognizers[i];
if (gs[r.name] && !handled[r.name]) {
if (r.flow && r.flow.start.indexOf(ev.type) > -1) {
if (r.reset) {
r.reset();
}
}
}
}
// enforce gesture recognizer order
for (var i = 0, r; i < recognizers.length; i++) {
r = recognizers[i];
Expand Down Expand Up @@ -356,6 +367,10 @@
name: 'track',
touchAction: 'none',
deps: ['mousedown', 'touchstart', 'touchmove', 'touchend'],
flow: {
start: ['mousedown', 'touchstart'],
end: ['mouseup', 'touchend']
},
emits: ['track'],

info: {
Expand All @@ -373,7 +388,7 @@
prevent: false
},

clearInfo: function() {
reset: function() {
this.info.state = 'start';
this.info.started = false;
this.info.moves = [];
Expand Down Expand Up @@ -412,7 +427,6 @@
Gestures.prevent('tap');
movefn(e);
}
self.clearInfo();
// remove the temporary listeners
document.removeEventListener('mousemove', movefn);
document.removeEventListener('mouseup', upfn);
Expand Down Expand Up @@ -454,7 +468,6 @@
this.info.addMove({x: ct.clientX, y: ct.clientY});
this.fire(t, ct);
}
this.clearInfo();
},

fire: function(target, touch) {
Expand Down Expand Up @@ -487,6 +500,10 @@
Gestures.register({
name: 'tap',
deps: ['mousedown', 'click', 'touchstart', 'touchend'],
flow: {
start: ['mousedown', 'touchstart'],
end: ['click', 'touchend']
},
emits: ['tap'],
info: {
x: NaN,
Expand Down Expand Up @@ -532,7 +549,6 @@
});
}
}
this.reset();
}
});

Expand Down

0 comments on commit a7495f7

Please sign in to comment.