8000 Keep the translation scroll position after sharing an ayah by marouanebatrone · Pull Request #4054 · quran/quran_android · GitHub
[go: up one dir, main page]

Skip to content

Keep the translation scroll position after sharing an ayah - #4054

Open
marouanebatrone wants to merge 1 commit into
quran:mainfrom
marouanebatrone:fix/translation-scroll-position
Open

marouanebatrone wants to merge 1 commit into
quran:mainfrom
marouanebatrone:fix/translation-scroll-position

Conversation

@marouanebatrone
Copy link
Copy Markdown

Assalamu alaikum,

Fixes #2248.

What

In translation mode, sharing an ayah (long-press → Share → text) and then closing the share sheet scrolled the translation list back to the top of the page, so the reader lost their place. This happens in single-page translation mode; dual-page translation on tablets already kept its place.

How

TranslationFragment saves its scroll position only in onSaveInstanceState, but TranslationPresenter.refresh() restored that saved position after every refresh, and the fragment refreshes whenever it resumes. While the share sheet is open, PagerActivity is only paused, so no state is saved. When the reader comes back, the stale value is applied again: that's the top of the page unless the page was recreated.

TranslationPresenter now restores the saved position only the first time the verses are shown. Later refreshes leave the list where the reader scrolled it.

  • A recreated page still restores its saved position: after rotation, or when a page that left the pager's window comes back, the fragment and its @QuranPageScope presenter are new.
  • With two pages (dual-page translation), the first load still restores after each page, as before.

Tests

  • New TranslationPresenterTest (Robolectric, using the existing fakes plus a small FakeTranslationScreen):
    • refreshing again keeps the position the reader scrolled to fails on main (expected: 1, but was: 2 restores) and passes with this change.
    • The other two tests pin the existing first-load behaviour and pass both before and after.
  • Everything CI runs, locally on JDK 27, all passed (675 unit tests, 0 failures):
    • assembleMadaniDebug
    • lintMadaniDebug
    • verifySqlDelightMigration
    • testMadaniDebug testReleaseUnitTest -PdisableFirebase
  • API 37 emulator, comparing debug builds of main (280bf44) and this branch with the same scripted steps: page 2, translation mode, scroll so 2:3 is at the top, long-press an ayah, Share → text, Back.
    • Phone, light, dark and Arabic UI: main jumps back to 2:1; this branch stays on 2:3.
    • Phone: rotating portrait → landscape → portrait still restores 2:3, and swiping to the next page and back keeps it. Same as main.
    • Pixel Tablet, dual-page translation: both lists keep their position after sharing, on main and on this branch.
  • Not verified:
    • other Android versions (I only have an API 37 image here);
    • physical devices;
    • process death.

Screenshots

After scrolling to 2:3, sharing an ayah's text and closing the share sheet:

Before (main) After (this PR)
Light main, light: back at 2:1 this PR, light: still at 2:3
Dark main, dark: back at 2:1 this PR, dark: still at 2:3
Arabic UI main, Arabic UI: back at 2:1 this PR, Arabic UI: still at 2:3

TranslationFragment only saves its scroll position in
onSaveInstanceState, but TranslationPresenter restored that saved
position after every refresh. The fragment refreshes whenever it
resumes, so coming back from something that only pauses the activity,
such as the share sheet, scrolled the list back to the stale saved
position (the top of the page unless the page was recreated).

Only restore the saved position the first time the verses are shown,
so later refreshes keep the position the reader scrolled to. Rotation
still restores the position, since it creates a new fragment and
presenter.

Fixes quran#2248.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

Scroll positioning in translation view lost on share

1 participant

0