Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, andscrollViewDidScrollrecords 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.