Skip to content

Conversation

@erkasraim
Copy link
Contributor

@erkasraim erkasraim commented Aug 13, 2025

I’ve migrated R2RTLViewPager to R2RTLViewPager2.
The key changes are as follows:

Applying RTL is now much simpler with ViewPager2.

With ViewPager2's support for both horizontal and vertical orientation,
WebViews can now be laid out vertically in scroll mode, which provides a better user experience.

In R2RTLViewPager2’s onInterceptTouchEvent(),
touch events are controlled based on the WebView's scroll state,
allowing for smoother swipe handling when switching between pages containing WebViews.

issue link : #703

@erkasraim erkasraim changed the title Refactor R2RTLViewPager using ViewPager2 for better RTL and scroll behavior Improve UX Consistency in Spine Navigation Aug 18, 2025
# Conflicts:
#	readium/navigator/src/main/java/org/readium/r2/navigator/pager/R2ViewPager.kt
@mickael-menu
Copy link
Member

Thank you, @erkasraim! It looks very promising. I'm sorry for the delay in reviewing your PR, I've had a lot on my plate.

I did notice an issue when testing, sometimes it crashed when jumping to a different location (at least in scroll mode) far away in the book:

java.lang.IllegalStateException: Can't access the Fragment View's LifecycleOwner for R2EpubPageFragment{836c7eb} (07db6bcb-3f3c-43de-a044-75236d79413a) when getView() is null i.e., before onCreateView() or after onDestroyView()
    at androidx.fragment.app.Fragment.getViewLifecycleOwner(Fragment.java:390)
    at org.readium.r2.navigator.pager.R2EpubPageFragment.loadLocator$readium_navigator_debug(R2EpubPageFragment.kt:426)
    at org.readium.r2.navigator.pager.R2PagerAdapter.loadLocatorAt$readium_navigator_debug(R2PagerAdapter.kt:111)
    at org.readium.r2.navigator.epub.EpubNavigatorFragment.go$setCurrent(EpubNavigatorFragment.kt:715)
    at org.readium.r2.navigator.epub.EpubNavigatorFragment.go(EpubNavigatorFragment.kt:719)
    at org.readium.r2.testapp.reader.BaseReaderFragment.go(BaseReaderFragment.kt:117)
    at org.readium.r2.testapp.reader.VisualReaderFragment.go(VisualReaderFragment.kt:316)
    at org.readium.r2.testapp.reader.ReaderActivity.closeOutlineFragment(ReaderActivity.kt:171)
    at org.readium.r2.testapp.reader.ReaderActivity.onCreate$lambda$3(ReaderActivity.kt:77)
    at org.readium.r2.testapp.reader.ReaderActivity.$r8$lambda$t78Hp_QXDYO79b_TQx3cc6m2QRw(Unknown Source:0)
    at org.readium.r2.testapp.reader.ReaderActivity$$ExternalSyntheticLambda0.onFragmentResult(D8$$SyntheticClass:0)
    at androidx.fragment.app.FragmentManager$LifecycleAwareResultListener.onFragmentResult(FragmentManager.java:340)
    at androidx.fragment.app.FragmentManager.setFragmentResult(FragmentManager.java:1171)
    at androidx.fragment.app.FragmentKt.setFragmentResult(Fragment.kt:33)
    at org.readium.r2.testapp.outline.OutlineFragment.onCreate$lambda$1(OutlineFragment.kt:46)
    at org.readium.r2.testapp.outline.OutlineFragment.$r8$lambda$GorhIFakUlYqyg6cNAsJWb5_jsE(Unknown Source:0)
    at org.readium.r2.testapp.outline.OutlineFragment$$ExternalSyntheticLambda0.onFragmentResult(D8$$SyntheticClass:0)
    at androidx.fragment.app.FragmentManager$LifecycleAwareResultListener.onFragmentResult(FragmentManager.java:340)
    at androidx.fragment.app.FragmentManager.setFragmentResult(FragmentManager.java:1171)
    at androidx.fragment.app.FragmentKt.setFragmentResult(Fragment.kt:33)
    at org.readium.r2.testapp.outline.NavigationFragment.onLinkSelected(NavigationFragment.kt:89)

I addressed the crash in this commit: 632e7c6

But I believe there's a more fundamental issue because now it doesn't restore the location. You can test this by setting a bookmark in the middle of a chapter and then trying to jump back and forth between distant locations and this bookmark. Sometimes you will end up at the beginning of the resource instead of the bookmark location. Do you have any idea?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants