-
Notifications
You must be signed in to change notification settings - Fork 83
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
Fix configuration change crash with PdfNavigatorFragment
#398
Conversation
|
||
override fun createDocumentFragmentFactory( | ||
input: PdfDocumentFragmentInput<PdfiumDocumentFragment.Listener, PdfiumSettings> | ||
): SingleFragmentFactory<PdfiumDocumentFragment> = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We return a SingleFragmentFactory
which is a custom implementation of FragmentFactory
able to instantiate a new instance without knowing the class of the fragment.
// We don't support fragment restoration for the PdfFragment, as we want to recreate a fresh | ||
// instance in [reset]. To prevent restoring (and crashing) the PdfFragment without a | ||
// document source, we remove it from the fragment manager. | ||
(childFragmentManager.findFragmentByTag(pdfFragmentTag) as? PdfFragment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thankfully, PSPDFKit's PdfFragment
will crash when creating its view and not when creating the fragment, so we have time to remove it from the fragment manager.
@@ -9,17 +8,17 @@ public interface InputListener { | |||
* Called when the user tapped the content, but nothing handled the event internally (eg. | |||
* by following an internal link). | |||
*/ | |||
public fun onTap(navigator: VisualNavigator, event: TapEvent): Boolean = false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I simplified InputListener
to not depend on a Navigator
instance. This way it could be forwarded to a lower level component, such as a PdfDocumentFragment
.
readium/navigator/src/main/java/org/readium/r2/navigator/pdf/PdfNavigatorFactory.kt
Outdated
Show resolved
Hide resolved
.../pdfium/pdfium-document/src/main/java/org/readium/adapters/pdfium/document/PdfiumDocument.kt
Outdated
Show resolved
Hide resolved
readium/navigator/src/main/java/org/readium/r2/navigator/pdf/PdfNavigatorFactory.kt
Outdated
Show resolved
Hide resolved
… into fix/pdf-fragments
PdfDocumentFactory
now returns aResourceTry<PdfDocument>
instead of throwing an exception in case of an error.PdfEngineProvider
now provides aFragmentFactory
for thePdfDocumentFragment
.PdfNavigatorFragment
is the source of truth for the current page and settings. When restoring the fragment, thePdfDocumentFragment
is recreated from the last known page index and settings stored in the view model. This is to simplify the implementations ofPdfDocumentFragment
, which don't need to save and restore any state.