Skip to content

Commit

Permalink
fix: disable scroll on carousel swipe
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-brainhub committed May 8, 2018
1 parent 759c96a commit 6a1505b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/components/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export default class Carousel extends Component {
if (this.node) {
this.node.ownerDocument.addEventListener('mousemove', this.onMouseMove, true);
this.node.ownerDocument.addEventListener('mouseup', this.onMouseUpTouchEnd, true);
this.node.ownerDocument.addEventListener('touchstart', this.onTouchStart, { passive: false });
this.node.ownerDocument.addEventListener('touchmove', this.onTouchMove, true);
this.node.ownerDocument.addEventListener('touchstart', this.onTouchStart, true);
this.node.ownerDocument.addEventListener('touchmove', this.onTouchMove, { passive: false });
this.node.ownerDocument.addEventListener('touchend', this.onMouseUpTouchEnd, true);
}

Expand Down Expand Up @@ -313,10 +313,6 @@ export default class Carousel extends Component {
* @param {number} index of the element drag started on
*/
onTouchStart = (e, index) => {
if (this.state.dragStart) {
e.preventDefault();
e.stopPropagation();
}
this.setState({
clicked: index,
dragStart: e.changedTouches[0].pageX,
Expand All @@ -328,6 +324,10 @@ export default class Carousel extends Component {
* @param {event} e event
*/
onTouchMove = e => {
if (Math.abs(this.state.dragOffset) > 10) {
e.preventDefault();
e.stopPropagation();
}
if (this.state.dragStart !== null) {
this.setState({
dragOffset: e.changedTouches[0].pageX - this.state.dragStart,
Expand Down

0 comments on commit 6a1505b

Please sign in to comment.