Skip to content

Add EPUBNavigatorViewController's viewport #612

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

Merged
merged 3 commits into from
Jun 16, 2025
Merged

Conversation

mickael-menu
Copy link
Member

Added

Navigator

  • You can now access the viewport property of an EPUBNavigatorViewController to obtain information about the visible portion of the publication, including the visible positions and reading order indices.

The initial use case that motivated this PR is the need to display a range of visible positions to the user (e.g., 5-6 of 120). This helps prevent confusion when turning pages "skips" several positions.

I initially considered adding a second locator representing the "last visible locator", but this solution has some issues:

  • Locator is not typed for each navigator. We want to move away from using Locator in the APIs and keep it as a serialization and exchange format only.
  • We want the locator to contain the last visible position, but its progression will actually be the beginning of the next "screen page" (as it is the same as the last scroll progression of the current screen page). Therefore the locator would contain two incompatible values.

After thinking more about this problem, I believe we should separate the current location (e.g. used for restoring the reading progression) from information about the rendering, which could actually contain more information that the last visible position (e.g. the list of reading order items currently displayed).

In this PR I added a new viewport property in the EPUB navigator which can be used to report information about the visible portion of a publication in the navigator. Currently it contains only two informations:

  • positions: ClosedRange<Int> - a range of visible positions, e.g 5...6
  • readingOrderIndices: ClosedRange<ReadingOrder.Index> - a contiguous range of indexes of the visible resources from the readingOrder.
    • This one is actually useful if you want to compute a "x positions left in chapter" label. We could get the visible resource from the current locator, but what we really want is the number of positions in the last visible resource in the navigator.

@qnga @JayPanoz @chocolatkey I would love to get your opinion on this as we will likely need to align the implementations at some point.

Copy link

@Copilot 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 pull request adds a new viewport property to the EPUB navigator to expose information about visible reading order indices and positions, and updates several APIs to replace direct use of links with reading order indices. Key changes include:

  • Introduction of the ReadingOrder typealias and ReadingOrderIndices to represent resource position data.
  • Updates to locator and progression computations to work with reading order indices.
  • Adjustments in several navigator view classes (EPUBSpreadView, EPUBSpread, EPUBNavigatorViewController, etc.) to improve consistency and readability.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Support/Carthage/Readium.xcodeproj/project.pbxproj Added ReadingOrder.swift file reference to the project.
Sources/Navigator/ReadingOrder.swift New typealiases for ReadingOrder and ReadingOrderIndices have been introduced.
Sources/Navigator/EPUB/Scripts/src/utils.js Updated scroll handling logic for clearer progression reporting.
Sources/Navigator/EPUB/EPUBSpreadView.swift Changed focusedResource type and progression() return type to use reading order indices.
Sources/Navigator/EPUB/EPUBSpread.swift Refactored spread logic to retrieve indices instead of links, ensuring consistency in JSON output.
Sources/Navigator/EPUB/EPUBNavigatorViewController.swift Introduced a viewport structure and updated location computation logic to include viewport data.
Sources/Navigator/EPUB/EPUBReflowableSpreadView.swift Updated spread view logic to use reading order indices for navigation.
Sources/Navigator/Audiobook/AudioNavigator.swift Added @mainactor context to playback task for improved thread safety.
CHANGELOG.md Updated changelog with the new viewport property and related navigator improvements.
Comments suppressed due to low confidence (3)

Sources/Navigator/EPUB/EPUBNavigatorViewController.swift:137

  • Consider using the existing typealias 'ReadingOrderIndices' instead of 'ClosedRange<[Link].Index>' for consistency and clarity.
public var readingOrderIndices: ClosedRange<[Link].Index>

Sources/Navigator/EPUB/EPUBSpreadView.swift:47

  • [nitpick] Since the variable now holds an index rather than a full resource, consider renaming 'focusedResource' to 'focusedResourceIndex' for improved clarity.
private(set) var focusedResource: ReadingOrder.Index?

Sources/Navigator/EPUB/EPUBSpreadView.swift:345

  • [nitpick] Returning '0 ..< 0' to represent an empty progression range might be unclear; consider defining a named constant (e.g. EMPTY_PROGRESSION) to improve readability and maintainability.
return 0 ..< 0

@mickael-menu mickael-menu merged commit 89d552b into develop Jun 16, 2025
5 checks passed
@mickael-menu mickael-menu deleted the epub/viewport branch June 16, 2025 13:15
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.

1 participant