merge: fix/39-reader-vertical-scroll-position dans develop (défilement vertical — ancrage de restauration recalculé sur la plage de défilement réelle, plus d'ouverture au milieu du livre)
This commit is contained in:
@ -162,7 +162,7 @@ export function ReaderPage({ bookId }: { bookId: number }) {
|
|||||||
const changeZoom = useCallback((nextZoom: number | ((currentZoom: number) => number)) => {
|
const changeZoom = useCallback((nextZoom: number | ((currentZoom: number) => number)) => {
|
||||||
const stage = document.querySelector(".reader-stage") as HTMLElement | null;
|
const stage = document.querySelector(".reader-stage") as HTMLElement | null;
|
||||||
const scrollRatioX = stage && stage.scrollWidth > stage.clientWidth ? (stage.scrollLeft + stage.clientWidth / 2) / stage.scrollWidth : 0.5;
|
const scrollRatioX = stage && stage.scrollWidth > stage.clientWidth ? (stage.scrollLeft + stage.clientWidth / 2) / stage.scrollWidth : 0.5;
|
||||||
const scrollRatioY = stage && stage.scrollHeight > stage.clientHeight ? (stage.scrollTop + stage.clientHeight / 2) / stage.scrollHeight : 0.5;
|
const scrollRatioY = stage && stage.scrollHeight > stage.clientHeight ? stage.scrollTop / (stage.scrollHeight - stage.clientHeight) : 0;
|
||||||
|
|
||||||
setZoom((currentZoom) => clampReaderZoom(typeof nextZoom === "function" ? nextZoom(currentZoom) : nextZoom));
|
setZoom((currentZoom) => clampReaderZoom(typeof nextZoom === "function" ? nextZoom(currentZoom) : nextZoom));
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ export function ReaderPage({ bookId }: { bookId: number }) {
|
|||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
if (!stage) return;
|
if (!stage) return;
|
||||||
stage.scrollLeft = Math.max(0, stage.scrollWidth * scrollRatioX - stage.clientWidth / 2);
|
stage.scrollLeft = Math.max(0, stage.scrollWidth * scrollRatioX - stage.clientWidth / 2);
|
||||||
stage.scrollTop = Math.max(0, stage.scrollHeight * scrollRatioY - stage.clientHeight / 2);
|
stage.scrollTop = Math.max(0, (stage.scrollHeight - stage.clientHeight) * scrollRatioY);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|||||||
@ -8,4 +8,12 @@ describe("ReaderPage vertical restore", () => {
|
|||||||
|
|
||||||
expect(bookResetEffect).toContain("setPage(1)");
|
expect(bookResetEffect).toContain("setPage(1)");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does not restore an unknown vertical scroll anchor to the middle of the book", () => {
|
||||||
|
const source = readFileSync(new URL("./ReaderPage.tsx", import.meta.url), "utf8");
|
||||||
|
const changeZoomBlock = source.slice(source.indexOf("const changeZoom = useCallback"), source.indexOf(" const zoomControls", source.indexOf("const changeZoom = useCallback")));
|
||||||
|
|
||||||
|
expect(changeZoomBlock).toContain("scrollRatioY");
|
||||||
|
expect(changeZoomBlock).not.toMatch(/scrollRatioY[\s\S]*:\s*0\.5/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user