From 600ad8ff17a893a688e0ab9025a8a18e6e6b2621 Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 6 Jan 2025 16:03:19 -0500 Subject: [PATCH 1/6] Fix code formatting and remove unused imports --- .../Site Picker/BlogList/SiteIconView.swift | 1 - .../ShareModularViewController.swift | 26 +++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconView.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconView.swift index 65a761cdc047..908b728a6fb2 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconView.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconView.swift @@ -2,7 +2,6 @@ import UIKit import SwiftUI import AsyncImageKit import DesignSystem -import WordPressShared struct SiteIconView: View { let viewModel: SiteIconViewModel diff --git a/WordPress/WordPressShareExtension/ShareModularViewController.swift b/WordPress/WordPressShareExtension/ShareModularViewController.swift index e4f9b7e5403a..a4b099e7ba1e 100644 --- a/WordPress/WordPressShareExtension/ShareModularViewController.swift +++ b/WordPress/WordPressShareExtension/ShareModularViewController.swift @@ -981,24 +981,24 @@ fileprivate extension ShareModularViewController { fileprivate extension ShareModularViewController { struct Constants { - static let sitesReuseIdentifier = String(describing: ShareSitesTableViewCell.self) - static let modulesReuseIdentifier = String(describing: ShareModularViewController.self) - static let siteRowHeight = CGFloat(74.0) - static let defaultRowHeight = CGFloat(44.0) - static let flashAnimationLength = 0.2 - static let unknownDefaultCategoryID = NSNumber(value: -1) - static let unknownDefaultCategoryName = AppLocalizedString("Default", comment: "Placeholder text displayed in the share extension's summary view. It lets the user know the default category will be used on their post.") + static let sitesReuseIdentifier = String(describing: ShareSitesTableViewCell.self) + static let modulesReuseIdentifier = String(describing: ShareModularViewController.self) + static let siteRowHeight = CGFloat(74.0) + static let defaultRowHeight = CGFloat(44.0) + static let flashAnimationLength = 0.2 + static let unknownDefaultCategoryID = NSNumber(value: -1) + static let unknownDefaultCategoryName = AppLocalizedString("Default", comment: "Placeholder text displayed in the share extension's summary view. It lets the user know the default category will be used on their post.") } struct SummaryText { - static let summaryPostPublishing = AppLocalizedString("Publish post on:", comment: "Text displayed in the share extension's summary view. It describes the publish post action.") - static let summaryDraftPostDefault = AppLocalizedString("Save draft post on:", comment: "Text displayed in the share extension's summary view that describes the save draft post action.") + static let summaryPostPublishing = AppLocalizedString("Publish post on:", comment: "Text displayed in the share extension's summary view. It describes the publish post action.") + static let summaryDraftPostDefault = AppLocalizedString("Save draft post on:", comment: "Text displayed in the share extension's summary view that describes the save draft post action.") static let summaryDraftPostSingular = AppLocalizedString("Save 1 photo as a draft post on:", comment: "Text displayed in the share extension's summary view that describes the action of saving a single photo in a draft post.") - static let summaryDraftPostPlural = AppLocalizedString("Save %ld photos as a draft post on:", comment: "Text displayed in the share extension's summary view that describes the action of saving multiple photos in a draft post.") - static let summaryPagePublishing = AppLocalizedString("Publish page on:", comment: "Text displayed in the share extension's summary view. It describes the publish page action.") - static let summaryDraftPageDefault = AppLocalizedString("Save draft page on:", comment: "Text displayed in the share extension's summary view that describes the save draft page action.") + static let summaryDraftPostPlural = AppLocalizedString("Save %ld photos as a draft post on:", comment: "Text displayed in the share extension's summary view that describes the action of saving multiple photos in a draft post.") + static let summaryPagePublishing = AppLocalizedString("Publish page on:", comment: "Text displayed in the share extension's summary view. It describes the publish page action.") + static let summaryDraftPageDefault = AppLocalizedString("Save draft page on:", comment: "Text displayed in the share extension's summary view that describes the save draft page action.") static let summaryDraftPageSingular = AppLocalizedString("Save 1 photo as a draft page on:", comment: "Text displayed in the share extension's summary view that describes the action of saving a single photo in a draft page.") - static let summaryDraftPagePlural = AppLocalizedString("Save %ld photos as a draft page on:", comment: "Text displayed in the share extension's summary view that describes the action of saving multiple photos in a draft page.") + static let summaryDraftPagePlural = AppLocalizedString("Save %ld photos as a draft page on:", comment: "Text displayed in the share extension's summary view that describes the action of saving multiple photos in a draft page.") } struct StatusText { From c966dc61b1b1e93d7cc71c82811ebec9e797edce Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 6 Jan 2025 16:30:44 -0500 Subject: [PATCH 2/6] Move SiteIconView to WordPressUI --- Modules/Package.swift | 10 ++- .../Resources/Assets.xcassets/Contents.json | 6 +- .../vector.imageset/Contents.json | 16 +++++ .../vector.imageset/Vector.pdf | Bin 0 -> 1883 bytes .../WordPressUI/Views}/SiteIconView.swift | 57 +++++++++++++++--- .../Classes/Models/ReaderPost+Swift.swift | 1 + .../Detail Header/BlogDetailHeaderView.swift | 1 + .../SiteDetailsSiteIconView.swift | 1 + .../BlogList/BlogListSiteView.swift | 1 + ...ift => SiteIconViewModel+Extensions.swift} | 32 ++-------- .../Gutenberg/GutenbergViewController.swift | 1 + .../Views/NotificationSettingsSiteView.swift | 1 + .../PrepublishingHeaderView.swift | 1 + .../Reader/Cards/ReaderPostCell.swift | 1 + .../Reader/Controllers/ReaderFeedCell.swift | 3 +- .../ReaderSubscriptionCell.swift | 1 + .../Reader/Views/ReaderSiteIconView.swift | 1 + 17 files changed, 93 insertions(+), 41 deletions(-) create mode 100644 Modules/Sources/WordPressUI/Resources/Assets.xcassets/vector.imageset/Contents.json create mode 100644 Modules/Sources/WordPressUI/Resources/Assets.xcassets/vector.imageset/Vector.pdf rename {WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList => Modules/Sources/WordPressUI/Views}/SiteIconView.swift (69%) rename WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/{SiteIconViewModel.swift => SiteIconViewModel+Extensions.swift} (89%) diff --git a/Modules/Package.swift b/Modules/Package.swift index 85e1bb172ba3..fafa8e6cd200 100644 --- a/Modules/Package.swift +++ b/Modules/Package.swift @@ -66,7 +66,15 @@ let package = Package( .target(name: "WordPressSharedObjC", resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]), .target(name: "WordPressShared", dependencies: [.target(name: "WordPressSharedObjC")], resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]), .target(name: "WordPressTesting", resources: [.process("Resources")]), - .target(name: "WordPressUI", dependencies: [.target(name: "WordPressShared")], resources: [.process("Resources")], swiftSettings: [.swiftLanguageMode(.v5)]), + .target( + name: "WordPressUI", + dependencies: [ + "AsyncImageKit", + .target(name: "WordPressShared") + ], + resources: [.process("Resources")], + swiftSettings: [.swiftLanguageMode(.v5)] + ), .testTarget(name: "JetpackStatsWidgetsCoreTests", dependencies: [.target(name: "JetpackStatsWidgetsCore")], swiftSettings: [.swiftLanguageMode(.v5)]), .testTarget(name: "DesignSystemTests", dependencies: [.target(name: "DesignSystem")], swiftSettings: [.swiftLanguageMode(.v5)]), .testTarget(name: "WordPressFluxTests", dependencies: ["WordPressFlux"], swiftSettings: [.swiftLanguageMode(.v5)]), diff --git a/Modules/Sources/WordPressUI/Resources/Assets.xcassets/Contents.json b/Modules/Sources/WordPressUI/Resources/Assets.xcassets/Contents.json index da4a164c9186..73c00596a7fc 100644 --- a/Modules/Sources/WordPressUI/Resources/Assets.xcassets/Contents.json +++ b/Modules/Sources/WordPressUI/Resources/Assets.xcassets/Contents.json @@ -1,6 +1,6 @@ { "info" : { - "version" : 1, - "author" : "xcode" + "author" : "xcode", + "version" : 1 } -} \ No newline at end of file +} diff --git a/Modules/Sources/WordPressUI/Resources/Assets.xcassets/vector.imageset/Contents.json b/Modules/Sources/WordPressUI/Resources/Assets.xcassets/vector.imageset/Contents.json new file mode 100644 index 000000000000..4bdc4947b421 --- /dev/null +++ b/Modules/Sources/WordPressUI/Resources/Assets.xcassets/vector.imageset/Contents.json @@ -0,0 +1,16 @@ +{ + "images" : [ + { + "filename" : "Vector.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "preserves-vector-representation" : true, + "template-rendering-intent" : "template" + } +} diff --git a/Modules/Sources/WordPressUI/Resources/Assets.xcassets/vector.imageset/Vector.pdf b/Modules/Sources/WordPressUI/Resources/Assets.xcassets/vector.imageset/Vector.pdf new file mode 100644 index 0000000000000000000000000000000000000000..d4c9dab9b0a3c604cbf432efb232f52c313ee618 GIT binary patch literal 1883 zcmZuyO;6iE5WVlOmI)D`= zlQ%o>&4)ccxm{hKt0)&jfrReoF9C3I0rC2Iytx~z(YSwV`l&0BQ7Y{PmzVA%OuMyV zA~}lxY}(!U2q}UaJSc{-H`PJJEAw|>o6XG?Ebr$3>OuSw@mj%d5GtA^B#L?CoUOM$ zcGU+Vqa@WyxxmO^WJ$izFx0ImiBA<|9mImn05YXwCqv9pqnb~TPqD!+KF&xj-eC>e zOc5aFz)(&+kjyOha!3fM#pA32S)`}r;UH8RDQ7E2XVyDjX2*m$q=-t#(g>xAv5az0 zokoeZ6et;GjFGUUbI6!DqUmH_+6xe)7#S5lI-y%JFxFV%!nq47un`%}iL+^hCYq8A z9cd@#PbtvERgyYpM~UX-#B#}NCKLebAblMAM;J$LRL#u6>QgTcFrXBw*ZP)->kA5PHCK0HGSL0o+39J%J*B+NGRLA2tVu=~v~FWPi= zsku$55}EJ<#H}-1pdZ?{8wa@mfeRI{`1`-#2IAXlXFTx5Z1>ew_YC)8&vBc=V;d}D z+L)nx>T5HAUD+E?x9r-{w5VwJFoCyKj~HkV;U1fGf z)vq9pB_2aMDPBXF41r@`?Hkhz`}+I1!gibv-NBr}>3)0Wni6liZUkHK)ZqAT|KDKt U)9bD3$Eh5ZWlEf!tiN8r0H UIMenu? diff --git a/WordPress/Classes/ViewRelated/Blog/Blog Details/Detail Header/SiteDetailsSiteIconView.swift b/WordPress/Classes/ViewRelated/Blog/Blog Details/Detail Header/SiteDetailsSiteIconView.swift index b69f148e58c1..d4a4e419c004 100644 --- a/WordPress/Classes/ViewRelated/Blog/Blog Details/Detail Header/SiteDetailsSiteIconView.swift +++ b/WordPress/Classes/ViewRelated/Blog/Blog Details/Detail Header/SiteDetailsSiteIconView.swift @@ -1,4 +1,5 @@ import UIKit +import WordPressUI final class SiteDetailsSiteIconView: UIView { diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/BlogListSiteView.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/BlogListSiteView.swift index d701c2809db8..8ee2a7bd9525 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/BlogListSiteView.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/BlogListSiteView.swift @@ -1,4 +1,5 @@ import SwiftUI +import WordPressUI import WordPressShared struct BlogListSiteView: View { diff --git a/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconViewModel.swift b/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconViewModel+Extensions.swift similarity index 89% rename from WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconViewModel.swift rename to WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconViewModel+Extensions.swift index 8daaa23b1785..aa49a5f98592 100644 --- a/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconViewModel.swift +++ b/WordPress/Classes/ViewRelated/Blog/Site Picker/BlogList/SiteIconViewModel+Extensions.swift @@ -3,33 +3,12 @@ import SwiftUI import WordPressShared import WordPressKit import AsyncImageKit +import WordPressUI -struct SiteIconViewModel { - var imageURL: URL? - var firstLetter: Character? - var size: Size - var host: MediaHost? - - enum Size { - case small - case regular - case large - - var width: CGFloat { - switch self { - case .small: 28 - case .regular: 40 - case .large: 72 - } - } - - var size: CGSize { - CGSize(width: width, height: width) - } - } - +extension SiteIconViewModel { init(blog: Blog, size: Size = .regular) { - self.size = size + self.init(size: size) + self.firstLetter = blog.title?.first if blog.hasIcon, let icon = blog.icon { @@ -39,7 +18,8 @@ struct SiteIconViewModel { } init(readerSiteTopic: ReaderSiteTopic, size: Size = .regular) { - self.size = size + self.init(size: size) + self.firstLetter = readerSiteTopic.title.first self.imageURL = SiteIconViewModel.makeReaderSiteIconURL( iconURL: readerSiteTopic.siteBlavatar, diff --git a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift index 8fb10799e061..bf503b28f924 100644 --- a/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift +++ b/WordPress/Classes/ViewRelated/Gutenberg/GutenbergViewController.swift @@ -4,6 +4,7 @@ import Gutenberg import Aztec import WordPressFlux import WordPressShared +import WordPressUI import React import AutomatticTracks import Combine diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationSettingsSiteView.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationSettingsSiteView.swift index 299f952c75f2..973979ebc43e 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationSettingsSiteView.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationSettingsSiteView.swift @@ -1,5 +1,6 @@ import Foundation import SwiftUI +import WordPressUI struct NotificationSettingsSiteView: View { let viewModel: NotificationSettingsSiteViewModel diff --git a/WordPress/Classes/ViewRelated/Post/Prepublishing Nudge/PrepublishingHeaderView.swift b/WordPress/Classes/ViewRelated/Post/Prepublishing Nudge/PrepublishingHeaderView.swift index 2233a5113d1a..c60b6c400548 100644 --- a/WordPress/Classes/ViewRelated/Post/Prepublishing Nudge/PrepublishingHeaderView.swift +++ b/WordPress/Classes/ViewRelated/Post/Prepublishing Nudge/PrepublishingHeaderView.swift @@ -1,4 +1,5 @@ import UIKit +import WordPressUI final class PrepublishingHeaderView: UIView { private let blogImageView = SiteIconHostingView() diff --git a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift index 0d98025c8c78..27922ffe48ee 100644 --- a/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift @@ -1,6 +1,7 @@ import SwiftUI import UIKit import Combine +import WordPressUI import WordPressShared import AsyncImageKit diff --git a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderFeedCell.swift b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderFeedCell.swift index 68be211e6f0b..6b90262ebb00 100644 --- a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderFeedCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderFeedCell.swift @@ -1,4 +1,5 @@ import SwiftUI +import WordPressUI import WordPressKit struct ReaderFeedCell: View { @@ -25,7 +26,7 @@ struct ReaderFeedCell: View { extension SiteIconViewModel { init(feed: ReaderFeed, size: Size = .regular) { - self.size = size + self.init(size: size) if let iconURL = feed.blavatarURL { self.imageURL = SiteIconViewModel.optimizedURL(for: iconURL.absoluteString, imageSize: size.size) } diff --git a/WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionCell.swift b/WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionCell.swift index bf8589559671..49575ab2542f 100644 --- a/WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionCell.swift +++ b/WordPress/Classes/ViewRelated/Reader/Subscriptions/ReaderSubscriptionCell.swift @@ -1,4 +1,5 @@ import SwiftUI +import WordPressUI struct ReaderSubscriptionCell: View { let site: ReaderSiteTopic diff --git a/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift b/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift index c1eca881cc4d..339720cdaa06 100644 --- a/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift +++ b/WordPress/Classes/ViewRelated/Reader/Views/ReaderSiteIconView.swift @@ -1,5 +1,6 @@ import SwiftUI import AsyncImageKit +import WordPressUI struct ReaderSiteIconView: View, Hashable { let site: ReaderSiteTopic From a6775eb22babebb5fe3b80c759770b98c21e23af Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 6 Jan 2025 17:04:36 -0500 Subject: [PATCH 3/6] Update Share extension to use SiteIconView --- Modules/Package.swift | 1 + .../NotificationSettingsViewController.swift | 14 ++-- .../ShareModularViewController.swift | 71 +++++++++---------- .../WPStyleGuide+Share.swift | 21 ------ 4 files changed, 43 insertions(+), 64 deletions(-) diff --git a/Modules/Package.swift b/Modules/Package.swift index fafa8e6cd200..1f999d2b80ce 100644 --- a/Modules/Package.swift +++ b/Modules/Package.swift @@ -201,6 +201,7 @@ enum XcodeSupport { .xcodeTarget("XcodeTarget_StatsWidget", dependencies: [ "JetpackStatsWidgetsCore", "WordPressShared", + "WordPressUI", .product(name: "CocoaLumberjackSwift", package: "CocoaLumberjack"), .product(name: "WordPressAPI", package: "wordpress-rs"), .product(name: "ColorStudio", package: "color-studio"), diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift index 181ee7c1a0d1..57c6905b1ca6 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift @@ -331,11 +331,15 @@ private extension NotificationSettingsViewController { labelView.translatesAutoresizingMaskIntoConstraints = false let textProvider = JetpackBrandingTextProvider(screen: JetpackBadgeScreen.notificationsSettings) - let badgeView = JetpackButton.makeBadgeView(title: textProvider.brandingText(), - topPadding: FooterMetrics.jetpackBadgeTopPadding, - bottomPadding: FooterMetrics.jetpackBadgeBottomPatting, - target: self, - selector: #selector(jetpackButtonTapped)) + let badgeView = JetpackButton.makeBadgeView( + title: textProvider.brandingText(), + topPadding: FooterMetrics.jetpackBadgeTopPadding, + bottomPadding: FooterMetrics.jetpackBadgeBottomPatting, + target: self, + selector: #selector( + jetpackButtonTapped + ) + ) badgeView.translatesAutoresizingMaskIntoConstraints = false let stackView = UIStackView(arrangedSubviews: [labelView, badgeView]) diff --git a/WordPress/WordPressShareExtension/ShareModularViewController.swift b/WordPress/WordPressShareExtension/ShareModularViewController.swift index a4b099e7ba1e..7d1dd3566ac7 100644 --- a/WordPress/WordPressShareExtension/ShareModularViewController.swift +++ b/WordPress/WordPressShareExtension/ShareModularViewController.swift @@ -1,6 +1,8 @@ import UIKit +import SwiftUI import WordPressKit import WordPressShared +import WordPressUI class ShareModularViewController: ShareExtensionAbstractViewController { @@ -185,7 +187,7 @@ class ShareModularViewController: ShareExtensionAbstractViewController { fileprivate func setupSitesTableView() { // Register the cells - sitesTableView.register(ShareSitesTableViewCell.self, forCellReuseIdentifier: Constants.sitesReuseIdentifier) + sitesTableView.register(UITableViewCell.self, forCellReuseIdentifier: Constants.sitesReuseIdentifier) sitesTableView.estimatedRowHeight = Constants.siteRowHeight // Hide the separators, whenever the table is empty @@ -564,34 +566,17 @@ fileprivate extension ShareModularViewController { return } - // Site's Details - let displayURL = URL(string: site.url)?.host ?? "" - if let name = site.name.nonEmptyString() { - cell.textLabel?.text = name - cell.detailTextLabel?.isEnabled = true - cell.detailTextLabel?.text = displayURL - } else { - cell.textLabel?.text = displayURL - cell.detailTextLabel?.isEnabled = false - cell.detailTextLabel?.text = nil - } + cell.selectionStyle = .none - // Site's Blavatar - cell.imageView?.image = WPStyleGuide.Share.blavatarPlaceholderImage - if let siteIconPath = site.icon, - let siteIconUrl = URL(string: siteIconPath) { - cell.imageView?.downloadBlavatar(from: siteIconUrl) - } else { - cell.imageView?.image = WPStyleGuide.Share.blavatarPlaceholderImage - } + cell.contentConfiguration = UIHostingConfiguration { + ShareSiteCellView(site: site) + }.margins(.vertical, 12) if site.blogID.intValue == shareData.selectedSiteID { cell.accessoryType = .checkmark } else { cell.accessoryType = .none } - - WPStyleGuide.Share.configureTableViewSiteCell(cell) } var rowCountForSites: Int { @@ -599,10 +584,7 @@ fileprivate extension ShareModularViewController { } func selectedSitesTableRowAt(_ indexPath: IndexPath) { - sitesTableView.flashRowAtIndexPath(indexPath, - scrollPosition: .none, - flashLength: Constants.flashAnimationLength, - completion: nil) + sitesTableView.flashRowAtIndexPath(indexPath, scrollPosition: .none, flashLength: Constants.flashAnimationLength, completion: nil) guard let cell = sitesTableView.cellForRow(at: indexPath), let site = siteForRowAtIndexPath(indexPath), @@ -981,7 +963,7 @@ fileprivate extension ShareModularViewController { fileprivate extension ShareModularViewController { struct Constants { - static let sitesReuseIdentifier = String(describing: ShareSitesTableViewCell.self) + static let sitesReuseIdentifier = "sitesReuseIdentifier" static let modulesReuseIdentifier = String(describing: ShareModularViewController.self) static let siteRowHeight = CGFloat(74.0) static let defaultRowHeight = CGFloat(44.0) @@ -1020,18 +1002,31 @@ private enum Strings { // MARK: - UITableView Cells -class ShareSitesTableViewCell: WPTableViewCell { - - // MARK: - Initializers - public required init?(coder aDecoder: NSCoder) { - super.init(coder: aDecoder) - } - - public required override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { - super.init(style: .subtitle, reuseIdentifier: reuseIdentifier) +private struct ShareSiteCellView: View { + let site: RemoteBlog + let size: SiteIconViewModel.Size = .regular + + var body: some View { + HStack(alignment: .center, spacing: 16) { + SiteIconView(viewModel: SiteIconViewModel(site: site)) + .frame(width: size.width, height: size.width) + VStack(alignment: .leading) { + HStack(alignment: .center) { + Text(site.name) + .font(.callout.weight(.medium)) + } + Text(URL(string: site.url)?.host ?? "") + .font(.footnote) + .foregroundStyle(.secondary) + } + .lineLimit(1) + } } +} - public convenience init() { - self.init(style: .subtitle, reuseIdentifier: nil) +private extension SiteIconViewModel { + init(site: RemoteBlog) { + self.init(size: .regular) + self.imageURL = site.icon.flatMap(URL.init) } } diff --git a/WordPress/WordPressShareExtension/WPStyleGuide+Share.swift b/WordPress/WordPressShareExtension/WPStyleGuide+Share.swift index 737e312a3b6c..6dca1692df24 100644 --- a/WordPress/WordPressShareExtension/WPStyleGuide+Share.swift +++ b/WordPress/WordPressShareExtension/WPStyleGuide+Share.swift @@ -5,8 +5,6 @@ extension WPStyleGuide { // MARK: - Styles Used by the WordPress Share Extension // class Share { - static let blavatarPlaceholderImage = UIImage(named: "blavatar-default") - static func configureModuleCell(_ cell: UITableViewCell) { cell.textLabel?.font = tableviewTextFont() cell.textLabel?.sizeToFit() @@ -68,24 +66,5 @@ extension WPStyleGuide { cell.backgroundColor = UIColor.clear cell.separatorInset = UIEdgeInsets.zero } - - static func configureTableViewSiteCell(_ cell: UITableViewCell) { - cell.textLabel?.font = tableviewTextFont() - cell.textLabel?.sizeToFit() - cell.textLabel?.textColor = .label - cell.textLabel?.numberOfLines = 0 - - cell.detailTextLabel?.font = subtitleFont() - cell.detailTextLabel?.sizeToFit() - cell.detailTextLabel?.textColor = .secondaryLabel - cell.detailTextLabel?.numberOfLines = 0 - - cell.imageView?.layer.borderColor = UIColor.white.cgColor - cell.imageView?.layer.borderWidth = 1 - cell.imageView?.tintColor = UIAppColor.neutral(.shade30) - - cell.backgroundColor = .secondarySystemGroupedBackground - cell.tintColor = UIAppColor.primary - } } } From 7c33ae7d5c892294a623dfbb7e79dda2d54a9495 Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 6 Jan 2025 17:05:40 -0500 Subject: [PATCH 4/6] Remove UIImageView+Blavatar --- .../Extensions/UIImageView+Blavatar.swift | 58 ------------------- 1 file changed, 58 deletions(-) delete mode 100644 Modules/Sources/WordPressUI/Extensions/UIImageView+Blavatar.swift diff --git a/Modules/Sources/WordPressUI/Extensions/UIImageView+Blavatar.swift b/Modules/Sources/WordPressUI/Extensions/UIImageView+Blavatar.swift deleted file mode 100644 index bc4b0414a71f..000000000000 --- a/Modules/Sources/WordPressUI/Extensions/UIImageView+Blavatar.swift +++ /dev/null @@ -1,58 +0,0 @@ -import Foundation -import UIKit - -public extension UIImageView { - - /// Downloads a resized Blavatar, meant to perfectly fit the UIImageView's Dimensions - /// - /// - Parameter url: The URL of the target blavatar - /// - func downloadBlavatar(from url: URL) { - var components = URLComponents(url: url, resolvingAgainstBaseURL: true) - components?.query = String(format: Downloader.blavatarResizeFormat, blavatarSize) - - guard let updatedURL = components?.url else { - assertionFailure() - return - } - - let size = CGSize(width: blavatarSizeInPoints, height: blavatarSizeInPoints) - downloadResizedImage(from: updatedURL, pointSize: size) - } - - /// Returns the desired Blavatar Side-Size, in pixels - /// - private var blavatarSize: Int { - return blavatarSizeInPoints * Int(mainScreenScale) - } - - /// Returns the desired Blavatar Side-Size, in points - /// - private var blavatarSizeInPoints: Int { - var size = Downloader.defaultImageSize - - if !bounds.size.equalTo(.zero) { - size = max(bounds.width, bounds.height) - } - - return Int(size) - } - - /// Returns the Main Screen Scale - /// - private var mainScreenScale: CGFloat { - return UIScreen.main.scale - } - - /// Private helper structure - /// - private struct Downloader { - /// Default Blavatar Image Size - /// - static let defaultImageSize = CGFloat(40) - - /// Blavatar Resize Query FormatString - /// - static let blavatarResizeFormat = "d=404&s=%d" - } -} From 119f4ccff993fa3d177b60f354c717a2933c41b0 Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 6 Jan 2025 17:07:35 -0500 Subject: [PATCH 5/6] Use firstLetter --- .../WordPressShareExtension/ShareModularViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/WordPressShareExtension/ShareModularViewController.swift b/WordPress/WordPressShareExtension/ShareModularViewController.swift index 7d1dd3566ac7..9093b6de4e66 100644 --- a/WordPress/WordPressShareExtension/ShareModularViewController.swift +++ b/WordPress/WordPressShareExtension/ShareModularViewController.swift @@ -1027,6 +1027,7 @@ private struct ShareSiteCellView: View { private extension SiteIconViewModel { init(site: RemoteBlog) { self.init(size: .regular) + self.firstLetter = blog.name.first self.imageURL = site.icon.flatMap(URL.init) } } From 0862ef18c8399bf37129bb81f8a8d45248281238 Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 6 Jan 2025 17:08:56 -0500 Subject: [PATCH 6/6] Update release notes --- RELEASE-NOTES.txt | 2 +- .../WordPressShareExtension/ShareModularViewController.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES.txt b/RELEASE-NOTES.txt index 9dc4a9881152..5c15bbe78c7c 100644 --- a/RELEASE-NOTES.txt +++ b/RELEASE-NOTES.txt @@ -15,7 +15,7 @@ * [*] Fix an issue with Referrers in Stats showing invalid icons [#23943] * [*] Update site menu style on iPhone [#23944] * [*] Integrate zoom transitions in Themes, Reader [#23945, #23947] - +* [*] Fix an issue with site icons cropped in share extensions [#23950] 25.6 ----- diff --git a/WordPress/WordPressShareExtension/ShareModularViewController.swift b/WordPress/WordPressShareExtension/ShareModularViewController.swift index 9093b6de4e66..f8afd9189d2c 100644 --- a/WordPress/WordPressShareExtension/ShareModularViewController.swift +++ b/WordPress/WordPressShareExtension/ShareModularViewController.swift @@ -1027,7 +1027,7 @@ private struct ShareSiteCellView: View { private extension SiteIconViewModel { init(site: RemoteBlog) { self.init(size: .regular) - self.firstLetter = blog.name.first + self.firstLetter = site.name.first self.imageURL = site.icon.flatMap(URL.init) } }