-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reader: RSS support improvements (#23751)
- Loading branch information
Showing
8 changed files
with
60 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ struct SiteIconView: View { | |
switch size { | ||
case .small: 18 | ||
case .regular: 24 | ||
case .large: 34 | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import SwiftUI | ||
|
||
struct ReaderSiteIconView: View, Hashable { | ||
let site: ReaderSiteTopic | ||
var size: SiteIconViewModel.Size = .small | ||
|
||
var body: some View { | ||
_ReaderSiteIconView(viewModel: .init(site: site, size: size)) | ||
.id(self) // important to ensure @StateObject is re-created if needed | ||
.frame(width: size.width, height: size.width) | ||
} | ||
} | ||
|
||
private struct _ReaderSiteIconView: View { | ||
@StateObject var viewModel: ReaderSiteIconViewModel | ||
|
||
var body: some View { | ||
SiteIconView(viewModel: viewModel.icon) | ||
.task { await viewModel.refresh() } | ||
} | ||
} | ||
|
||
@MainActor | ||
final class ReaderSiteIconViewModel: ObservableObject { | ||
@Published private(set) var icon: SiteIconViewModel | ||
|
||
let site: ReaderSiteTopic | ||
let size: SiteIconViewModel.Size | ||
|
||
init(site: ReaderSiteTopic, size: SiteIconViewModel.Size) { | ||
self.site = site | ||
self.size = size | ||
self.icon = SiteIconViewModel(readerSiteTopic: site, size: size) | ||
} | ||
|
||
func refresh() async { | ||
if site.isExternal, icon.imageURL == nil, let siteURL = URL(string: site.siteURL) { | ||
if let faviconURL = FaviconService.shared.cachedFavicon(forURL: siteURL) { | ||
icon.imageURL = faviconURL | ||
} else { | ||
icon.imageURL = try? await FaviconService.shared.favicon(forURL: siteURL) | ||
} | ||
} | ||
} | ||
} |