Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPUB columns are not refreshed when rotating a device #128

Open
mickael-menu opened this issue Jun 3, 2022 · 1 comment
Open

EPUB columns are not refreshed when rotating a device #128

mickael-menu opened this issue Jun 3, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@mickael-menu
Copy link
Member

Bug Report

What happened?

When rotating the device, EPUB columns get messed up if we don't recreate the Activity:

Screen.Recording.2022-06-03.at.11.51.07.mov

Expected behavior

How to reproduce?

  1. Disable recreation of the reader Activity during screen rotations in AndroidManifest.xml:
    <activity
        android:name=".reader.ReaderActivity"
        android:configChanges="orientation|screenSize"
        android:label="Reader" />
  2. Open an EPUB.
  3. Rotate the device.

Environment

  • Readium version: develop

Testing device

  • Android version: API 31
  • Is it an emulator? Yes

Additional context

I'm not 100% sure this is to be fixed, as Android recommend to not handle configuration changes manually anyways:

Caution: Handling the configuration change yourself can make it much more difficult to use alternative resources, because the system does not automatically apply them for you. This technique should be considered a last resort when you must avoid restarts due to a configuration change and is not recommended for most applications.
https://developer.android.com/guide/topics/resources/runtime-changes#HandlingTheChange

However, this issue might surface in other legit situations like a resizable window on Chrome OS.

This is already supposed to work with this piece of JavaScript code, maybe there's an issue with Android.getViewportWidth():

function onViewportWidthChanged() {
// We can't rely on window.innerWidth for the pageWidth on Android, because if the
// device pixel ratio is not an integer, we get rounding issues offsetting the pages.
//
// See https://github.com/readium/readium-css/issues/97
// and https://github.com/readium/r2-navigator-kotlin/issues/146
var width = Android.getViewportWidth();
pageWidth = width / window.devicePixelRatio;
setProperty(
"--RS__viewportWidth",
"calc(" + width + "px / " + window.devicePixelRatio + ")"
);
}

@mickael-menu mickael-menu added the bug Something isn't working label Jun 3, 2022
@mickael-menu
Copy link
Member Author

Calling onViewportWidthChanged from the ResizeObserver seems to fix the problem. However, we loose the scroll progression as it is not restored by the web view. This needs more work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant