Fix TypeError when reaching scroll end in continuous pager
When the end of the scrollable element is reached in the continuous reader, the last image is not visible anymore. Thus, the "firstVisibleImageIndex" is invalid and gets incorrectly used for the "isEndReached" case which results in an TypeError when trying to use the actual page via the index
This commit is contained in:
@@ -465,15 +465,17 @@ export class ReaderControls {
|
||||
const lastPage = imageRefs.current?.[imageRefs.current.length - 1];
|
||||
const isEndReached = lastPage && isEndOfPageInViewport(lastPage, type, readingDirection);
|
||||
|
||||
if (firstVisibleImageIndex === -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// handle cases where the last page is too small to ever be the "firstVisibleImageIndex"
|
||||
if (isEndReached) {
|
||||
updateCurrentPageIndex(firstVisibleImageIndex, false, true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (firstVisibleImageIndex !== -1) {
|
||||
updateCurrentPageIndex(firstVisibleImageIndex, firstVisibleImageIndex !== lastPageIndex);
|
||||
}
|
||||
updateCurrentPageIndex(firstVisibleImageIndex, firstVisibleImageIndex !== lastPageIndex);
|
||||
}
|
||||
|
||||
static useHandleClick(
|
||||
|
||||
Reference in New Issue
Block a user