Skip to content

Commit

Permalink
Merge pull request #4962 from Polymer/passive-touch-no-touchend
Browse files Browse the repository at this point in the history
Do not set touchend listeners to passive
  • Loading branch information
dfreedm authored Dec 4, 2017
2 parents 1fbb504 + c5407a8 commit b311a77
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lib/utils/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@
/**
* Generate settings for event listeners, dependant on `Polymer.passiveTouchGestures`
*
* @param {string} eventName Event name to determine if `{passive}` option is needed
* @return {{passive: boolean} | undefined} Options to use for addEventListener and removeEventListener
*/
function PASSIVE_TOUCH() {
function PASSIVE_TOUCH(eventName) {
if (isMouseEvent(eventName) || eventName === 'touchend') {
return;
}
if (HAS_NATIVE_TA && SUPPORTS_PASSIVE && Polymer.passiveTouchGestures) {
return {passive: true};
} else {
Expand Down Expand Up @@ -485,8 +489,7 @@
gobj[dep] = gd = {_count: 0};
}
if (gd._count === 0) {
let options = !isMouseEvent(dep) && PASSIVE_TOUCH();
node.addEventListener(dep, this._handleNative, options);
node.addEventListener(dep, this._handleNative, PASSIVE_TOUCH(dep));
}
gd[name] = (gd[name] || 0) + 1;
gd._count = (gd._count || 0) + 1;
Expand Down Expand Up @@ -520,8 +523,7 @@
gd[name] = (gd[name] || 1) - 1;
gd._count = (gd._count || 1) - 1;
if (gd._count === 0) {
let options = !isMouseEvent(dep) && PASSIVE_TOUCH();
node.removeEventListener(dep, this._handleNative, options);
node.removeEventListener(dep, this._handleNative, PASSIVE_TOUCH(dep));
}
}
}
Expand Down
10 changes: 8 additions & 2 deletions test/smoke/passive-gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@
is: 'x-passive',
listeners: {
'down': 'prevent',
'move': 'prevent'
'move': 'prevent',
'up': 'prevent',
'tap': 'allowed',
'click': 'allowed'
},
prevent(e) {
e.preventDefault();
console.log('prevented!');
console.log('prevented?: ' + e.type + ' ' + e.defaultPrevented);
},
allowed(e) {
console.log(e.type + ' allowed');
}
});
</script>
Expand Down

0 comments on commit b311a77

Please sign in to comment.