Skip to content

Commit

Permalink
Fix: Don't swallow touch start event to prevent iOS inertia scrolling (
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy Press authored Jul 19, 2017
1 parent 2a236fe commit d628c14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/lib/viewers/doc/PresentationViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class PresentationViewer extends DocBaseViewer {
this.docEl.addEventListener('wheel', this.wheelHandler());
if (this.hasTouch) {
this.docEl.addEventListener('touchstart', this.mobileScrollHandler);
this.docEl.addEventListener('touchmove', this.mobileScrollHandler);
this.docEl.addEventListener('touchend', this.mobileScrollHandler);
}
}
Expand All @@ -174,6 +175,7 @@ class PresentationViewer extends DocBaseViewer {
this.docEl.removeEventListener('wheel', this.wheelHandler());
if (this.hasTouch) {
this.docEl.removeEventListener('touchstart', this.mobileScrollHandler);
this.docEl.removeEventListener('touchmove', this.mobileScrollHandler);
this.docEl.removeEventListener('touchend', this.mobileScrollHandler);
}
}
Expand Down Expand Up @@ -228,10 +230,10 @@ class PresentationViewer extends DocBaseViewer {
return;
}

event.preventDefault();

if (event.type === 'touchstart') {
this.scrollStart = event.changedTouches[0].clientY;
} else if (event.type === 'touchmove') {
event.preventDefault();
} else {
const scrollEnd = event.changedTouches[0].clientY;

Expand Down
9 changes: 9 additions & 0 deletions src/lib/viewers/doc/__tests__/PresentationViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ describe('lib/viewers/doc/PresentationViewer', () => {

presentation.bindDOMListeners();
expect(stubs.addEventListener).to.be.calledWith('touchstart', presentation.mobileScrollHandler);
expect(stubs.addEventListener).to.be.calledWith('touchmove', presentation.mobileScrollHandler);
expect(stubs.addEventListener).to.be.calledWith('touchend', presentation.mobileScrollHandler);
});
});
Expand All @@ -292,6 +293,7 @@ describe('lib/viewers/doc/PresentationViewer', () => {

presentation.unbindDOMListeners();
expect(stubs.removeEventListener).to.be.calledWith('touchstart', presentation.mobileScrollHandler);
expect(stubs.removeEventListener).to.be.calledWith('touchmove', presentation.mobileScrollHandler);
expect(stubs.removeEventListener).to.be.calledWith('touchend', presentation.mobileScrollHandler);
});
});
Expand Down Expand Up @@ -374,6 +376,13 @@ describe('lib/viewers/doc/PresentationViewer', () => {

presentation.mobileScrollHandler(stubs.event);
expect(presentation.scrollStart).to.equal(100);
});

it('should prevent default behaviour if the event is touchmove', () => {
stubs.event.type = 'touchmove';
stubs.event.changedTouches[0].clientY = 100;

presentation.mobileScrollHandler(stubs.event);
expect(stubs.event.preventDefault).to.be.called;
});

Expand Down

0 comments on commit d628c14

Please sign in to comment.