|
@@ -1,7 +1,6 @@
|
|
|
import { useState, useRef, useCallback, useEffect } from 'react';
|
|
|
import { fromEvent, Subscription } from 'rxjs';
|
|
|
import { throttleTime } from 'rxjs/operators';
|
|
|
-import MobileDetect from 'mobile-detect';
|
|
|
|
|
|
import { getAbsoluteCoordinate } from '../helpers/position';
|
|
|
|
|
@@ -84,8 +83,6 @@ const useCursorPosition: UseCursorPositionType = (time = defaultTime) => {
|
|
|
);
|
|
|
|
|
|
useEffect(() => {
|
|
|
- const md = new MobileDetect(window.navigator.userAgent);
|
|
|
-
|
|
|
let mouseSubscription: Subscription | null = null;
|
|
|
let touchSubscription: Subscription | null = null;
|
|
|
|
|
@@ -121,38 +118,33 @@ const useCursorPosition: UseCursorPositionType = (time = defaultTime) => {
|
|
|
if (element) {
|
|
|
const addEvent = element.addEventListener.bind(element);
|
|
|
|
|
|
- if (md.mobile() || md.tablet()) {
|
|
|
- touchSubscription = fromEvent(element, 'touchmove')
|
|
|
- .pipe(throttleTime(time))
|
|
|
- .subscribe(onTouchMoveEvent);
|
|
|
-
|
|
|
- addEvent('touchstart', onTouch);
|
|
|
- addEvent('touchend', onUp);
|
|
|
- } else {
|
|
|
- mouseSubscription = fromEvent(element, 'mousemove')
|
|
|
- .pipe(throttleTime(time))
|
|
|
- .subscribe(onMouseMoveEvent);
|
|
|
-
|
|
|
- addEvent('mouseenter', onEnter);
|
|
|
- addEvent('mouseleave', onLeave);
|
|
|
- addEvent('mousedown', onDown);
|
|
|
- addEvent('mouseup', onUp);
|
|
|
- }
|
|
|
+ touchSubscription = fromEvent(element, 'touchmove')
|
|
|
+ .pipe(throttleTime(time))
|
|
|
+ .subscribe(onTouchMoveEvent);
|
|
|
+
|
|
|
+ addEvent('touchstart', onTouch);
|
|
|
+ addEvent('touchend', onUp);
|
|
|
+
|
|
|
+ mouseSubscription = fromEvent(element, 'mousemove')
|
|
|
+ .pipe(throttleTime(time))
|
|
|
+ .subscribe(onMouseMoveEvent);
|
|
|
+
|
|
|
+ addEvent('mouseenter', onEnter);
|
|
|
+ addEvent('mouseleave', onLeave);
|
|
|
+ addEvent('mousedown', onDown);
|
|
|
+ addEvent('mouseup', onUp);
|
|
|
}
|
|
|
|
|
|
return (): void => {
|
|
|
if (element) {
|
|
|
const removeEvent = element.removeEventListener.bind(element);
|
|
|
|
|
|
- if (md.mobile() || md.tablet()) {
|
|
|
- removeEvent('touchstart', onTouch);
|
|
|
- removeEvent('touchend', onUp);
|
|
|
- } else {
|
|
|
- removeEvent('mouseenter', onEnter);
|
|
|
- removeEvent('mouseleave', onLeave);
|
|
|
- removeEvent('mousedown', onDown);
|
|
|
- removeEvent('mouseup', onUp);
|
|
|
- }
|
|
|
+ removeEvent('touchstart', onTouch);
|
|
|
+ removeEvent('touchend', onUp);
|
|
|
+ removeEvent('mouseenter', onEnter);
|
|
|
+ removeEvent('mouseleave', onLeave);
|
|
|
+ removeEvent('mousedown', onDown);
|
|
|
+ removeEvent('mouseup', onUp);
|
|
|
}
|
|
|
};
|
|
|
}, [element]);
|