Commit Graph

50 Commits

Author SHA1 Message Date
Constantin Piber
4423dee14e Fix preserving scroll position on infinite scroll previous chapter load (#913)
When scrolling to the previous chapter, which has not been preloaded, the scroll position got lost due to the resulting layout shift

* Update scroll preserve by tracking cursor

* Clean up interface

* Observe just the wrappers instead of individual images

* Switch to `IntersectionObserver` for tracking active element

* Clean up adding of observations

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>

---------

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>
2025-04-05 12:45:52 +02:00
schroda
e1895b21e3 Use "ReaderChapterViewer" as "root" for "IntersectionObserver" for "infinite scroll"
Using the actual "document element" as the "intersection observer root" causes issues in case the available reader width is less than the viewport.
In these cases sometimes the previous/next chapter never loaded because the necessary intersection never fired.
2025-04-05 01:05:54 +02:00
schroda
642708b8b3 Immediately open previous/next chapter on reader nav bar button click
The logic didn't handle cases were the next/previous chapter wasn't loaded yet, which lead to the load happening in the background without any user feedback.
2025-04-02 02:27:01 +02:00
schroda
7145c33fbb Preserve current page on reader width change only when necessary
The pages only change in size with specific "page scale modes".
Thus, if these modes are not active, the scroll position will not be lost.

There are different cases were even with these modes active, the scroll position won't get lost (e.g. "fit width" while no page is larger than the available width), but handling these would be too cumbersome.

Ideally the relative scroll position would be preserved, however, from testing a little that seems to not work too well
2025-03-27 19:49:53 +01:00
Constantin Piber
541eeb0445 Reader preserve current page on window resize (#905)
* Reader: Reset bounds on window size change

19f2d993 introduced a `minWidth` to make sure sizes are consistent over
chapter changes (or when images load later), but when the window itself
changes, this makes the reader incorrectly sized

* Reader: Update size on navbar width change

This happens mostly when the bar is pinned; same effect as previous
commit

* Reader: Attempt to set the page on resize

It's not perfect, but not changing position at all seems impossible due
to how resizes are handled by the browser (since we adjust our content
to the window size)

* Simplify and abstract reader size reset

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>

* fix: Reader page full width was not properly calculated for static navbar

Only relevant for Fit Content, this did not properly consider the navbar
when the user clamps the content to a custom width

* Refactor: Put reader min sizes to reader itself instead of chapter

This allows some logic simplification.
The `ResizeObserver` can needs to be on an element without restrictions;
previously, the observer would not see the chapter elements get smaller,
since the `min-width` prevented it from shrinking. By applying to the
outer element, we still preserve the centering (since `margin: auto` is
also applied here), but allow the chapter itself to be smaller.

* Reader: Only scroll in continuous reading modes

* Reader: clean up size tracking

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>

* Fixup previous commit stupidness

* Reader: move `minWidth`/`minHeight` back to chapter wrapper

* Apply suggestions from code review

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>

* Also revert `fullWidth` calculation

* Simplify `chapterViewerSize`

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>

* Move size logic entirely to hook

---------

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>
2025-03-24 23:45:06 +01:00
Constantin Piber
c9c1b8625a Reader preserve current page on reader mode change (#906)
* Reader: Re-scroll on reader mode change

* Simplify reading mode restore

https://github.com/Suwayomi/Suwayomi-WebUI/pull/906#discussion_r2009147119

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>

* Move effect as per suggestion

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>

---------

Co-authored-by: schroda <50052685+schroda@users.noreply.github.com>
2025-03-24 23:24:36 +01:00
schroda
a85e5584c8 Preserve scroll position continuous pager on previous chapter load
In the horizontal pager loading the previous chapter caused the scroll position to get lost and instead of starting at the end of the previous chapter, the scroll position was at the very start.
This happened everytime no matter if the scroll position was at the x 0 or not before the previous chapter got visible.

Same issue can be observed in the vertical pager in case the scroll position is at y 0 before the previous chapter has been rendered.
2025-02-19 16:43:58 +01:00
schroda
eba3cadb8b Properly detect previous chapter load state
Regression from 174d850093
2025-02-18 02:06:13 +01:00
schroda
c6fe715e57 Handle faulty "lastPageRead" values
There seems to be a bug on the server which sets the "lastPageRead" of a chapter to -1 which should not happen
2025-02-12 19:40:43 +01:00
schroda
174d850093 Preload previous/next chapter in reader 2025-02-10 22:40:49 +01:00
schroda
187693ce5a Properly handle not skipping duplicate chapters
The filtered chapter list of the reader state always incorrectly filtered out duplicated chapters even while the setting was disabled
2025-02-05 20:05:36 +01:00
schroda
a32c88a549 Reset "ReaderChapterViewer" min width/height on "ReadingMode" change 2025-02-05 15:48:55 +01:00
schroda
19f2d99345 Center "ReaderChapterViewers"
The viewers can have different sizes which caused theme to not be properly centered.

E.g. for the "vertical mode" in case "chapter 1" is greater in width than "chapter 2", the pages of "chapter 2" were not correctly centered due to the "viewers" having different widths.
2025-02-05 00:34:44 +01:00
schroda
2ec42d962a Remove context usage from ReaderPage
In case many chapters are rendered, even just the HOC wrapper component re-render due to the context change increases the render time.

Thus, getting rid of these HOC wrapper re-renders by moving the context usage up to the ReaderViewer decreases the render time.
2025-02-03 17:17:35 +01:00
schroda
b01b23b069 Remove context usage from ReaderChapterViewer
In case many chapters are rendered, even just the HOC wrapper component re-render due to the context change increases the render time.

Thus, getting rid of these HOC wrapper re-renders by moving the context usage up to the ReaderViewer decreases the render time.
2025-02-03 17:17:35 +01:00
schroda
4a9d2903b8 Add infinite scroll to reader 2025-02-03 17:17:35 +01:00
schroda
649a17c2ae Move "ReaderTransitionPage" to "ReaderViewer" 2025-01-21 19:19:27 +01:00
schroda
19f83d5237 Extract hooks from utils file 2025-01-18 22:07:59 +01:00
schroda
757cf599d6 Enable mouse drag scrolling for all reading modes 2025-01-10 02:07:24 +01:00
schroda
afc3a23ae0 Always scroll to start of page on page change
By the time the scroll area got scrolled to the start of the visible pages, the previous/next page wasn't yet shown and thus, the scrollable area wasn't updated yet.
Thus, in case the scrollable area grew in width due to the page change, the start never got scrolled into view due to triggering the logic too early.
2025-01-10 02:03:31 +01:00
schroda
a423d11442 Prevent reader pages from getting cut off on small screens
In case the pages were larger in width then the screen, they got cut off and were not fully viewable.
2025-01-09 21:41:38 +01:00
schroda
17cf8ec9d0 Update "pagesToSpreadState" during render
Gets rid of an unnecessary rendering
2024-12-31 13:25:37 +01:00
schroda
3bab657c52 Update "actualPages" immediately
Instead of immediately updating the value once the page count changed, it got updated after "pagesToSpreadState" changed, which was after the rendering finished.

This was the actual root cause of what was tried to be fixed with 9ab6ec89c7
2024-12-31 13:24:29 +01:00
schroda
95f95e770f Prevent TypeError and incorrect state updates for "pagesSpreadState"
Page spread state updates of an already closed chapter caused TypeErrors or incorrect state updates.
2024-12-30 21:03:13 +01:00
schroda
7c98bab43b Prevent TypeError and incorrect state updates for "pageLoadStates"
Page load state updates of an already closed chapter caused TypeErrors or incorrect state updates.
2024-12-30 21:03:10 +01:00
schroda
45f46a05d0 Optionally show preview or "reading mode" and "tap zone overlay"
Shows a preview when opening the reader or when the values change
2024-12-30 16:51:39 +01:00
schroda
a943d2f2bc Extract logic from "ReaderViewer" into functions and hooks 2024-12-29 21:38:31 +01:00
schroda
94ee7d4958 Improve "page spread page state" updates
Since "pagesToSpreadState" isn't part of the dependency array and also would decrease the render performance if it was (see reasoning of c79f7cc874), the array reference might be out of date and thus, the guard might not work correctly
2024-12-29 21:38:24 +01:00
schroda
c79f7cc874 Improve "page load state" updates
Changes of d6ff85fdd3 decreased the render performance due to the "onLoad" function changing and causing all pages to re-render.
2024-12-29 17:21:37 +01:00
schroda
347c88f240 Correctly check "page load state" before state update 2024-12-28 01:59:07 +01:00
schroda
c5630ca5ce Reset "pageToScrollToIndex" after page selection
In case the current page changed after selecting a page, the previously selected page couldn't be selected again since the "pageToScrollToIndex" was still set to this page
2024-12-28 01:28:12 +01:00
schroda
d6ff85fdd3 Prevent unnecessary "page load state" updates
Only update state in case it has changed
2024-12-27 18:26:19 +01:00
schroda
e2075a651e Add "automatic scrolling" 2024-12-27 03:02:39 +01:00
schroda
5220f8ca44 Prevent unnecessary "page spread state" updates
Only update state in case it has changed
2024-12-25 23:50:07 +01:00
schroda
ae89a42ac4 Scroll to start of page on page change
Resets the scroll position for single/double page mode to the start of the opened page on a page change.
2024-12-25 02:59:53 +01:00
schroda
34ad331a71 Improve memoization of page rendering 2024-12-22 00:48:22 +01:00
schroda
58c402dd0e Memoize components 2024-12-22 00:48:21 +01:00
schroda
f5642af219 Use HOC for reader context usage 2024-12-22 00:48:18 +01:00
schroda
392998f4ca Prevent going to next page on "offset spread pages" change
Due to handling an "offset spread page" change as if the "double page" mode got activated, the index of the secondary page was set, which resulted in opening the next page
2024-12-17 01:55:11 +01:00
schroda
f51446995a Fix "continuous vertical pager" unintentional page gaps
Depending on the screen size and e.g. the set "reader width" pages might not have filled out the full img elements size due to "object-fit contain".
This was caused due to the image wrappers flex container "align-items center" which slightly reduced the images width to some ".xy" number (e.g. instead of wrappers width 258px, the images were something like 257.83px)
2024-12-16 22:09:00 +01:00
schroda
942d8699c1 Add "Webtoon" reading mode 2024-12-16 22:08:58 +01:00
schroda
d00c930598 Fix "is read" detection in single/double page mode
In case the last page of a manga was immediately visible or the became visible after the "image spread state" change, the chapter never got marked as read
2024-12-12 13:21:48 +01:00
schroda
8ca0af8d02 Hide overlay on page/scroll change 2024-12-11 22:36:02 +01:00
schroda
1387a016c7 Fix page changes via click/hotkey in horizontal pager
Due to the way the pages got scrolled into view, the current page was not changed to the new page.
This then prevented the previous/next page to get opened via click/hotkey actions
2024-12-09 15:07:52 +01:00
schroda
be0d1dbf30 Add logic to retry all errored pages 2024-12-09 02:38:37 +01:00
schroda
5de5eb7cdc Hide cursor on mouse inactivity 2024-12-09 02:38:37 +01:00
schroda
965aa7215c Update chapter 2024-12-09 02:38:37 +01:00
schroda
206c216093 Add mouse drag scrolling to continuous pagers 2024-12-09 02:38:37 +01:00
schroda
fb31a92cd7 Reader transition page 2024-12-09 02:38:37 +01:00
schroda
7cf78e771a Reader page rendering 2024-12-09 02:38:37 +01:00