Skip to content

Commit

Permalink
Move isTouchDevice constant to utils
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwep committed Mar 19, 2021
1 parent 77915eb commit 2df8145
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
11 changes: 3 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {css, eventPath, intersects, off, on, removeElement, selectAll, SelectAllSelectors, simplifyEvent} from '@utils';
import {css, eventPath, intersects, isTouchDevice, off, on, removeElement, selectAll, SelectAllSelectors, simplifyEvent} from '@utils';
import {EventTarget} from './EventEmitter';
import {AreaLocation, Coordinates, ScrollEvent, SelectionEvents, SelectionOptions, SelectionStore} from './types';

Expand All @@ -8,11 +8,6 @@ export * from './types';
// Some var shorting for better compression and readability
const {abs, max, min, ceil} = Math;

// Likely want to move this to utils
// Determines if the device's primary input supports touch
// See this article: https://css-tricks.com/touch-devices-not-judged-size/
const isTouchEnabled = window.matchMedia('(hover: none), (pointer: coarse)').matches;

export default class SelectionArea extends EventTarget<SelectionEvents> {
public static version = VERSION;

Expand Down Expand Up @@ -294,7 +289,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
this._onTapMove(evt);
}

if (allowTouch && isTouchEnabled) {
if (allowTouch && isTouchDevice) {
evt.preventDefault(); // Prevent swipe-down refresh
}
}
Expand Down Expand Up @@ -407,7 +402,7 @@ export default class SelectionArea extends EventTarget<SelectionEvents> {
this._redrawSelectionArea();
}

if (allowTouch && isTouchEnabled) {
if (allowTouch && isTouchDevice) {
evt.preventDefault(); // Prevent swipe-down refresh
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Determines if the device's primary input supports touch
// See this article: https://css-tricks.com/touch-devices-not-judged-size/
export const isTouchDevice = window.matchMedia('(hover: none), (pointer: coarse)').matches;
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './events';
export * from './intersects';
export * from './removeElement';
export * from './selectAll';
export * from './constants';

0 comments on commit 2df8145

Please sign in to comment.