Skip to content

Conversation

@mickael-menu
Copy link
Member

Changelog

Added

Navigator

  • Added fit preference for PDF documents to control how pages are scaled within the viewport.
    • Only effective in scroll mode. Paginated mode always uses page fit due to PDFKit limitations.

Changed

Navigator

  • The Fit enum has been redesigned to fit the PDF implementation.
    • Breaking change: Update any code using the old Fit enum values.
  • The PDF navigator's content inset behavior has changed:
    • iPhone: Continues to apply window safe area insets (to account for notch/Dynamic Island).
    • iPad/macOS: Now displays edge-to-edge with no automatic safe area insets.
    • You can customize this behavior with VisualNavigatorDelegate.navigatorContentInset(_:).

Implementation notes

I hit a wall implementing the fit preference with Apple’s PDFKit. While it works in scroll mode, the paginated mode has critical limitations (maybe because Apple doesn't use it in their own apps like Preview).

  • Visual snap: There is no API to pre-set the zoom scale for the next page. ⁠PDFView resets the scale per page, causing a visible snap when swiping. We don’t see the issue with edge taps.
  • Incorrect anchoring: When zooming larger than the page fit, the viewport centers vertically instead of showing the top. The API to fix this works in scroll mode but is ignored in paginated mode.

We could try hacking the internal ⁠PDFView view hierarchy, but it would be extremely fragile.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new fit preference for PDF documents to control how pages are scaled within the viewport, along with redesigning the Fit enum and adjusting content inset behavior for different devices.

  • Introduces a fit preference (auto/page/width) for PDF documents to control page scaling, effective only in scroll mode
  • Redesigns the Fit enum from cover/contain/width/height to auto/page/width (breaking change)
  • Changes PDF navigator content inset behavior: iPhones retain safe area insets (for notch/Dynamic Island), while iPads/macOS display edge-to-edge

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Sources/Navigator/Preferences/Types.swift Redesigned Fit enum with new values and updated documentation
Sources/Navigator/PDF/Preferences/PDFPreferences.swift Added fit property to preferences struct with proper initialization and merging
Sources/Navigator/PDF/Preferences/PDFSettings.swift Added fit to settings with proper defaults (.auto) and fallback chain
Sources/Navigator/PDF/Preferences/PDFPreferencesEditor.swift Added fit preference editor with supported values and effectiveness condition
Sources/Navigator/PDF/PDFDocumentView.swift Implemented scale factor calculations, content inset logic, and caching for the fit preference
Sources/Navigator/PDF/PDFNavigatorViewController.swift Updated scale factor logic to use new fit preference and handle rotation properly
TestApp/Sources/Reader/Common/Preferences/UserPreferences.swift Integrated fit preference into test app UI with updated enum values
CHANGELOG.md Documented the new feature and breaking changes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mickael-menu mickael-menu merged commit e49966e into develop Dec 4, 2025
5 checks passed
@mickael-menu mickael-menu deleted the pdf-fit branch December 4, 2025 16:18
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