|
@@ -3,20 +3,35 @@ import _ from 'lodash';
|
|
|
|
|
|
import Viewer from '../components/Viewer';
|
|
|
import PdfPage from './PdfPage';
|
|
|
-import { watchScroll } from '../helpers/utility';
|
|
|
+import { watchScroll, scaleCheck } from '../helpers/utility';
|
|
|
+import useGestureScale from '../hooks/useGestureScale';
|
|
|
|
|
|
+import useActions from '../actions';
|
|
|
import useStore from '../store';
|
|
|
|
|
|
type Props = {
|
|
|
scrollToUpdate: (state: ScrollStateType) => void;
|
|
|
};
|
|
|
|
|
|
+let timer = 0;
|
|
|
+
|
|
|
const PdfPages: React.FC<Props> = ({ scrollToUpdate }: Props) => {
|
|
|
const [elements, setElement] = useState<React.ReactNode[]>([]);
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
const [
|
|
|
- { totalPage, currentPage, viewport, rotation, displayMode, annotations },
|
|
|
+ {
|
|
|
+ totalPage,
|
|
|
+ currentPage,
|
|
|
+ scale,
|
|
|
+ viewport,
|
|
|
+ rotation,
|
|
|
+ displayMode,
|
|
|
+ annotations,
|
|
|
+ },
|
|
|
+ dispatch,
|
|
|
] = useStore();
|
|
|
+ const { changeScale } = useActions(dispatch);
|
|
|
+ const [zoom] = useGestureScale(containerRef);
|
|
|
|
|
|
const createPages = (): void => {
|
|
|
const pagesContent: React.ReactNode[] = [];
|
|
@@ -76,6 +91,20 @@ const PdfPages: React.FC<Props> = ({ scrollToUpdate }: Props) => {
|
|
|
updatePages();
|
|
|
}, [currentPage, viewport, rotation, annotations]);
|
|
|
|
|
|
+ useEffect(() => {
|
|
|
+ if (zoom !== 0) {
|
|
|
+ const viewer = containerRef.current as HTMLElement;
|
|
|
+ viewer.style.transform = `scale(${1 + zoom})`;
|
|
|
+ clearTimeout(timer);
|
|
|
+
|
|
|
+ timer = setTimeout(() => {
|
|
|
+ const targetScale = Math.round(scale * 100 + zoom * 100);
|
|
|
+ changeScale(scaleCheck(targetScale));
|
|
|
+ viewer.style.transform = `scale(1)`;
|
|
|
+ }, 500);
|
|
|
+ }
|
|
|
+ }, [zoom]);
|
|
|
+
|
|
|
return (
|
|
|
<Viewer
|
|
|
ref={containerRef}
|