Skip to content

Commit 414632d

Browse files
authored
Merge pull request #51 from yappbox/bug/click-capturing
PreventDefault on touch end event when scrolling
2 parents dc81799 + ad8fcae commit 414632d

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

addon/components/scroll-view.js

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -249,30 +249,21 @@ class ScrollView extends Component {
249249
this.scroller.doTouchMove(touches, timeStamp, scale)
250250
}
251251

252-
doTouchEnd(touches, timeStamp) {
253-
if (this.needsCaptureClick()) {
254-
this.setupCaptureClickTask.perform();
252+
doTouchEnd(touches, timeStamp, event) {
253+
let preventClick = this.needsPreventClick()
254+
255+
if (preventClick) {
256+
event.preventDefault();
255257
}
258+
256259
this.scroller.doTouchEnd(timeStamp);
257-
}
258260

259-
@task
260-
setupCaptureClickTask = function *() {
261-
try {
262-
let { scrollViewElement } = this;
263-
let captureClick = (e) => {
264-
e.stopPropagation(); // Stop the click from being propagated.
265-
scrollViewElement.removeEventListener('click', captureClick, true); // cleanup
266-
}
267-
scrollViewElement.addEventListener('click', captureClick, true);
268-
yield timeout(0);
269-
scrollViewElement.removeEventListener('click', captureClick, true);
270-
} finally {
261+
if (preventClick) {
271262
this._decelerationVelocityY = null;
272263
}
273264
}
274265

275-
needsCaptureClick() {
266+
needsPreventClick() {
276267
// There are two cases where we want to prevent the click that normally follows a mouseup/touchend.
277268
//
278269
// 1) when the user is just finishing a purposeful scroll (i.e. dragging scroll view beyond a threshold)

addon/utils/zynga-scroller-vertical-recognizer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default class ZyngaScrollerVerticalRecognizer extends Hammer.Pan {
4747
if (inputData.isFirst) {
4848
this.options.scrollComponent.doTouchStart(inputData.pointers, inputData.timeStamp);
4949
} else if (inputData.isFinal) {
50-
this.options.scrollComponent.doTouchEnd(inputData.pointers, inputData.timeStamp);
50+
this.options.scrollComponent.doTouchEnd(inputData.pointers, inputData.timeStamp, inputData.srcEvent);
5151
} else {
5252
this.options.scrollComponent.doTouchMove(inputData.pointers, inputData.timeStamp, inputData.scale);
5353
}

0 commit comments

Comments
 (0)