From ea1cd06776e757b7dffce690a32d25edede2bedd Mon Sep 17 00:00:00 2001 From: bd <331677620@qq.com> Date: Wed, 22 May 2024 17:00:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BC=A9=E5=B0=8F=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=A1=B5=E7=A0=81=E7=9A=84=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/calm-clocks-rush.md | 5 +++++ packages/pdf-viewer/src/PDFViewer.tsx | 4 +++- .../src/ZoomAndPageController/ZoomAndPageController.tsx | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/calm-clocks-rush.md diff --git a/.changeset/calm-clocks-rush.md b/.changeset/calm-clocks-rush.md new file mode 100644 index 00000000..0bb00303 --- /dev/null +++ b/.changeset/calm-clocks-rush.md @@ -0,0 +1,5 @@ +--- +'@orca-fe/pdf-viewer': patch +--- + +fix: 缩小时,调整页码的位置不对的 bug diff --git a/packages/pdf-viewer/src/PDFViewer.tsx b/packages/pdf-viewer/src/PDFViewer.tsx index b00997c3..eba81545 100644 --- a/packages/pdf-viewer/src/PDFViewer.tsx +++ b/packages/pdf-viewer/src/PDFViewer.tsx @@ -283,8 +283,10 @@ const PDFViewer = React.forwardRef((props, pRef const dom = pageContainerRef.current; if (dom) { const top = pageTopArr[page]; + const height = viewports[page]?.height * scale * PixelsPerInch.PDF_TO_CSS_UNITS; + const containerHeight = dom.getBoundingClientRect().height; dom.scrollTo({ - top, + top: Math.min(top, top + 0.5 * (height - containerHeight)), behavior: anim ? 'smooth' : 'auto', }); } diff --git a/packages/pdf-viewer/src/ZoomAndPageController/ZoomAndPageController.tsx b/packages/pdf-viewer/src/ZoomAndPageController/ZoomAndPageController.tsx index 0cc9b51c..9b1c5b87 100644 --- a/packages/pdf-viewer/src/ZoomAndPageController/ZoomAndPageController.tsx +++ b/packages/pdf-viewer/src/ZoomAndPageController/ZoomAndPageController.tsx @@ -39,8 +39,9 @@ const ZoomAndPageController = (props: ZoomAndPageControllerProps) => { } }} onChange={(value) => { - if (!Number.isNaN(Number(value) - 1)) { - pdfViewer.changePage(Number(value) - 1); + const newPage = Number(value) - 1; + if (!Number.isNaN(newPage) && pdfViewer.getCurrentPage() !== newPage) { + pdfViewer.changePage(newPage); } }} />