Refactor EPUB navigation: use jumpTo instead of gotoEpubCfi#213
Refactor EPUB navigation: use jumpTo instead of gotoEpubCfi#213Quinver wants to merge 3 commits into
Conversation
Kara-Zor-El
left a comment
There was a problem hiding this comment.
looks good overall, just fix up in a few areas
| logger.d("Restoring chapter index: $savedIndex"); | ||
| Future.delayed(Duration(milliseconds: 500), () { | ||
| _epubController.jumpTo(index: savedIndex); | ||
| }); |
There was a problem hiding this comment.
i don't actually remember why i had it wait 5 seconds (assuming its to let the book load). If possible can we instead have this done on a hook once the book loads?
There was a problem hiding this comment.
I'm not entirely sure how to implement it as a hook yet, but I’ve resolved the delay issue as mentioned in my comment below. I might look into adding a proper hook later once I’ve had a deeper dive into the codebase.
Merge with upstream
…other tasks if needed.
| Future<void> onBookLoaded() async { | ||
| // Restore saved chapter index | ||
| final savedIndex = await loadChapterIndex(); | ||
| if (savedIndex != null) { | ||
| logger.d("Restoring chapter index: $savedIndex"); | ||
|
|
||
| // Wait for frame to fully load | ||
| WidgetsBinding.instance.addPostFrameCallback((_) { | ||
| _epubController.jumpTo(index: savedIndex); | ||
| }); | ||
| } | ||
|
|
||
| // Add other book loaded tasks here | ||
| logger.d("Book is fully loaded"); | ||
| } |
There was a problem hiding this comment.
Added helper function to run actions after book frame is fully rendered
This should reliably handle tasks that depend on the book being fully loaded,
fixing issues where onDocumentLoaded fires before the UI is ready.
Problem:
gotoEpubCfiapproach didn't reliably jump to the saved position in my testing.Solution:
jumpTo(index)to restore the last read position.Notes:
gotoEpubCfiwork reliably, so this is an alternative approach.Also fixes issue #203.