mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Fix restore-selection bug on refreshing the timeline.
This commit is contained in:
1 parent
09b467f9d4
commit
c5625635de
2 files changed
+19
-12
No files matched your search
@@ -226,11 +226,10 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
Self.logger.debug("MainTimelineModernViewController: restoreSelectionIfNecessary selecting item and adjusting scroll")
|
||||
collectionView.selectItemAndScrollIfNotVisible(at: indexPath, animations: [])
|
||||
} else {
|
||||
if let indexPaths = collectionView.indexPathsForSelectedItems {
|
||||
if !indexPaths.contains(indexPath) {
|
||||
Self.logger.debug("MainTimelineModernViewController: restoreSelectionIfNecessary does not contain selected index path")
|
||||
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically)
|
||||
}
|
||||
let indexPaths = collectionView.indexPathsForSelectedItems ?? []
|
||||
if !indexPaths.contains(indexPath) {
|
||||
Self.logger.debug("MainTimelineModernViewController: restoreSelectionIfNecessary does not contain selected index path")
|
||||
collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -256,6 +255,7 @@ final class MainTimelineModernViewController: UIViewController, UndoableCommandR
|
||||
func reinitializeArticles(resetScroll: Bool) {
|
||||
Self.logger.debug("MainTimelineModernViewController: reinitializeArticles")
|
||||
resetUI(resetScroll: resetScroll)
|
||||
restoreSelectionIfNecessary(adjustScroll: false)
|
||||
}
|
||||
|
||||
func reloadArticles(animated: Bool) {
|
||||
|
||||
@@ -816,7 +816,7 @@ struct SidebarItemNode: Hashable, Sendable {
|
||||
if let article = self.currentArticle, let account = article.account {
|
||||
exceptionArticleFetcher = SingleArticleFetcher(account: account, articleID: article.articleID)
|
||||
}
|
||||
fetchAndReplaceArticlesAsync(animated: true) {
|
||||
fetchAndReplaceArticlesAsync(animated: true, emptyFirst: false) {
|
||||
self.mainTimelineViewController?.reinitializeArticles(resetScroll: resetScroll)
|
||||
}
|
||||
}
|
||||
@@ -2081,12 +2081,17 @@ private extension SceneCoordinator {
|
||||
if articles != sortedArticles {
|
||||
articles = sortedArticles
|
||||
|
||||
// Clear current article if it's no longer in the timeline.
|
||||
// Update currentArticle to the new instance if it's still in the timeline,
|
||||
// or clear it if it's no longer there.
|
||||
// Don't call selectArticle(nil) because that triggers navigation on iPhone.
|
||||
// Skip during state restoration so the restored article stays open.
|
||||
if !isRestoringState, let currentArticle, !sortedArticles.contains(where: { $0.articleID == currentArticle.articleID && $0.accountID == currentArticle.accountID }) {
|
||||
self.currentArticle = nil
|
||||
articleViewController?.article = nil
|
||||
if !isRestoringState, let currentArticle {
|
||||
if let newArticle = sortedArticles.first(where: { $0.articleID == currentArticle.articleID && $0.accountID == currentArticle.accountID }) {
|
||||
self.currentArticle = newArticle
|
||||
} else {
|
||||
self.currentArticle = nil
|
||||
articleViewController?.article = nil
|
||||
}
|
||||
}
|
||||
|
||||
updateShowNamesAndIcons()
|
||||
@@ -2139,11 +2144,13 @@ private extension SceneCoordinator {
|
||||
fetchRequestQueue.cancelAllRequests()
|
||||
}
|
||||
|
||||
func fetchAndReplaceArticlesAsync(animated: Bool, completion: @escaping () -> Void) {
|
||||
func fetchAndReplaceArticlesAsync(animated: Bool, emptyFirst: Bool = true, completion: @escaping () -> Void) {
|
||||
// To be called when we need to do an entire fetch, but an async delay is okay.
|
||||
// Example: we have the Today feed selected, and the calendar day just changed.
|
||||
cancelPendingAsyncFetches()
|
||||
emptyTheTimeline()
|
||||
if emptyFirst {
|
||||
emptyTheTimeline()
|
||||
}
|
||||
guard let timelineFeed = timelineFeed else {
|
||||
completion()
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user