|
@@ -1,5 +1,6 @@
|
|
import React, { useState, useEffect, useCallback } from 'react';
|
|
import React, { useState, useEffect, useCallback } from 'react';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
|
+import MobileDetect from 'mobile-detect';
|
|
|
|
|
|
import { ANNOTATION_TYPE } from '../constants';
|
|
import { ANNOTATION_TYPE } from '../constants';
|
|
import Icon from '../components/Icon';
|
|
import Icon from '../components/Icon';
|
|
@@ -28,7 +29,7 @@ type Props = {
|
|
};
|
|
};
|
|
|
|
|
|
const FreehandTool: React.FC<Props> = ({ title, isActive, onClick }: Props) => {
|
|
const FreehandTool: React.FC<Props> = ({ title, isActive, onClick }: Props) => {
|
|
- const [cursorPosition, setRef] = useCursorPosition(30);
|
|
|
|
|
|
+ const [cursorPosition, setRef] = useCursorPosition(20);
|
|
|
|
|
|
const [uuid, setUuid] = useState('');
|
|
const [uuid, setUuid] = useState('');
|
|
const [data, setData] = useState({
|
|
const [data, setData] = useState({
|
|
@@ -94,8 +95,8 @@ const FreehandTool: React.FC<Props> = ({ title, isActive, onClick }: Props) => {
|
|
const point = position[0][0];
|
|
const point = position[0][0];
|
|
annotations[index].obj_attr.position = [
|
|
annotations[index].obj_attr.position = [
|
|
[
|
|
[
|
|
- { x: point.x - 5, y: point.y - 5 },
|
|
|
|
- { x: point.x + 5, y: point.y + 5 },
|
|
|
|
|
|
+ { x: point.x - 3, y: point.y - 3 },
|
|
|
|
+ { x: point.x + 3, y: point.y + 3 },
|
|
],
|
|
],
|
|
];
|
|
];
|
|
annotations[index] = appendUserIdAndDate(annotations[index]);
|
|
annotations[index] = appendUserIdAndDate(annotations[index]);
|
|
@@ -140,19 +141,29 @@ const FreehandTool: React.FC<Props> = ({ title, isActive, onClick }: Props) => {
|
|
}, [annotations, cursorPosition, uuid]);
|
|
}, [annotations, cursorPosition, uuid]);
|
|
|
|
|
|
const subscribeEvent = (): void => {
|
|
const subscribeEvent = (): void => {
|
|
|
|
+ const md = new MobileDetect(window.navigator.userAgent);
|
|
const pdfViewer = document.getElementById('pdf_viewer') as HTMLDivElement;
|
|
const pdfViewer = document.getElementById('pdf_viewer') as HTMLDivElement;
|
|
- pdfViewer.addEventListener('mousedown', handleMouseDown);
|
|
|
|
- pdfViewer.addEventListener('mouseup', handleMouseUp);
|
|
|
|
- pdfViewer.addEventListener('touchstart', handleMouseDown);
|
|
|
|
- pdfViewer.addEventListener('touchend', handleMouseUp);
|
|
|
|
|
|
+
|
|
|
|
+ if (md.mobile() || md.tablet()) {
|
|
|
|
+ pdfViewer.addEventListener('touchstart', handleMouseDown);
|
|
|
|
+ pdfViewer.addEventListener('touchend', handleMouseUp);
|
|
|
|
+ } else {
|
|
|
|
+ pdfViewer.addEventListener('mousedown', handleMouseDown);
|
|
|
|
+ pdfViewer.addEventListener('mouseup', handleMouseUp);
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
const unsubscribeEvent = (): void => {
|
|
const unsubscribeEvent = (): void => {
|
|
|
|
+ const md = new MobileDetect(window.navigator.userAgent);
|
|
const pdfViewer = document.getElementById('pdf_viewer') as HTMLDivElement;
|
|
const pdfViewer = document.getElementById('pdf_viewer') as HTMLDivElement;
|
|
- pdfViewer.removeEventListener('mousedown', handleMouseDown);
|
|
|
|
- pdfViewer.removeEventListener('mouseup', handleMouseUp);
|
|
|
|
- pdfViewer.removeEventListener('touchstart', handleMouseDown);
|
|
|
|
- pdfViewer.removeEventListener('touchend', handleMouseUp);
|
|
|
|
|
|
+
|
|
|
|
+ if (md.mobile() || md.tablet()) {
|
|
|
|
+ pdfViewer.removeEventListener('touchstart', handleMouseDown);
|
|
|
|
+ pdfViewer.removeEventListener('touchend', handleMouseUp);
|
|
|
|
+ } else {
|
|
|
|
+ pdfViewer.removeEventListener('mousedown', handleMouseDown);
|
|
|
|
+ pdfViewer.removeEventListener('mouseup', handleMouseUp);
|
|
|
|
+ }
|
|
};
|
|
};
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|