From c8b6c5344c7194e2ef3336446919b66714062560 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Sun, 23 Aug 2026 00:47:56 +0000 Subject: Restore scroll position within an article on Next/Previous Next/Previous replaces this screen's own back-stack entry with a fresh one for the neighboring article, which recreates the WebView from scratch -- going back to an article you'd been partway through always landed you back at the top. Tracks each article's scroll offset in an in-memory, process-lifetime map (ReaderScrollPositions) as the WebView scrolls, and restores it once the freshly-loaded page finishes laying out. --- app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt') diff --git a/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt b/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt index 4c74e5a..2bdaf64 100644 --- a/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt +++ b/app/src/main/java/org/terst/feedreader/ui/ReaderScreen.kt @@ -519,7 +519,12 @@ private fun ReaderContent( ctx, onOpenLink, onLongPressLink = { longPressedLink = it }, - onYouTubeVideo = { youtubeVideoId = it } + onYouTubeVideo = { youtubeVideoId = it }, + onScrollChanged = { scrollY -> ReaderScrollPositions.set(articleId, scrollY) }, + // The page's real content height isn't known until layout finishes + // -- scrolling to a saved offset any earlier would just clamp back + // to 0 on a page that hasn't grown tall enough yet. + onPageFinished = { webView -> webView.scrollTo(0, ReaderScrollPositions.get(articleId)) } ).apply { loadDataWithBaseURL(baseUrl, wrapReaderHtml(content, article?.title, article?.publishedAt, article?.imageUrl), "text/html", "UTF-8", null) loadedContent.value = content -- cgit v1.2.3