Skip to content

feat(mobile): 新增閱讀頁全書頁碼顯示,修正翻頁導覽與目錄跳轉問題#5

Merged
Retsomm merged 2 commits into
mainfrom
dev
Jul 5, 2026
Merged

feat(mobile): 新增閱讀頁全書頁碼顯示,修正翻頁導覽與目錄跳轉問題#5
Retsomm merged 2 commits into
mainfrom
dev

Conversation

@Retsomm

@Retsomm Retsomm commented Jul 5, 2026

Copy link
Copy Markdown
Owner
  • 閱讀頁底部新增「第 X 頁/共 Y 頁・Z%」顯示,比照網頁版 Toolbar 設計;全書頁數改用背景 隱藏渲染每個 linear 章節取得精確頁數(scanAllChapterPages),取代原本字元數概算的作法
  • 修正目錄章節跳轉失敗(No Section Found):目錄 href 與 spine item href 格式不一致, 改用檔名比對 spine items 後再導覽,並補上翻頁忙碌鎖避免與其他導覽動作衝突
  • 修正翻到書尾頁碼與總頁數對不上、Android 書中間頁碼被誤鎖住等問題
  • 統一閱讀頁與書櫃卡片的進度百分比計算來源,避免兩處顯示數字不一致
  • 移除開發過程中新增的診斷用 debug log

Summary by CodeRabbit

  • New Features

    • Added a page number and reading progress display in the reader footer.
    • Improved chapter and page progress accuracy across the reading experience.
  • Bug Fixes

    • Fixed progress percentage mismatches between the reader and library views.
    • Improved page-turning and end-of-book handling on Android.
    • Fixed navigation to table-of-contents targets and bookmarks, including cases that previously failed to open.
    • Prevented layout jumps by reserving space for the progress bar.

- 閱讀頁底部新增「第 X 頁/共 Y 頁・Z%」顯示,比照網頁版 Toolbar 設計;全書頁數改用背景
  隱藏渲染每個 linear 章節取得精確頁數(scanAllChapterPages),取代原本字元數概算的作法
- 修正目錄章節跳轉失敗(No Section Found):目錄 href 與 spine item href 格式不一致,
  改用檔名比對 spine items 後再導覽,並補上翻頁忙碌鎖避免與其他導覽動作衝突
- 修正翻到書尾頁碼與總頁數對不上、Android 書中間頁碼被誤鎖住等問題
- 統一閱讀頁與書櫃卡片的進度百分比計算來源,避免兩處顯示數字不一致
- 移除開發過程中新增的診斷用 debug log

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@vercel

vercel Bot commented Jul 5, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
travel-in-time Ready Ready Preview, Comment Jul 5, 2026 8:04am

@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@Retsomm, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8c773eab-7d67-45e6-98fe-cd903b439aa4

📥 Commits

Reviewing files that changed from the base of the PR and between e873659 and 85523c6.

📒 Files selected for processing (2)
  • mobile/lib/readerHtml.generated.ts
  • mobile/reader-web/index.ts
📝 Walkthrough

Walkthrough

This PR reworks the reader's page/progress computation to use a hidden epub.js rendition scan across linear spine items instead of location-based estimation, fixes TOC navigation targeting, aligns reader footer percentage with library card percentage, updates message types, adds a page progress UI, and removes temporary debug logging.

Changes

Reader Page Progress and Navigation Fix

