All files / src/carousel utils.js

100% Statements 26/26
100% Branches 31/31
100% Functions 2/2
100% Lines 23/23

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3718x 28x 28x   28x 28x 28x 28x 28x 13x   28x       9x   19x 9x   10x 6x 3x   3x     4x     18x 12x 8x 5x 1x    
export const getSwipeDirection = (touchObject, verticalSwiping = false) => {
  let xDist = 0;
  let yDist = 0;
  let swipeAngle;
  xDist = touchObject.startX - touchObject.endX;
  yDist = touchObject.startY - touchObject.endY;
  const r = Math.atan2(yDist, xDist);
  swipeAngle = Math.round((r * 180) / Math.PI);
  if (swipeAngle < 0) {
    swipeAngle = 360 - Math.abs(swipeAngle);
  }
  if (
    (swipeAngle <= 45 && swipeAngle >= 0)
    || (swipeAngle <= 360 && swipeAngle >= 315)
  ) {
    return 'left';
  }
  if (swipeAngle >= 135 && swipeAngle <= 225) {
    return 'right';
  }
  if (verticalSwiping === true) {
    if (swipeAngle > 45 && swipeAngle < 135) {
      return 'up';
    }
    return 'down';
  }
 
  return 'vertical';
};
 
export const keyHandler = (e, accessibility, rtl) => {
  if (e.target.tagName.match('TEXTAREA|INPUT|SELECT') || !accessibility) return '';
  if (e.keyCode === 37) return rtl ? 'next' : 'previous';
  if (e.keyCode === 39) return rtl ? 'previous' : 'next';
  return '';
};