Skip to content

Keep the reader's place in an article across a rotation - #5507

Open
dave-atx wants to merge 1 commit into
Ranchero-Software:mainfrom
dave-atx:fix-article-scroll-position-on-rotation
Open

dave-atx wants to merge 1 commit into
Ranchero-Software:mainfrom
dave-atx:fix-article-scroll-position-on-rotation

Conversation

@dave-atx

Copy link
Copy Markdown
Contributor

Rotating a device from landscape to portrait and back loses your place in the article, dropping you somewhere else in the text.

The recorded position is window.scrollY, an absolute pixel offset baked into the rendered page. Rotating reflows the article at a new width, so the paragraph that was at that offset is no longer there. The web view also scrolls on its own partway through the transition, and scrollViewDidScroll records those intermediate offsets over the one worth keeping.

The fix notes the element at the top of the viewport along with its offset, ignores scrolling while the view is changing size, and scrolls back to that element once the transition finishes. An element survives the reflow in a way a pixel offset can't.

Verified on an iPhone Duo. I first noticed it on an iPad, where it's easiest to reproduce — open an article, scroll into the middle, rotate, rotate back.

The recorded scroll position is window.scrollY, an absolute pixel offset
baked into the rendered page. Rotating reflows the article at a new width,
so that offset points somewhere else. The web view also scrolls on its own
during the transition, overwriting the stored position before anything can
restore it.

Record the element at the top of the viewport along with its offset, stop
recording while the view changes size, and scroll back to that element once
the transition ends.

Verified on an iPhone Duo. The same loss happens on iPad, which is where I
first noticed it.
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