From b12e28346c1493d1a4cffce3e51082a33a84fc21 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Wed, 5 Feb 2025 21:23:20 +0100 Subject: [PATCH] Improve reader infinite scroll chapter change detection A 10% intersection threshold does not work for pages that are so long that 10% of the page will never be in the viewport --- .../reader/hooks/useReaderInfiniteScrollUpdateChapter.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/reader/hooks/useReaderInfiniteScrollUpdateChapter.ts b/src/modules/reader/hooks/useReaderInfiniteScrollUpdateChapter.ts index e38c92af..9ce6cc23 100644 --- a/src/modules/reader/hooks/useReaderInfiniteScrollUpdateChapter.ts +++ b/src/modules/reader/hooks/useReaderInfiniteScrollUpdateChapter.ts @@ -25,7 +25,7 @@ interface ElementIntersectionInfo { [ReadingMode.CONTINUOUS_HORIZONTAL]: ElementIntersection; } -const OPEN_CHAPTER_INTERSECTION_RATIO = 0.1; +const OPEN_CHAPTER_INTERSECTION_RATIO = 0; /** * Returns info about if the start or end of an element is intersecting. @@ -217,7 +217,7 @@ export const useReaderInfiniteScrollUpdateChapter = ( elementIntersectionInfo, readingMode, ); - const wasPageScrolledOutOfView = entry.intersectionRatio < OPEN_CHAPTER_INTERSECTION_RATIO; + const wasPageScrolledOutOfView = entry.intersectionRatio <= OPEN_CHAPTER_INTERSECTION_RATIO; if (!shouldHandleIntersectionEvent(elementIntersectionInfo, readingMode)) { return; @@ -242,7 +242,7 @@ export const useReaderInfiniteScrollUpdateChapter = ( wasNextChapterOpened = true; } }, - { threshold: [OPEN_CHAPTER_INTERSECTION_RATIO] }, + { threshold: [OPEN_CHAPTER_INTERSECTION_RATIO], rootMargin: '-10px 0px 0px 0px' }, ); intersectionObserver.observe(image);