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.

32 lines
891 B

  1. import { supportsPassiveEvents } from 'detect-passive-events';
  2. import { forceSingleColumn } from 'mastodon/initial_state';
  3. const LAYOUT_BREAKPOINT = 630;
  4. export const isMobile = width => width <= LAYOUT_BREAKPOINT;
  5. export const layoutFromWindow = () => {
  6. if (isMobile(window.innerWidth)) {
  7. return 'mobile';
  8. } else if (forceSingleColumn) {
  9. return 'single-column';
  10. } else {
  11. return 'multi-column';
  12. }
  13. };
  14. const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
  15. let userTouching = false;
  16. let listenerOptions = supportsPassiveEvents ? { passive: true } : false;
  17. const touchListener = () => {
  18. userTouching = true;
  19. window.removeEventListener('touchstart', touchListener, listenerOptions);
  20. };
  21. window.addEventListener('touchstart', touchListener, listenerOptions);
  22. export const isUserTouching = () => userTouching;
  23. export const isIOS = () => iOS;