mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-28 00:04:25 +00:00
Use accountID + articleID for key in timeline, to avoid row-height-measurement confusion which caused a too-many-layout-passes crash.
This commit is contained in:
1 parent
798c6fc580
commit
1c66fd474b
1 file changed
+15
-9
@@ -189,7 +189,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
}
|
||||
private var estimatedRowHeight: CGFloat = 0.0 // For rows not yet measured
|
||||
private var rowHeights = [String: TimelineRowHeight]() // articleID: height measured at rowHeightWidth
|
||||
private var rowHeights = [ArticleIdentityKey: TimelineRowHeight]() // Height measured at rowHeightWidth
|
||||
private var rowHeightWidth: CGFloat = 0.0 // The width of a standard-layout cell
|
||||
private var rowHeightMeasuringStartRow: Int? // Where the next measuring pass starts
|
||||
private var isRowHeightMeasuringScheduled = false
|
||||
@@ -272,9 +272,15 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
private static let readArticleAlphaValue: CGFloat = 0.6
|
||||
|
||||
private struct ArticleIdentityKey: Equatable {
|
||||
/// Two accounts can have articles with the same articleID — the same feed in On My Mac and iCloud, for instance.
|
||||
private struct ArticleIdentityKey: Hashable {
|
||||
let accountID: String
|
||||
let articleID: String
|
||||
|
||||
init(_ article: Article) {
|
||||
self.accountID = article.accountID
|
||||
self.articleID = article.articleID
|
||||
}
|
||||
}
|
||||
|
||||
/// A changed article is a new instance, so `article` tells whether the height is still current.
|
||||
@@ -1010,7 +1016,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
|
||||
/// Nil when the row hasn’t been measured, or its article changed since.
|
||||
private func measuredRowHeight(for article: Article) -> CGFloat? {
|
||||
guard let rowHeight = rowHeights[article.articleID], rowHeight.article === article else {
|
||||
guard let rowHeight = rowHeights[ArticleIdentityKey(article)], rowHeight.article === article else {
|
||||
return nil
|
||||
}
|
||||
return rowHeight.height
|
||||
@@ -1021,7 +1027,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
let cellData = TimelineCellData(article: article, showFeedName: showFeedNames, feedName: article.feed?.nameForDisplay, byline: article.byline(), iconImage: nil, showIcon: showIcons, thumbnail: nil, showThumbnail: showThumbnail)
|
||||
let appearance: TimelineCellAppearance = showIcons ? cellAppearanceWithIcon : cellAppearance
|
||||
let height = TimelineCellLayout.height(for: rowHeightWidth, cellData: cellData, appearance: appearance)
|
||||
rowHeights[article.articleID] = TimelineRowHeight(article: article, showsThumbnail: showThumbnail, height: height)
|
||||
rowHeights[ArticleIdentityKey(article)] = TimelineRowHeight(article: article, showsThumbnail: showThumbnail, height: height)
|
||||
}
|
||||
|
||||
private func articleShowsThumbnail(_ article: Article) -> Bool {
|
||||
@@ -1041,7 +1047,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
guard let article = articles.articleAtRow(row) else {
|
||||
continue
|
||||
}
|
||||
rowHeights[article.articleID] = nil
|
||||
rowHeights[ArticleIdentityKey(article)] = nil
|
||||
if measuresNow {
|
||||
measureRowHeight(for: article)
|
||||
}
|
||||
@@ -1062,7 +1068,7 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
private func remeasureRowsWhoseThumbnailChanged() {
|
||||
var rows = IndexSet()
|
||||
for (row, article) in articles.enumerated() {
|
||||
if let rowHeight = rowHeights[article.articleID], rowHeight.showsThumbnail != articleShowsThumbnail(article) {
|
||||
if let rowHeight = rowHeights[ArticleIdentityKey(article)], rowHeight.showsThumbnail != articleShowsThumbnail(article) {
|
||||
rows.insert(row)
|
||||
}
|
||||
}
|
||||
@@ -1070,8 +1076,8 @@ final class TimelineViewController: NSViewController, UndoableCommandRunner, Unr
|
||||
}
|
||||
|
||||
private func removeRowHeightsForMissingArticles() {
|
||||
let articleIDs = Set(articles.articleIDs())
|
||||
rowHeights = rowHeights.filter { articleIDs.contains($0.key) }
|
||||
let articleKeys = Set(articles.map { ArticleIdentityKey($0) })
|
||||
rowHeights = rowHeights.filter { articleKeys.contains($0.key) }
|
||||
}
|
||||
|
||||
/// A width change makes every height stale. Rows near the visible ones are measured during layout, the rest in passes.
|
||||
@@ -1378,7 +1384,7 @@ extension TimelineViewController: NSTableViewDelegate {
|
||||
// Compare by identity, not content — re-pushing an updated article that the user is reading
|
||||
// would reset the article view scroll position.
|
||||
// <https://github.com/Ranchero-Software/NetNewsWire/issues/5387>
|
||||
let selectedArticleKeys = selectedArticles?.map { ArticleIdentityKey(accountID: $0.accountID, articleID: $0.articleID) }
|
||||
let selectedArticleKeys = selectedArticles?.map { ArticleIdentityKey($0) }
|
||||
guard selectedArticleKeys != previouslySelectedArticleKeys else {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user