Improve image preloading of previous/next chapter pages
The previous/next chapter only ever preloaded the first page, ignoring available preload contingent. I.e., if all leading/trailing pages of the current chapter were loaded, the reader did not keep preloading the previous/next chapters pages
This commit is contained in:
@@ -31,6 +31,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|||||||
- (**Source/Extension**) Rename language "All" to "Multi"
|
- (**Source/Extension**) Rename language "All" to "Multi"
|
||||||
- (**Reader**) Simplify changing settings in desktop sidebar
|
- (**Reader**) Simplify changing settings in desktop sidebar
|
||||||
- (**Reader**) Ignore tap zone clicks while window does not have focus
|
- (**Reader**) Ignore tap zone clicks while window does not have focus
|
||||||
|
- (**Reader**) Improve preloading pages from the previous/next chapter
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -363,6 +363,7 @@ export interface ReaderPagerProps
|
|||||||
resumeMode: ReaderResumeMode;
|
resumeMode: ReaderResumeMode;
|
||||||
handleAsInitialRender: boolean;
|
handleAsInitialRender: boolean;
|
||||||
ref?: Ref<HTMLDivElement>;
|
ref?: Ref<HTMLDivElement>;
|
||||||
|
currentChapterRemainingPages: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum PageInViewportType {
|
export enum PageInViewportType {
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ const BaseReaderChapterViewer = ({
|
|||||||
minWidth,
|
minWidth,
|
||||||
minHeight,
|
minHeight,
|
||||||
scrollElement,
|
scrollElement,
|
||||||
|
currentChapterRemainingPages,
|
||||||
}: Pick<ReaderStatePages, 'currentPageIndex' | 'transitionPageMode' | 'retryFailedPagesKeyPrefix'> &
|
}: Pick<ReaderStatePages, 'currentPageIndex' | 'transitionPageMode' | 'retryFailedPagesKeyPrefix'> &
|
||||||
Omit<ReaderPagerProps, 'pages' | 'totalPages' | 'pageLoadStates' | 'handleAsInitialRender' | 'resumeMode'> &
|
Omit<ReaderPagerProps, 'pages' | 'totalPages' | 'pageLoadStates' | 'handleAsInitialRender' | 'resumeMode'> &
|
||||||
Pick<
|
Pick<
|
||||||
@@ -433,6 +434,7 @@ const BaseReaderChapterViewer = ({
|
|||||||
isPreloadMode={isPreloadMode}
|
isPreloadMode={isPreloadMode}
|
||||||
resumeMode={resumeMode}
|
resumeMode={resumeMode}
|
||||||
handleAsInitialRender={scrollIntoView}
|
handleAsInitialRender={scrollIntoView}
|
||||||
|
currentChapterRemainingPages={currentChapterRemainingPages}
|
||||||
/>
|
/>
|
||||||
{showNextTransitionPage && (
|
{showNextTransitionPage && (
|
||||||
<ReaderTransitionPage chapterId={chapterId} type={ReaderTransitionPageMode.NEXT} />
|
<ReaderTransitionPage chapterId={chapterId} type={ReaderTransitionPageMode.NEXT} />
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ import {
|
|||||||
useReaderSettingsStore,
|
useReaderSettingsStore,
|
||||||
} from '@/features/reader/stores/ReaderStore.ts';
|
} from '@/features/reader/stores/ReaderStore.ts';
|
||||||
import { STABLE_EMPTY_OBJECT } from '@/base/Base.constants.ts';
|
import { STABLE_EMPTY_OBJECT } from '@/base/Base.constants.ts';
|
||||||
|
import { getPage } from '@/features/reader/overlay/progress-bar/ReaderProgressBar.utils.tsx';
|
||||||
|
|
||||||
const READING_MODE_TO_IN_VIEWPORT_TYPE: Record<ReadingMode, PageInViewportType> = {
|
const READING_MODE_TO_IN_VIEWPORT_TYPE: Record<ReadingMode, PageInViewportType> = {
|
||||||
[ReadingMode.SINGLE_PAGE]: PageInViewportType.X,
|
[ReadingMode.SINGLE_PAGE]: PageInViewportType.X,
|
||||||
@@ -290,10 +291,13 @@ const BaseReaderViewer = ({
|
|||||||
const isCurrentChapter = chapter.id === currentChapter.id;
|
const isCurrentChapter = chapter.id === currentChapter.id;
|
||||||
const isPreviousChapter = chapter.id === chaptersToRender[currentChapterIndex + 1]?.id;
|
const isPreviousChapter = chapter.id === chaptersToRender[currentChapterIndex + 1]?.id;
|
||||||
const isNextChapter = chapter.id === chaptersToRender[currentChapterIndex - 1]?.id;
|
const isNextChapter = chapter.id === chaptersToRender[currentChapterIndex - 1]?.id;
|
||||||
|
const isAdjacentChapterToCurrentChapter = isPreviousChapter || isNextChapter;
|
||||||
|
|
||||||
const isLeadingChapter = initialChapter.sourceOrder > chapter.sourceOrder;
|
const isLeadingChapter = initialChapter.sourceOrder > chapter.sourceOrder;
|
||||||
const isTrailingChapter = initialChapter.sourceOrder < chapter.sourceOrder;
|
const isTrailingChapter = initialChapter.sourceOrder < chapter.sourceOrder;
|
||||||
const isLastLeadingChapter = visibleChapters.lastLeadingChapterSourceOrder === chapter.sourceOrder;
|
const isLastLeadingChapter = visibleChapters.lastLeadingChapterSourceOrder === chapter.sourceOrder;
|
||||||
const isLastTrailingChapter = visibleChapters.lastTrailingChapterSourceOrder === chapter.sourceOrder;
|
const isLastTrailingChapter = visibleChapters.lastTrailingChapterSourceOrder === chapter.sourceOrder;
|
||||||
|
|
||||||
const isPreloadMode =
|
const isPreloadMode =
|
||||||
(isLastLeadingChapter && visibleChapters.isLeadingChapterPreloadMode) ||
|
(isLastLeadingChapter && visibleChapters.isLeadingChapterPreloadMode) ||
|
||||||
(isLastTrailingChapter && visibleChapters.isTrailingChapterPreloadMode);
|
(isLastTrailingChapter && visibleChapters.isTrailingChapterPreloadMode);
|
||||||
@@ -306,6 +310,29 @@ const BaseReaderViewer = ({
|
|||||||
|
|
||||||
const isChapterSizeSourceChapter = chapter.id === minChapterSizeSourceChapterId;
|
const isChapterSizeSourceChapter = chapter.id === minChapterSizeSourceChapterId;
|
||||||
|
|
||||||
|
const currentChapterCurrentPageIndex = isAdjacentChapterToCurrentChapter
|
||||||
|
? getReaderChapterViewerCurrentPageIndex(
|
||||||
|
currentPageIndex,
|
||||||
|
currentChapter,
|
||||||
|
currentChapter,
|
||||||
|
true,
|
||||||
|
isCurrentChapterReady,
|
||||||
|
initialChapter.sourceOrder > currentChapter.sourceOrder,
|
||||||
|
initialChapter.sourceOrder < currentChapter.sourceOrder,
|
||||||
|
visibleChapters,
|
||||||
|
)
|
||||||
|
: -1;
|
||||||
|
const currentChapterCurrentPagesIndex = isAdjacentChapterToCurrentChapter
|
||||||
|
? getPage(currentChapterCurrentPageIndex, pages).pagesIndex
|
||||||
|
: -1;
|
||||||
|
|
||||||
|
const currentChapterRemainingLeadingPages = currentChapterCurrentPagesIndex;
|
||||||
|
const currentChapterRemainingTrailingPages = pages.length - 1 - currentChapterCurrentPagesIndex;
|
||||||
|
|
||||||
|
const currentChapterRemainingPages = isNextChapter
|
||||||
|
? currentChapterRemainingTrailingPages
|
||||||
|
: currentChapterRemainingLeadingPages;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ReaderChapterViewer
|
<ReaderChapterViewer
|
||||||
key={chapter.id}
|
key={chapter.id}
|
||||||
@@ -315,6 +342,7 @@ const BaseReaderViewer = ({
|
|||||||
isPreviousChapterVisible={previousNextChapterVisibility.previous}
|
isPreviousChapterVisible={previousNextChapterVisibility.previous}
|
||||||
isNextChapterVisible={previousNextChapterVisibility.next}
|
isNextChapterVisible={previousNextChapterVisibility.next}
|
||||||
lastPageRead={coerceIn(chapter.lastPageRead, 0, chapter.pageCount - 1)}
|
lastPageRead={coerceIn(chapter.lastPageRead, 0, chapter.pageCount - 1)}
|
||||||
|
currentChapterRemainingPages={currentChapterRemainingPages}
|
||||||
currentPageIndex={getReaderChapterViewerCurrentPageIndex(
|
currentPageIndex={getReaderChapterViewerCurrentPageIndex(
|
||||||
currentPageIndex,
|
currentPageIndex,
|
||||||
chapter,
|
chapter,
|
||||||
|
|||||||
@@ -533,12 +533,12 @@ export const isSpreadPage = (image: HTMLImageElement): boolean => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const MIN_PREVIOUS_NEXT_CHAPTER_IMAGE_LOAD_AMOUNT = 0;
|
const MIN_PREVIOUS_NEXT_CHAPTER_IMAGE_LOAD_AMOUNT = 0;
|
||||||
const MAX_PREVIOUS_NEXT_CHAPTER_IMAGE_LOAD_AMOUNT = 1;
|
|
||||||
const getImagePreLoadAmount = (
|
const getImagePreLoadAmount = (
|
||||||
isCurrentChapter: boolean,
|
isCurrentChapter: boolean,
|
||||||
isPreviousChapter: boolean,
|
isPreviousChapter: boolean,
|
||||||
isNextChapter: boolean,
|
isNextChapter: boolean,
|
||||||
imagePreLoadAmount: number,
|
imagePreLoadAmount: number,
|
||||||
|
currentChapterRemainingPages: number,
|
||||||
): number => {
|
): number => {
|
||||||
if (isCurrentChapter) {
|
if (isCurrentChapter) {
|
||||||
return imagePreLoadAmount;
|
return imagePreLoadAmount;
|
||||||
@@ -546,7 +546,7 @@ const getImagePreLoadAmount = (
|
|||||||
|
|
||||||
if (isPreviousChapter || isNextChapter) {
|
if (isPreviousChapter || isNextChapter) {
|
||||||
return coerceIn(
|
return coerceIn(
|
||||||
MAX_PREVIOUS_NEXT_CHAPTER_IMAGE_LOAD_AMOUNT,
|
imagePreLoadAmount - currentChapterRemainingPages,
|
||||||
MIN_PREVIOUS_NEXT_CHAPTER_IMAGE_LOAD_AMOUNT,
|
MIN_PREVIOUS_NEXT_CHAPTER_IMAGE_LOAD_AMOUNT,
|
||||||
imagePreLoadAmount,
|
imagePreLoadAmount,
|
||||||
);
|
);
|
||||||
@@ -557,6 +557,7 @@ const getImagePreLoadAmount = (
|
|||||||
|
|
||||||
const PREVIOUS_IMAGE_LOAD_AMOUNT = 2;
|
const PREVIOUS_IMAGE_LOAD_AMOUNT = 2;
|
||||||
export const getPageIndexesToLoad = (
|
export const getPageIndexesToLoad = (
|
||||||
|
currentChapterRemainingPages: number,
|
||||||
currentPageIndex: number,
|
currentPageIndex: number,
|
||||||
pages: ReaderStatePages['pages'],
|
pages: ReaderStatePages['pages'],
|
||||||
previousCurrentPageIndex: number,
|
previousCurrentPageIndex: number,
|
||||||
@@ -576,6 +577,7 @@ export const getPageIndexesToLoad = (
|
|||||||
isPreviousChapter,
|
isPreviousChapter,
|
||||||
isNextChapter,
|
isNextChapter,
|
||||||
imagePreLoadAmount,
|
imagePreLoadAmount,
|
||||||
|
currentChapterRemainingPages,
|
||||||
);
|
);
|
||||||
|
|
||||||
const directionInvert = previousCurrentPageIndex <= currentPageIndex && !isPreviousChapter ? 1 : -1;
|
const directionInvert = previousCurrentPageIndex <= currentPageIndex && !isPreviousChapter ? 1 : -1;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ const BaseBasePager = ({
|
|||||||
resumeMode,
|
resumeMode,
|
||||||
handleAsInitialRender,
|
handleAsInitialRender,
|
||||||
ref,
|
ref,
|
||||||
|
currentChapterRemainingPages,
|
||||||
}: Omit<ReaderPagerProps, 'pageLoadStates' | 'retryFailedPagesKeyPrefix' | 'isPreloadMode'> &
|
}: Omit<ReaderPagerProps, 'pageLoadStates' | 'retryFailedPagesKeyPrefix' | 'isPreloadMode'> &
|
||||||
Pick<IReaderSettings, 'readingMode' | 'imagePreLoadAmount'> & {
|
Pick<IReaderSettings, 'readingMode' | 'imagePreLoadAmount'> & {
|
||||||
createPage: (
|
createPage: (
|
||||||
@@ -67,6 +68,7 @@ const BaseBasePager = ({
|
|||||||
const pagesIndexesToRender = useMemo(
|
const pagesIndexesToRender = useMemo(
|
||||||
() =>
|
() =>
|
||||||
getPageIndexesToLoad(
|
getPageIndexesToLoad(
|
||||||
|
currentChapterRemainingPages,
|
||||||
currentPageIndex,
|
currentPageIndex,
|
||||||
pages,
|
pages,
|
||||||
previousCurrentPageIndex.current,
|
previousCurrentPageIndex.current,
|
||||||
@@ -76,7 +78,16 @@ const BaseBasePager = ({
|
|||||||
isPreviousChapter,
|
isPreviousChapter,
|
||||||
isNextChapter,
|
isNextChapter,
|
||||||
),
|
),
|
||||||
[currentPageIndex, pages, imagePreLoadAmount, readingMode, isCurrentChapter, isPreviousChapter, isNextChapter],
|
[
|
||||||
|
currentChapterRemainingPages,
|
||||||
|
currentPageIndex,
|
||||||
|
pages,
|
||||||
|
imagePreLoadAmount,
|
||||||
|
readingMode,
|
||||||
|
isCurrentChapter,
|
||||||
|
isPreviousChapter,
|
||||||
|
isNextChapter,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isCurrentChapter) {
|
if (isCurrentChapter) {
|
||||||
|
|||||||
Reference in New Issue
Block a user