Various bugfixes related to reflowable EPUB positioning.
Improve the reliability of the callback executed when the page is fully laid out.
Before we used several strategies which were not 100% reliable, causing the loss of positions:
A hard-coded delay.
Executing a dummy JavaScript and waiting for the callback.
Now when available we use WebViewCompat.postVisualStateCallback() which will call back when the current DOM state is ready to be drawn. During my tests, it was 100% reliable. Time will tell if this is enough.
Fixed a regression to notify the current location when jumping in the same resource.
Fixed loading a faulty initial locator by closing the Publication systematically when the ReaderViewModel.onCleared() is called.
Before, we were waiting for ReaderActivity.finish() to close the Publication. But if the reader activity is restarted right away, after being killed from the Recents Tasks screen, but before the ReaderRepository (and whole process) is killed, we will get the old Publication object and its initialLocation which is now outdated.
Bonus: Fix JavaScript "ResizeObserver loop completed with undelivered notifications" warnings by wrapping the callback from ResizeObserver with a requestAnimationFrame. This helps prevents an infinite loop caused by the callback triggering a layout. The WebView stops the infinite loop when detected with the aforementioned warning.
Various bugfixes related to reflowable EPUB positioning.
WebViewCompat.postVisualStateCallback()
which will call back when the current DOM state is ready to be drawn. During my tests, it was 100% reliable. Time will tell if this is enough.Publication
systematically when theReaderViewModel.onCleared()
is called.ReaderActivity.finish()
to close thePublication
. But if the reader activity is restarted right away, after being killed from the Recents Tasks screen, but before theReaderRepository
(and whole process) is killed, we will get the oldPublication
object and itsinitialLocation
which is now outdated.ResizeObserver
with arequestAnimationFrame
. This helps prevents an infinite loop caused by the callback triggering a layout. The WebView stops the infinite loop when detected with the aforementioned warning.