fix(web): lecteurs CBZ/CBR et PDF — ancrer la page courante au passage en mode vertical une fois les pages rendues, sans saut au milieu (correctif complémentaire bug #39)
This commit is contained in:
@ -23,7 +23,8 @@ export function CbzReader({
|
||||
onControlsChange: (controls: ReaderControls) => void;
|
||||
}) {
|
||||
const frameRef = useRef<HTMLDivElement>(null);
|
||||
const previousModeRef = useRef<ReaderMode>(mode);
|
||||
const previousModeRef = useRef<ReaderMode | null>(null);
|
||||
const pendingVerticalAnchorRef = useRef(false);
|
||||
const [pages, setPages] = useState<CbzPagesDto | null>(null);
|
||||
const [documentError, setDocumentError] = useState<string>();
|
||||
const [pageError, setPageError] = useState<string>();
|
||||
@ -124,15 +125,23 @@ export function CbzReader({
|
||||
useEffect(() => {
|
||||
if (mode !== "vertical") {
|
||||
previousModeRef.current = mode;
|
||||
pendingVerticalAnchorRef.current = false;
|
||||
return;
|
||||
}
|
||||
if (previousModeRef.current !== "vertical") {
|
||||
if (previousModeRef.current !== "vertical") pendingVerticalAnchorRef.current = true;
|
||||
if (pendingVerticalAnchorRef.current) {
|
||||
const target = frameRef.current?.querySelector<HTMLElement>(`[data-reader-page="${currentPage}"]`);
|
||||
if (!target) {
|
||||
previousModeRef.current = mode;
|
||||
return;
|
||||
}
|
||||
pendingVerticalAnchorRef.current = false;
|
||||
requestAnimationFrame(() => {
|
||||
frameRef.current?.querySelector<HTMLElement>(`[data-reader-page="${currentPage}"]`)?.scrollIntoView({ block: "start" });
|
||||
target.scrollIntoView({ block: "start" });
|
||||
});
|
||||
}
|
||||
previousModeRef.current = mode;
|
||||
}, [currentPage, mode]);
|
||||
}, [currentPage, mode, pages]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mode !== "vertical" || !pages) return;
|
||||
|
||||
Reference in New Issue
Block a user