Skip to content

fix(reader): prevent webtoon backward scroll from jumping chapters#652

Merged
everpcpc merged 3 commits intomainfrom
fix-webtoon
Mar 11, 2026
Merged

fix(reader): prevent webtoon backward scroll from jumping chapters#652
everpcpc merged 3 commits intomainfrom
fix-webtoon

Conversation

@everpcpc
Copy link
Copy Markdown
Owner

Problem

Scrolling backward (up) in Webtoon mode causes the reader to jump to previous chapters. Tapping the "previous" zone also jumps a full chapter, and dragging up triggers cascading jumps through many chapters.

The root cause is a state inconsistency in update(): rebuildContentItemsIfNeeded() updates the page-to-index mapping to reflect newly prepended chapters before handleDataReload() captures the current scroll offset. The capture then looks up the current page's new index against the old collection view layout, reading the wrong cell's frame. After reloadData(), the wrong offset is restored, placing the user in the wrong chapter and triggering further segment preloading in a cascade.

Approach

Move rebuildContentItemsIfNeeded from update() into handleDataReload() so the entire sequence is atomic:

  1. Capture offset — old indices + old layout (consistent)
  2. Rebuild content items — index mapping updated to new
  3. Reload collection view — layout updated to match new indices
  4. Restore offset — new indices + new layout (consistent)

For deferred reloads (user actively scrolling), the offset is captured at defer time while indices and layout are still consistent, stored in pendingReloadPreCapturedOffset, and passed through when the deferred reload fires.

Scope

  • WebtoonScrollEngine: add needsRebuild(viewModel:) check and pendingReloadPreCapturedOffset storage
  • WebtoonReaderView_iOS: restructure update(), handleDataReload(), applyPendingReloadIfNeeded()
  • WebtoonReaderView_macOS: same restructuring as iOS

Testing

  • Open Webtoon-mode book, scroll to beginning of chapter, scroll up — should NOT jump chapters
  • Tap "previous" zone at top — should scroll up within chapter
  • Drag upward continuously — should scroll smoothly without cascading jumps
  • Scroll to end of chapter — next chapter should still load correctly
  • Rotate device / resize window — scroll position should be preserved

🤖 Generated with Claude Code

everpcpc and others added 3 commits March 11, 2026 22:32
Move rebuildContentItemsIfNeeded from update() into handleDataReload()
so offset capture, index rebuild, layout reload, and offset restore
form an atomic sequence. Previously the index mapping was updated before
the offset was captured against the old layout, causing wrong offsets
when previous chapters were prepended.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@everpcpc everpcpc merged commit 03d2c68 into main Mar 11, 2026
3 checks passed
@everpcpc everpcpc deleted the fix-webtoon branch March 11, 2026 14:38
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