Wait for initial page to be rendered before scrolling it into view (#696)

The ResizeObserver triggers the first time when the element has a height of 0, which apparently did not work with scrolling it into view.

Due to immediately disconnecting the observer, the next resize event, which would successfully scroll the page into view, was never handled

Regression introduced with 0c1abebaf4
This commit is contained in:
schroda
2024-04-01 13:17:50 +02:00
committed by GitHub
parent c4139b5d51
commit b1ce977dcd
2 changed files with 8 additions and 0 deletions

View File

@@ -114,6 +114,10 @@ export function HorizontalPager(props: IReaderProps) {
}
const resizeObserver = new ResizeObserver(() => {
if (!initialPageElement.offsetHeight) {
return;
}
initialPageElement.scrollIntoView({ inline: 'center' });
resizeObserver.disconnect();
});

View File

@@ -172,6 +172,10 @@ export function VerticalPager(props: IReaderProps) {
}
const resizeObserver = new ResizeObserver(() => {
if (!initialPageElement.offsetHeight) {
return;
}
initialPageElement.scrollIntoView();
resizeObserver.disconnect();
});