mirror of
https://github.com/Ranchero-Software/NetNewsWire.git
synced 2025-01-11 17:24:04 +01:00
Make sure image loaders don't loop if onAppear gets repeatedly called
This commit is contained in:
parent
e7e3a0d5d7
commit
ee4d8b34b1
@ -23,6 +23,7 @@ final class ArticleIconImageLoader: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadImage(for article: Article) {
|
func loadImage(for article: Article) {
|
||||||
|
guard image == nil else { return }
|
||||||
self.article = article
|
self.article = article
|
||||||
image = article.iconImage()
|
image = article.iconImage()
|
||||||
}
|
}
|
||||||
@ -50,7 +51,7 @@ private extension ArticleIconImageLoader {
|
|||||||
|
|
||||||
for author in authors {
|
for author in authors {
|
||||||
if author.avatarURL == avatarURL {
|
if author.avatarURL == avatarURL {
|
||||||
|
image = article.iconImage()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,8 +21,27 @@ final class FeedIconImageLoader: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func loadImage(for feed: Feed) {
|
func loadImage(for feed: Feed) {
|
||||||
|
guard image == nil else { return }
|
||||||
self.feed = feed
|
self.feed = feed
|
||||||
|
fetchImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private extension FeedIconImageLoader {
|
||||||
|
|
||||||
|
@objc func faviconDidBecomeAvailable(_ note: Notification) {
|
||||||
|
fetchImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func webFeedIconDidBecomeAvailable(_ note: Notification) {
|
||||||
|
guard let feed = feed as? WebFeed, let noteFeed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed, feed == noteFeed else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fetchImage()
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchImage() {
|
||||||
if let webFeed = feed as? WebFeed {
|
if let webFeed = feed as? WebFeed {
|
||||||
if let feedIconImage = appDelegate.webFeedIconDownloader.icon(for: webFeed) {
|
if let feedIconImage = appDelegate.webFeedIconDownloader.icon(for: webFeed) {
|
||||||
image = feedIconImage
|
image = feedIconImage
|
||||||
@ -40,19 +59,3 @@ final class FeedIconImageLoader: ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private extension FeedIconImageLoader {
|
|
||||||
|
|
||||||
@objc func faviconDidBecomeAvailable(_ note: Notification) {
|
|
||||||
guard let feed = feed else { return }
|
|
||||||
loadImage(for: feed)
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func webFeedIconDidBecomeAvailable(_ note: Notification) {
|
|
||||||
guard let feed = feed as? WebFeed, let noteFeed = note.userInfo?[UserInfoKey.webFeed] as? WebFeed, feed == noteFeed else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
loadImage(for: feed)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -24,7 +24,7 @@ struct TimelineItemView: View {
|
|||||||
VStack {
|
VStack {
|
||||||
Text(verbatim: timelineItem.article.title ?? "N/A")
|
Text(verbatim: timelineItem.article.title ?? "N/A")
|
||||||
.fontWeight(.semibold)
|
.fontWeight(.semibold)
|
||||||
.lineLimit(3)
|
.lineLimit(AppDefaults.timelineNumberOfLines)
|
||||||
.frame(maxWidth: .infinity, alignment: .leading)
|
.frame(maxWidth: .infinity, alignment: .leading)
|
||||||
.padding(.trailing, 4)
|
.padding(.trailing, 4)
|
||||||
Spacer()
|
Spacer()
|
||||||
|
Loading…
Reference in New Issue
Block a user