You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
776 B

  1. import detectPassiveEvents from 'detect-passive-events';
  2. const LAYOUT_BREAKPOINT = 630;
  3. export function isMobile(width, columns) {
  4. switch (columns) {
  5. case 'multiple':
  6. return false;
  7. case 'single':
  8. return true;
  9. default:
  10. return width <= LAYOUT_BREAKPOINT;
  11. }
  12. };
  13. const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
  14. let userTouching = false;
  15. let listenerOptions = detectPassiveEvents.hasSupport ? { passive: true } : false;
  16. function touchListener() {
  17. userTouching = true;
  18. window.removeEventListener('touchstart', touchListener, listenerOptions);
  19. }
  20. window.addEventListener('touchstart', touchListener, listenerOptions);
  21. export function isUserTouching() {
  22. return userTouching;
  23. }
  24. export function isIOS() {
  25. return iOS;
  26. };