mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-12-01 01:40:22 +00:00
Revert to direct cell access — it’s faster than using diffable data source APIs and avoids a race with animated snapshot applies.
This commit is contained in:
1 parent
c56bd57044
commit
469845f980
2 files changed
+43
-41
No files matched your search
@@ -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
|
||||
|
||||
@@ -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<String>, !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 {
|
||||
|
||||
Reference in new issue
Block a user