Skip to content

fix(reader): correct divina scroll page jump on app background/foreground#656

Merged
everpcpc merged 1 commit intomainfrom
fix-jump
Mar 13, 2026
Merged

fix(reader): correct divina scroll page jump on app background/foreground#656
everpcpc merged 1 commit intomainfrom
fix-jump

Conversation

@everpcpc
Copy link
Copy Markdown
Owner

Problem

Minimizing and reopening the app while reading in Divina scroll mode causes the reader to jump backward by 2 pages (or 1 page from even-numbered pages, then 2 on subsequent cycles).

Approach

The root cause is in centeredItem() which calculates the viewport center to find the nearest page. For UIScrollView, bounds.origin equals contentOffset, so bounds.midX already includes the content offset. The old code added contentOffset again, producing a center at 2 * contentOffset + width/2 instead of the correct contentOffset + width/2. This biased the nearest-item lookup toward wrong pages whenever multiple items were momentarily visible during app state transitions.

Additionally, the willResignActive notification handler dispatched via Task { @MainActor } which yields before executing, allowing the collection view state to change before the position was committed.

Scope

  • Fix centeredItem() center calculation to use bounds.midX/midY directly (matching the macOS implementation)
  • Switch notification handler from async Task to synchronous MainActor.assumeIsolated

Testing

  • iOS build passes
  • macOS build passes
  • Manual: read in Divina scroll mode, minimize and reopen — position should be preserved

…ound

Fix centeredItem() viewport center calculation that double-counted contentOffset.
UIScrollView.bounds.origin equals contentOffset, so bounds.midX already
includes the offset. Adding contentOffset again produced a center at
2*offset+width/2 instead of offset+width/2, biasing the nearest-item
lookup toward incorrect pages when multiple items were visible during
app state transitions.

Also switch the willResignActive notification handler from Task to
MainActor.assumeIsolated to eliminate the yield gap that allowed
collection view state to change before the position was committed.
@everpcpc everpcpc merged commit 1bf1a47 into main Mar 13, 2026
3 checks passed
@everpcpc everpcpc deleted the fix-jump branch March 13, 2026 12:52
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