From fa244b212e04adab547a29dd3b8fd7421f565dcf Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 15 Nov 2026 19:45:49 -0800 Subject: [PATCH] Update the swiped row on marking read/unread/starred (in iOS timeline) before animating back to position. --- .../MainTimelineViewController.swift | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 9e86e5455..8e07a0c24 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -26,6 +26,8 @@ final class MainTimelineViewController: UIViewController, UndoableCommandRunner private var feedNameAndDateAboveTitle = false private var showsFullTitles = false private var articleIDsToReload = Set() + /// The article whose row was just swiped to change its status. + private var swipedArticleID: String? private lazy var feedTapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(showFeedInspector(_:))) private lazy var filterButton = UIBarButtonItem(image: Assets.Images.filter, style: .plain, target: self, action: #selector(toggleFilter(_:))) private lazy var nextUnreadButton = UIBarButtonItem(image: Assets.Images.nextUnread, style: .plain, target: self, action: #selector(nextUnread(_:))) @@ -838,14 +840,8 @@ private extension MainTimelineViewController { NSLocalizedString("Starred", comment: "Starred") UIAccessibility.post(notification: .announcement, argument: announcement) - /// The call to `toggleStar` is delayed in order to allow - /// the swipe animation to complete. Calling `toggleStar` with no - /// delay results UICollectionView internal inconsistency: unexpected - /// removal of the current swipe occurrence’s mask view error. - DispatchQueue.main.asyncAfter(deadline: .now() + 0.85) { - self?.toggleStar(article) - } - + self?.swipedArticleID = article.articleID + self?.toggleStar(article) completion(true) } @@ -932,13 +928,8 @@ private extension MainTimelineViewController { NSLocalizedString("Marked as Read", comment: "Accessibility announcement") UIAccessibility.post(notification: .announcement, argument: announcement) - /// The call to `toggleRead` is delayed in order to allow - /// the swipe animation to complete. Calling `toggleRead` with no - /// delay results UICollectionView internal inconsistency: unexpected - /// removal of the current swipe occurrence’s mask view error. - DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.85) { - self?.toggleRead(article) - } + self?.swipedArticleID = article.articleID + self?.toggleRead(article) completion(true) } @@ -1156,8 +1147,20 @@ private extension MainTimelineViewController { return } - let visibleArticles = indexPaths.compactMap { dataSource.itemIdentifier(for: $0) } - let visibleUpdatedArticles = visibleArticles.filter { articleIDs.contains($0.articleID) } + var visibleUpdatedArticles = indexPaths.compactMap { dataSource.itemIdentifier(for: $0) }.filter { articleIDs.contains($0.articleID) } + + // The swiped row is updated in place, since a snapshot reload during the swipe animation triggers a UICollectionView + // “unexpected removal of the current swipe occurrence’s mask view” error. A status change doesn’t change a row’s height. + if let swipedArticleID, articleIDs.contains(swipedArticleID) { + self.swipedArticleID = nil + if let index = visibleUpdatedArticles.firstIndex(where: { $0.articleID == swipedArticleID }) { + let swipedArticle = visibleUpdatedArticles.remove(at: index) + if let indexPath = dataSource.indexPath(for: swipedArticle), let cell = collectionView.cellForItem(at: indexPath) as? MainTimelineCell { + cell.cellData = configure(article: swipedArticle) + } + } + } + reloadCells(visibleUpdatedArticles) }