From 469845f9803b24a014e608945c40b5e7610d183a Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 22 Jan 2026 16:55:54 -0800 Subject: [PATCH] =?UTF-8?q?Revert=20to=20direct=20cell=20access=20?= =?UTF-8?q?=E2=80=94=C2=A0it=E2=80=99s=20faster=20than=20using=20diffable?= =?UTF-8?q?=20data=20source=20APIs=20and=20avoids=20a=20race=20with=20anim?= =?UTF-8?q?ated=20snapshot=20applies.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MainFeedCollectionViewController.swift | 32 +++++------- .../MainTimelineViewController.swift | 52 +++++++++++-------- 2 files changed, 43 insertions(+), 41 deletions(-) diff --git a/iOS/MainFeed/MainFeedCollectionViewController.swift b/iOS/MainFeed/MainFeedCollectionViewController.swift index 59790cc89..d3466b5da 100644 --- a/iOS/MainFeed/MainFeedCollectionViewController.swift +++ b/iOS/MainFeed/MainFeedCollectionViewController.swift @@ -625,16 +625,19 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab return } - let visibleIndexPaths = collectionView.indexPathsForVisibleItems - let itemsToReconfigure = visibleIndexPaths.compactMap { indexPath -> SidebarItemNode? in - guard let sidebarItemNode = dataSource.itemIdentifier(for: indexPath), + for cell in collectionView.visibleCells { + guard let indexPath = collectionView.indexPath(for: cell), + let sidebarItemNode = dataSource.itemIdentifier(for: indexPath), sidebarItemNode.node.representedObject === unreadCountProvider as AnyObject else { - return nil + continue + } + if let feedCell = cell as? MainFeedCollectionViewCell { + feedCell.unreadCount = unreadCountProvider.unreadCount + } + if let folderCell = cell as? MainFeedCollectionViewFolderCell { + folderCell.unreadCount = unreadCountProvider.unreadCount } - return sidebarItemNode } - - reloadCells(itemsToReconfigure) } @objc func feedSettingDidChange(_ note: Notification) { @@ -647,25 +650,14 @@ final class MainFeedCollectionViewController: UICollectionViewController, Undoab } @objc func faviconDidBecomeAvailable(_ note: Notification) { - reloadAllVisibleCells() + applyToAvailableCells(configureIcon) } @objc func feedIconDidBecomeAvailable(_ note: Notification) { guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else { return } - - let visibleIndexPaths = collectionView.indexPathsForVisibleItems - let itemsToReconfigure = visibleIndexPaths.compactMap { indexPath -> SidebarItemNode? in - guard let sidebarItemNode = dataSource.itemIdentifier(for: indexPath), - let candidateSidebarItem = sidebarItemNode.node.representedObject as? SidebarItem, - feed.sidebarItemID == candidateSidebarItem.sidebarItemID else { - return nil - } - return sidebarItemNode - } - - reloadCells(itemsToReconfigure) + applyToCellsForRepresentedObject(feed, configureIcon(_:_:)) } // MARK: - Actions diff --git a/iOS/MainTimeline/MainTimelineViewController.swift b/iOS/MainTimeline/MainTimelineViewController.swift index 006e906a8..b48de9f30 100644 --- a/iOS/MainTimeline/MainTimelineViewController.swift +++ b/iOS/MainTimeline/MainTimelineViewController.swift @@ -614,7 +614,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu @objc func statusesDidChange(_ note: Notification) { Self.logger.debug("MainTimelineViewController: statusesDidChange") - guard isViewLoaded, view.window != nil else { + guard isViewLoaded else { return } guard let articleIDs = note.userInfo?[Account.UserInfoKey.articleIDs] as? Set, !articleIDs.isEmpty else { @@ -626,13 +626,27 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu let visibleArticles = indexPaths.compactMap { dataSource.itemIdentifier(for: $0) } let visibleUpdatedArticles = visibleArticles.filter { articleIDs.contains($0.articleID) } - reloadCells(visibleUpdatedArticles) + + for article in visibleUpdatedArticles { + if let indexPath = dataSource.indexPath(for: article) { + if let cell = tableView.cellForRow(at: indexPath) as? MainTimelineIconFeedCell { + let cellData = configure(article: article) + cell.cellData = cellData + cell.indexPathRow = indexPath.row + } + if let cell = tableView.cellForRow(at: indexPath) as? MainTimelineFeedCell { + let cellData = configure(article: article) + cell.cellData = cellData + cell.indexPathRow = indexPath.row + } + } + } } @objc func feedIconDidBecomeAvailable(_ note: Notification) { Self.logger.debug("MainTimelineViewController: feedIconDidBecomeAvailable") - guard isViewLoaded, view.window != nil else { + guard isViewLoaded else { return } guard let feed = note.userInfo?[UserInfoKey.feed] as? Feed else { @@ -645,7 +659,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu @objc func avatarDidBecomeAvailable(_ note: Notification) { Self.logger.debug("MainTimelineViewController: avatarDidBecomeAvailable") - guard isViewLoaded, view.window != nil else { + guard isViewLoaded else { return } guard showIcons, let avatarURL = note.userInfo?[UserInfoKey.url] as? String else { @@ -655,26 +669,22 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu return } - let articlesToReload = indexPaths.compactMap { indexPath -> Article? in - guard let article = dataSource.itemIdentifier(for: indexPath), - let authors = article.authors, - !authors.isEmpty else { - return nil + for indexPath in indexPaths { + guard let article = dataSource.itemIdentifier(for: indexPath), let authors = article.authors, !authors.isEmpty else { + continue } for author in authors { - if author.avatarURL == avatarURL { - return article + if author.avatarURL == avatarURL, let cell = tableView.cellForRow(at: indexPath) as? MainTimelineIconFeedCell, let image = iconImageFor(article) { + cell.setIconImage(image) } } - return nil } - reloadCells(articlesToReload) } @objc func faviconDidBecomeAvailable(_ note: Notification) { Self.logger.debug("MainTimelineViewController: faviconDidBecomeAvailable") - guard isViewLoaded, view.window != nil else { + guard isViewLoaded else { return } @@ -683,7 +693,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu /// Update icon for all visible articles — or, if feed is non-nil, update articles only from that feed. private func updateIconForVisibleArticles(_ feed: Feed? = nil) { - guard isViewLoaded, view.window != nil else { + guard isViewLoaded else { return } guard showIcons else { @@ -693,16 +703,16 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu return } - let articlesToReload = indexPaths.compactMap { indexPath -> Article? in + for indexPath in indexPaths { guard let article = dataSource.itemIdentifier(for: indexPath) else { - return nil + continue } if feed == nil || feed == article.feed { - return article + if let cell = tableView.cellForRow(at: indexPath) as? MainTimelineIconFeedCell, let image = iconImageFor(article) { + cell.setIconImage(image) + } } - return nil } - reloadCells(articlesToReload) } func userDefaultsDidChange() { @@ -743,7 +753,7 @@ final class MainTimelineViewController: UITableViewController, UndoableCommandRu } @objc private func reloadAllVisibleCells() { - guard isViewLoaded, view.window != nil else { + guard isViewLoaded else { return } guard let indexPaths = tableView.indexPathsForVisibleRows else {