Layer / File(s) Summary
Message type updates
mobile/lib/readerMessages.ts
OutboundMessage's relocated variant now allows nullable page/total; the debug variant is removed.
Hidden rendition page scan
mobile/reader-web/index.ts
New global state tracks per-chapter page counts and scan readiness; scanAllChapterPages paginates linear spine items via a hidden rendition to compute accurate totals.
Relocated event page/progress computation
mobile/reader-web/index.ts
postRelocated derives global page/total from scanned chapter totals when ready, falls back to estimation otherwise, applies book-end stuck-CFI correction, and a delayed background scan re-posts relocated data after initial display.
TOC/nav goto normalization
mobile/reader-web/index.ts
resolveNavTarget and gotoTarget normalize nav hrefs to spine item hrefs and wait for the busy lock; goto message handling now uses gotoTarget instead of directly calling rendition.display.
Debug logging removal
mobile/reader-web/index.ts
Removes the temporary debugLog helper and debug logging in tap-zone click handling.
RN reader UI page/progress display
mobile/app/reader/[id].tsx
Adds pageInfo state populated from relocated messages, removes the debug message handler and Platform import, extends SafeAreaView to bottom edge, and renders a fixed-height page progress bar showing page/total/percentage.
Progress tracker documentation
RN_SETUP_GUIDE.md
Documents the page-row plan, Android sync iterations, algorithm switch to hidden-rendition scan, footer/library percentage alignment, TOC jump debugging, and removal of diagnostic logging.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ReaderUI as reader/[id].tsx
  participant WebView as reader-web/index.ts
  participant Rendition as HiddenRendition

  ReaderUI->>WebView: load book, display initial location
  WebView->>Rendition: scanAllChapterPages (delayed background)
  Rendition->>WebView: displayed.total per linear chapter
  WebView->>WebView: set chapterPageCounts, locationsReady
  WebView->>WebView: postRelocated (recompute using scanned totals)
  WebView->>ReaderUI: relocated { page, total, percentage }
  ReaderUI->>ReaderUI: update pageInfo, render progress bar
Loading
sequenceDiagram
  participant ReaderUI as reader/[id].tsx
  participant WebView as reader-web/index.ts
  participant Rendition as EpubRendition

  ReaderUI->>WebView: goto message { target }
  WebView->>WebView: resolveNavTarget(target)
  WebView->>WebView: wait for navigation busy lock
  WebView->>Rendition: display(resolved href)
  Rendition->>WebView: relocated event
  WebView->>ReaderUI: postRelocated payload
Loading

Possibly related PRs

  • Retsomm/TravelInTime#1: Introduces the earlier reader-web relocated/page/progress flow that this PR directly reworks in mobile/reader-web/index.ts.
  • Retsomm/TravelInTime#2: Modifies the same relocated handling in mobile/reader-web/index.ts and the relocated payload shape in mobile/lib/readerMessages.ts.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title accurately summarizes the main changes: reader page display plus fixes to page navigation and TOC jumping.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mobile/reader-web/index.ts`:
- Around line 37-48: Reset the pagination globals per loaded book and guard the
delayed scan so it cannot write stale state after a new book is opened. In
`loadBook`, clear `chapterPageCounts`, `locationsReady`, `lastRelocatedLoc`, and
`lastLinearSpineIndex` when starting a new book, and in `scanAllChapterPages`
capture the current `book`/generation before the async work and skip the final
`chapterPageCounts` assignment if it no longer matches. Also make sure the
downstream pagination path that uses `postRelocated` only reads the current
book’s state, not values left over from a previous load.
- Around line 353-363: The spine href resolution logic is stripping off TOC
anchor fragments during matching, then returning only the resolved spine href,
which loses the original `#fragment`. Update the href resolution around the
cleanHref/spineItem lookup so it preserves any fragment from target when
returning the resolved href, while still matching against the fragment-free path
for spine item lookup. Keep the fix localized to the same resolver that uses
target, cleanHref, filename, and spineItem.
- Around line 482-484: The hidden offscreen rendition created in the renderTo
flow is currently enabling scripted content, which should stay disabled for the
whole-book scan. Update the hidden rendition setup in the renderTo call to keep
allowScriptedContent off by default, and only enable it behind a targeted
fallback for EPUBs that cannot paginate otherwise. Use the hiddenRendition
creation path in the reader-web index logic to make the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2a9d430b-a171-4d48-9f81-13f2a82af46d

📥 Commits

Reviewing files that changed from the base of the PR and between 9011a20 and e873659.

📒 Files selected for processing (5)
  • RN_SETUP_GUIDE.md
  • mobile/app/reader/[id].tsx
  • mobile/lib/readerHtml.generated.ts
  • mobile/lib/readerMessages.ts
  • mobile/reader-web/index.ts

Comment thread mobile/reader-web/index.ts
Comment thread mobile/reader-web/index.ts Outdated
Comment thread mobile/reader-web/index.ts Outdated
- loadBook 換書時重置分頁狀態並用 loadGeneration 防止舊書背景掃描覆寫新書資料
- resolveNavTarget 解析 spine href 時保留原本的 #fragment 錨點
- scanAllChapterPages 的隱藏渲染預設關閉 allowScriptedContent,僅在掃不出頁數時才 fallback 開啟

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@Retsomm Retsomm merged commit f2fd67f into main Jul 5, 2026
6 checks passed
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