Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scroll to article URL fragments (updated) #4434

Merged
merged 3 commits into from Jan 10, 2023

Conversation

junholee6a
Copy link
Contributor

Phabricator: https://phabricator.wikimedia.org/T321066

Notes

  • Currently, links with fragments (such as sections and equations) do not scroll to the fragment when opened in the app, unless that article is already open. This is fixed by adding the fragment to the web view's request before loading, which triggers the existing restoreScrollStateIfNecessary method to scroll the view to the fragment after the web view loads.
  • Currently, if the user has an article open in the app and clicks on a link to a fragment in that same article, nothing happens. This is fixed by adding a statement to scroll to the fragment in this case.
  • I made a similar PR before but used the show method when I should've used scroll, which caused the long-press context menu to immediately dismiss for article links with fragments. That was fixed here.

Test 1 Steps: External link with fragment, different article

  1. Make sure the “Juice” article is not currently open in the app
  2. Paste this link into Safari: https://en.wikipedia.org/wiki/Juice#Preparation
  3. Select the link and “Open in Wikipedia”
  4. Should open the “Juice” article in the app and scroll to the “Preparation” section

Test 2 Steps: Internal link with fragment, same article

  1. Open this article in the app: https://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors
  2. Scroll to the “Algebraic multiplicity” section
  3. Click the “Equation (4)” link
  4. Should scroll to equation 4

Adds a statement that scrolls to the given fragment. This statement is
run if the user has an article open and clicks a link to a fragment in
that same article, such as a link to a section or equation.
This causes the checkForScrollToAnchor method in ArticleViewController
to set scrollRestorationState to .scrollToAnchor once the webview
loads, which causes the restoreScrollStateIfNecessary method to scroll
the view to the fragment.
Copy link
Collaborator

@tonisevener tonisevener left a comment

Choose a reason for hiding this comment

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

Working well for me - thank you for this!

@tonisevener tonisevener merged commit cf4191c into wikimedia:main Jan 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants