diff --git a/iOS/Article/ArticleViewController.swift b/iOS/Article/ArticleViewController.swift index 3ff5f2ba8..81e537dc3 100644 --- a/iOS/Article/ArticleViewController.swift +++ b/iOS/Article/ArticleViewController.swift @@ -59,6 +59,14 @@ class ArticleViewController: UIViewController { } } + var restoreScrollPosition: (isShowingExtractedArticle: Bool, articleWindowScrollY: Int)? { + didSet { + if let rsp = restoreScrollPosition { + currentWebViewController?.setScrollPosition(isShowingExtractedArticle: rsp.isShowingExtractedArticle, articleWindowScrollY: rsp.articleWindowScrollY) + } + } + } + var currentState: State? { guard let controller = currentWebViewController else { return nil} return State(extractedArticle: controller.extractedArticle, @@ -125,6 +133,10 @@ class ArticleViewController: UIViewController { controller = createWebViewController(article, updateView: true) } + if let rsp = restoreScrollPosition { + controller.setScrollPosition(isShowingExtractedArticle: rsp.isShowingExtractedArticle, articleWindowScrollY: rsp.articleWindowScrollY) + } + articleExtractorButton.buttonState = controller.articleExtractorButtonState self.pageViewController.setViewControllers([controller], direction: .forward, animated: false, completion: nil) diff --git a/iOS/SceneCoordinator.swift b/iOS/SceneCoordinator.swift index 593b22748..147b66d09 100644 --- a/iOS/SceneCoordinator.swift +++ b/iOS/SceneCoordinator.swift @@ -461,8 +461,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { if let (feedIndexPath, articleID, isShowingExtractedArticle, articleWindowScrollY) = deferredFeedAndArticleSelect { selectFeed(indexPath: feedIndexPath) { - self.selectArticleInCurrentFeed(articleID) - self.articleViewController?.setScrollPosition(isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) + self.selectArticleInCurrentFeed(articleID, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) } } } @@ -836,7 +835,7 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { } } - func selectArticle(_ article: Article?, animations: Animations = []) { + func selectArticle(_ article: Article?, animations: Animations = [], isShowingExtractedArticle: Bool? = nil, articleWindowScrollY: Int? = nil) { guard article != currentArticle else { return } currentArticle = article @@ -866,6 +865,9 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { masterTimelineViewController?.updateArticleSelection(animations: animations) currentArticleViewController.article = article + if let isShowingExtractedArticle = isShowingExtractedArticle, let articleWindowScrollY = articleWindowScrollY { + currentArticleViewController.restoreScrollPosition = (isShowingExtractedArticle, articleWindowScrollY) + } } func beginSearching() { @@ -1284,9 +1286,9 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider { rootSplitViewController.preferredDisplayMode = rootSplitViewController.displayMode == .allVisible ? .primaryHidden : .allVisible } - func selectArticleInCurrentFeed(_ articleID: String) { + func selectArticleInCurrentFeed(_ articleID: String, isShowingExtractedArticle: Bool? = nil, articleWindowScrollY: Int? = nil) { if let article = self.articles.first(where: { $0.articleID == articleID }) { - self.selectArticle(article) + self.selectArticle(article, isShowingExtractedArticle: isShowingExtractedArticle, articleWindowScrollY: articleWindowScrollY) } }