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

Fix configuration change crash with PdfNavigatorFragment #398

Merged
merged 14 commits into from
Oct 3, 2023

Conversation

mickael-menu
Copy link
Member

@mickael-menu mickael-menu commented Sep 26, 2023

  • Fix crash during configuration changes with PDFium and PSPDFKit.
  • The PdfDocumentFactory now returns a ResourceTry<PdfDocument> instead of throwing an exception in case of an error.
  • The PdfEngineProvider now provides a FragmentFactory for the PdfDocumentFragment.
  • Added a listener and customization point for PSPDFKit.
  • During the fragment lifecycle, the PdfNavigatorFragment is the source of truth for the current page and settings. When restoring the fragment, the PdfDocumentFragment is recreated from the last known page index and settings stored in the view model. This is to simplify the implementations of PdfDocumentFragment, which don't need to save and restore any state.

@mickael-menu mickael-menu requested a review from qnga September 26, 2023 15:53

override fun createDocumentFragmentFactory(
input: PdfDocumentFragmentInput<PdfiumDocumentFragment.Listener, PdfiumSettings>
): SingleFragmentFactory<PdfiumDocumentFragment> =
Copy link
Member Author

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)
Copy link
Member Author

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
Copy link
Member Author

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.

@mickael-menu mickael-menu merged commit e4f1cc4 into v3 Oct 3, 2023
3 checks passed
@mickael-menu mickael-menu deleted the fix/pdf-fragments branch October 3, 2023 10:17
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