From 56463eeb48491ea6e9603e960e5478f70bb32f27 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Wed, 8 May 2024 16:14:29 -0600 Subject: [PATCH 01/11] Redesign like notification details content --- .../DesignSystem/Foundation/IconName.swift | 2 + .../reader.follow.imageset/Contents.json | 16 ++ .../reader.follow.imageset/reader-follow.pdf | Bin 0 -> 972 bytes .../reader.following.imageset/Contents.json | 16 ++ .../reader-following.pdf | Bin 0 -> 1005 bytes .../Likes/LikesListController.swift | 14 +- .../NotificationDetailsViewController.swift | 4 +- .../Views/LikeUserTableViewCell.swift | 85 ++++----- .../Views/LikeUserTableViewCell.xib | 73 +------- .../Views/NotificationDetailUserView.swift | 174 ++++++++++++++++++ WordPress/WordPress.xcodeproj/project.pbxproj | 6 + 11 files changed, 267 insertions(+), 123 deletions(-) create mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json create mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/reader-follow.pdf create mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.following.imageset/Contents.json create mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.following.imageset/reader-following.pdf create mode 100644 WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift diff --git a/Modules/Sources/DesignSystem/Foundation/IconName.swift b/Modules/Sources/DesignSystem/Foundation/IconName.swift index 4e6287501223..8d47e92fecd0 100644 --- a/Modules/Sources/DesignSystem/Foundation/IconName.swift +++ b/Modules/Sources/DesignSystem/Foundation/IconName.swift @@ -24,6 +24,8 @@ public enum IconName: String, CaseIterable { case arrowUp = "arrow.up" case arrowDown = "arrow.down" case vector = "vector" + case readerFollow = "reader.follow" + case readerFollowing = "reader.following" } // MARK: - Load Image diff --git a/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json b/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json new file mode 100644 index 000000000000..d443994dae33 --- /dev/null +++ b/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json @@ -0,0 +1,16 @@ +{ + "images" : [ + { + "filename" : "reader-follow.pdf", + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + }, + "properties" : { + "preserves-vector-representation" : true, + "template-rendering-intent" : "template" + } +} diff --git a/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/reader-follow.pdf b/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/reader-follow.pdf new file mode 100644 index 0000000000000000000000000000000000000000..27fa36c2d19d7be22ffa9aacd474c8b215267596 GIT binary patch literal 972 zcmY!laBPWcrI(FQ;PBNHHs<9RbDa8uW zpnwjFMY0JLXfTaFsd?!o845;57F_ynnK>mu=j*%W03GL&nw+1K3er_v0`x^LSH+y% zi3j6d+oe`bidj1ty_e)9e@3M;`-lqq{@_|K9@7MZz!ux`|{a1RR8POx~M?ulWn4F z#MM$`R`5>xz2cjcK~V6-MaOu0-iWQ;v{gPWcrI(FQ;PBNHHs<9RbDa8uW zpnwjFMY0JLXfTaFsd?!o845;bK;>?kIVC{n>$~Lu9p{pooS%{k(p6jn^hGXL#hl!U zzF9{Mcv`>Pwdw`*&i}tC$2;-b+hyzqm*r3JOgS)T|D-uBhfMgYHvLiDdt||i*PK#8 z3+s688RMh^xhF1v^>d;{>PgclOE%4Tu{-19Q|&#MbsIL@FTQ*KY<+T^yf=UA<A9+_l!`^BF@JqOGev?6-B9OTm}jjTn2EUU}kD+Y^so^024E|0481#P{>1w z83W@FP0Yj?n4ZwY49zgr8JJpPs53AG#xt5;BU50Kg^86EC1&QN7J>6-aAs91(8>Bi p`S~RZpo9m^X`Xp$`3j))3{K+3C5c5PV85B08*r(ry863u0RU=dN(BG_ literal 0 HcmV?d00001 diff --git a/WordPress/Classes/ViewRelated/Likes/LikesListController.swift b/WordPress/Classes/ViewRelated/Likes/LikesListController.swift index d028b02cf9e2..1626d574cc44 100644 --- a/WordPress/Classes/ViewRelated/Likes/LikesListController.swift +++ b/WordPress/Classes/ViewRelated/Likes/LikesListController.swift @@ -403,13 +403,22 @@ private extension LikesListController { } func userCell(for indexPath: IndexPath) -> UITableViewCell { - guard let user = likingUsers[safe: indexPath.row], + guard let parent = parent, + let user = likingUsers[safe: indexPath.row], let cell = tableView.dequeueReusableCell(withIdentifier: LikeUserTableViewCell.defaultReuseID) as? LikeUserTableViewCell else { DDLogError("Failed dequeueing LikeUserTableViewCell") return UITableViewCell() } + cell.configure( + avatarURL: URL(string: user.avatarUrl), + username: user.displayName, + blog: String(format: Constants.usernameFormat, user.username), + onUserClicked: { [weak self] in + self?.delegate?.didSelectUser(user, at: indexPath) + }, + parent: parent + ) - cell.configure(withUser: user, isLastRow: (indexPath.row == likingUsers.endIndex - 1)) return cell } @@ -429,6 +438,7 @@ private extension LikesListController { static let headerSectionIndex = 0 static let headerRowIndex = 0 static let numberOfHeaderRows = 1 + static let usernameFormat = NSLocalizedString("@%1$@", comment: "Label displaying the user's username preceeded by an '@' symbol. %1$@ is a placeholder for the username.") } struct Strings { diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index d225d156e51a..371f5518eec8 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -355,7 +355,7 @@ extension NotificationDetailsViewController { } func setupMainView() { - view.backgroundColor = note.isBadge ? .ungroupedListBackground : .listBackground + view.backgroundColor = .ungroupedListBackground } func setupTableView() { @@ -363,7 +363,7 @@ extension NotificationDetailsViewController { tableView.keyboardDismissMode = .interactive tableView.accessibilityIdentifier = .notificationDetailsTableAccessibilityId tableView.accessibilityLabel = NSLocalizedString("Notification Details Table", comment: "Notifications Details Accessibility Identifier") - tableView.backgroundColor = note.isBadge ? .ungroupedListBackground : .listBackground + tableView.backgroundColor = .ungroupedListBackground } func setupTableViewCells() { diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift index 2ef714f1b345..a52d70874b0b 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift @@ -1,65 +1,54 @@ import Foundation +import SwiftUI class LikeUserTableViewCell: UITableViewCell, NibReusable { - - // MARK: - Properties - - @IBOutlet weak var gravatarImageView: CircularImageView! - @IBOutlet weak var nameLabel: UILabel! - @IBOutlet weak var usernameLabel: UILabel! - @IBOutlet weak var separatorView: UIView! - @IBOutlet weak var separatorHeightConstraint: NSLayoutConstraint! - @IBOutlet weak var separatorLeadingConstraint: NSLayoutConstraint! - @IBOutlet weak var cellStackViewLeadingConstraint: NSLayoutConstraint! - static let estimatedRowHeight: CGFloat = 80 - private typealias Style = WPStyleGuide.Notifications - // MARK: - View + private var controller: UIHostingController? - override func awakeFromNib() { - super.awakeFromNib() - configureCell() + func configure(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void, parent: UIViewController) { + let view = NotificationDetailUserView(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked) + host(view, parent: parent) } - // MARK: - Public Methods - - func configure(withUser user: LikeUser, isLastRow: Bool = false) { - nameLabel.text = user.displayName - usernameLabel.text = String(format: Constants.usernameFormat, user.username) - downloadGravatarWithURL(user.avatarUrl) - separatorLeadingConstraint.constant = isLastRow ? 0 : cellStackViewLeadingConstraint.constant + func configure( + avatarURL: URL?, + username: String?, + blog: String?, + isFollowed: Bool, + onUserClicked: @escaping () -> Void, + onFollowClicked: @escaping (Bool) -> Void, + parent: UIViewController + ) { + let view = NotificationDetailUserView( + avatarURL: avatarURL, + username: username, + blog: blog, + isFollowed: isFollowed, + onUserClicked: onUserClicked, + onFollowClicked: onFollowClicked + ) + host(view, parent: parent) } -} - -// MARK: - Private Extension + private func host(_ content: NotificationDetailUserView, parent: UIViewController) { + if let controller = controller { + controller.rootView = content + controller.view.layoutIfNeeded() + } else { + let cellViewController = UIHostingController(rootView: content) + controller = cellViewController -private extension LikeUserTableViewCell { + parent.addChild(cellViewController) + contentView.addSubview(cellViewController.view) + cellViewController.view.translatesAutoresizingMaskIntoConstraints = false + layout(hostingView: cellViewController.view) - func configureCell() { - nameLabel.textColor = Style.blockTextColor - usernameLabel.textColor = .textSubtle - backgroundColor = Style.blockBackgroundColor - separatorView.backgroundColor = Style.blockSeparatorColor - separatorHeightConstraint.constant = .hairlineBorderWidth - } - - func downloadGravatarWithURL(_ url: String?) { - // Always reset gravatar - gravatarImageView.cancelImageDownload() - gravatarImageView.image = .gravatarPlaceholderImage - - guard let url = url, - let gravatarURL = URL(string: url) else { - return + cellViewController.didMove(toParent: parent) } - - gravatarImageView.downloadImage(from: gravatarURL, placeholderImage: .gravatarPlaceholderImage) } - struct Constants { - static let usernameFormat = NSLocalizedString("@%1$@", comment: "Label displaying the user's username preceeded by an '@' symbol. %1$@ is a placeholder for the username.") + func layout(hostingView view: UIView) { + self.contentView.pinSubviewToAllEdges(view) } - } diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib index 43b23f19547e..928aa21a2d18 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib +++ b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib @@ -1,11 +1,9 @@ - + - - - + @@ -17,75 +15,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift new file mode 100644 index 000000000000..aab75199fced --- /dev/null +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift @@ -0,0 +1,174 @@ +import SwiftUI +import DesignSystem + +struct NotificationDetailUserView: View { + typealias FollowConfig = NotificationDetailUserView.FollowActionConfiguration + + let config: Configuration + + init(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void) { + self.config = Configuration(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked) + } + + init( + avatarURL: URL?, + username: String?, + blog: String?, + isFollowed: Bool, + onUserClicked: @escaping () -> Void, + onFollowClicked: @escaping (Bool) -> Void + ) { + self.config = Configuration( + avatarURL: avatarURL, + username: username, + blog: blog, + followActionConfig: FollowConfig(isFollowed: isFollowed, onFollowClicked: onFollowClicked), + onUserClicked: onUserClicked + ) + } + + var body: some View { + HStack { + Button(action: config.onUserClicked) { + HStack(spacing: .DS.Padding.split) { + AvatarsView(style: .single(config.avatarURL)) + VStack(alignment: .leading) { + if let username = config.username { + Text(username) + .style(.bodySmall(.regular)) + .foregroundStyle(Color.DS.Foreground.primary) + .lineLimit(1) + } + if let blog = config.blog { + Text(blog) + .style(.bodySmall(.regular)) + .foregroundStyle(Color.DS.Foreground.secondary) + .lineLimit(1) + } + } + Spacer() + } + } + if let followAction = config.followActionConfig { + FollowButton(config: followAction) + } + } + .padding(.horizontal, .DS.Padding.double) + .padding(.top, .DS.Padding.double) + } + + struct Configuration { + let avatarURL: URL? + let username: String? + let blog: String? + let followActionConfig: FollowActionConfiguration? + let onUserClicked: () -> Void + + init( + avatarURL: URL?, + username: String?, + blog: String?, + followActionConfig: FollowActionConfiguration? = nil, + onUserClicked: @escaping () -> Void + ) { + self.avatarURL = avatarURL + self.username = username + self.blog = blog + self.followActionConfig = followActionConfig + self.onUserClicked = onUserClicked + } + } + + struct FollowActionConfiguration { + let isFollowed: Bool + let onFollowClicked: (Bool) -> Void + } + +} + +private struct FollowButton: View { + @State private var isFollowed: Bool + let onFollowClicked: (Bool) -> Void + + init(config: NotificationDetailUserView.FollowActionConfiguration) { + self._isFollowed = State(initialValue: config.isFollowed) + self.onFollowClicked = config.onFollowClicked + } + + var body: some View { + Button(action: { + isFollowed.toggle() + onFollowClicked(isFollowed) + }) { + HStack(spacing: .DS.Padding.half) { + if isFollowed { + Image.DS.icon(named: .readerFollowing) + .resizable() + .scaledToFit() + .frame(width: 14, height: 14) + .foregroundColor(Color.DS.Foreground.success) + Text(Follow.selectedTitle) + .style(.bodySmall(.regular)) + .accessibilityHint(Follow.selectedHint) + .foregroundStyle(Color.DS.Foreground.success) + } else { + Image.DS.icon(named: .readerFollow) + .resizable() + .scaledToFit() + .frame(width: 14, height: 14) + .foregroundColor(Color.DS.Foreground.secondary) + Text(Follow.title) + .style(.bodySmall(.regular)) + .accessibilityHint(Follow.hint) + .foregroundStyle(Color.DS.Foreground.secondary) + } + } + } + } +} + +public struct ImageConfiguration { + let url: URL? + let placeholder: Image? + + public init(url: URL?, placeholder: Image? = nil) { + self.url = url + self.placeholder = placeholder + } + + public init(url: String?, placeholder: Image? = nil) { + self.init(url: URL(string: url ?? ""), placeholder: placeholder) + } +} + +#Preview { + VStack(alignment: .leading) { + NotificationDetailUserView( + avatarURL: URL(string: "https://i.pravatar.cc/300"), + username: "Alex Turner", + blog: "@alexturner", + isFollowed: false, + onUserClicked: {}, + onFollowClicked: { _ in } + ) + NotificationDetailUserView( + avatarURL: URL(string: "invalid-url"), + username: "Jordan Fisher", + blog: "@jordanfisher", + onUserClicked: {} + ) + NotificationDetailUserView( + avatarURL: URL(string: "https://i.pravatar.cc/400"), + username: "Casey Hart", + blog: nil, + onUserClicked: {} + ) + NotificationDetailUserView( + avatarURL: URL(string: "https://i.pravatar.cc/600"), + username: nil, + blog: "@emilystanton", + onUserClicked: {} + ) + } + .padding(.horizontal, .DS.Padding.double) +} diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index f4d071bdd4d2..573dc3f6c265 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -1732,6 +1732,8 @@ 74FA4BE51FBFA0660031EAAD /* Extensions.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 74FA4BE31FBFA0660031EAAD /* Extensions.xcdatamodeld */; }; 74FA4BE61FBFA0660031EAAD /* Extensions.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 74FA4BE31FBFA0660031EAAD /* Extensions.xcdatamodeld */; }; 74FA4BED1FBFA2350031EAAD /* SharedCoreDataStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 746D6B241FBF701F003C45BE /* SharedCoreDataStack.swift */; }; + 776D09F32BEC01B500DE07A1 /* NotificationDetailUserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776D09F22BEC01B500DE07A1 /* NotificationDetailUserView.swift */; }; + 776D09F42BEC01B500DE07A1 /* NotificationDetailUserView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 776D09F22BEC01B500DE07A1 /* NotificationDetailUserView.swift */; }; 77A141172B68546100BF75DD /* BooleanUserDefaultsDebugViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77A141162B68546100BF75DD /* BooleanUserDefaultsDebugViewModelTests.swift */; }; 77B84EFE2B62D8280035AEFE /* BooleanUserDefaultsDebugView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77B84EFD2B62D8280035AEFE /* BooleanUserDefaultsDebugView.swift */; }; 77DFF0882B68362200FA561D /* BooleanUserDefaultsDebugViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 77DFF0872B68362200FA561D /* BooleanUserDefaultsDebugViewModel.swift */; }; @@ -7424,6 +7426,7 @@ 74FA2EE3200E8A6C001DDC13 /* AppExtensionsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppExtensionsService.swift; sourceTree = ""; }; 74FA4BE41FBFA0660031EAAD /* Extensions.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Extensions.xcdatamodel; sourceTree = ""; }; 75305C06D345590B757E3890 /* Pods-Apps-WordPress.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Apps-WordPress.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Apps-WordPress/Pods-Apps-WordPress.debug.xcconfig"; sourceTree = ""; }; + 776D09F22BEC01B500DE07A1 /* NotificationDetailUserView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationDetailUserView.swift; sourceTree = ""; }; 77A141162B68546100BF75DD /* BooleanUserDefaultsDebugViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooleanUserDefaultsDebugViewModelTests.swift; sourceTree = ""; }; 77B84EFD2B62D8280035AEFE /* BooleanUserDefaultsDebugView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooleanUserDefaultsDebugView.swift; sourceTree = ""; }; 77DFF0872B68362200FA561D /* BooleanUserDefaultsDebugViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BooleanUserDefaultsDebugViewModel.swift; sourceTree = ""; }; @@ -16083,6 +16086,7 @@ B5C66B711ACF071000F68370 /* NoteBlockTextTableViewCell.xib */, B52C4C7C199D4CD3009FD823 /* NoteBlockUserTableViewCell.swift */, B5C66B791ACF074600F68370 /* NoteBlockUserTableViewCell.xib */, + 776D09F22BEC01B500DE07A1 /* NotificationDetailUserView.swift */, FEDDD46E26A03DE900F8942B /* ListTableViewCell+Notifications.swift */, ); path = Views; @@ -23417,6 +23421,7 @@ 8236EB502024ED8C007C7CF9 /* NotificationsViewController+JetpackPrompt.swift in Sources */, C3234F4E27EB96A9004ADB29 /* IntentCell.swift in Sources */, 5D732F971AE84E3C00CD89E7 /* PostListFooterView.m in Sources */, + 776D09F32BEC01B500DE07A1 /* NotificationDetailUserView.swift in Sources */, 1767494E1D3633A000B8D1D1 /* ThemeBrowserSearchHeaderView.swift in Sources */, 0857C2781CE5375F0014AE99 /* MenuItemInsertionView.m in Sources */, 98ED5963265EBD0000A0B33E /* ReaderDetailLikesListController.swift in Sources */, @@ -24453,6 +24458,7 @@ FE7B9A8B2A6BD20200488791 /* PrepublishingSocialAccountsTableFooterView.swift in Sources */, FABB20E62602FC2C00C8785C /* TitleSubtitleHeader.swift in Sources */, FABB20E82602FC2C00C8785C /* AppAppearance.swift in Sources */, + 776D09F42BEC01B500DE07A1 /* NotificationDetailUserView.swift in Sources */, FABB20E92602FC2C00C8785C /* ReaderTabViewController.swift in Sources */, FE4DC5A8293A84E6008F322F /* MigrationDeepLinkRouter.swift in Sources */, 77DFF0892B68386800FA561D /* BooleanUserDefaultsDebugViewModel.swift in Sources */, From 301b7466bc3ce3a1d58ca89fedc2994edb72a079 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Thu, 9 May 2024 09:58:58 -0600 Subject: [PATCH 02/11] Redesign followers notification details content --- .../NotificationDetailsViewController.swift | 45 ++++-- .../Views/NoteBlockUserTableViewCell.swift | 140 +++++------------- .../Views/NoteBlockUserTableViewCell.xib | 96 +----------- 3 files changed, 68 insertions(+), 213 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index 371f5518eec8..f7be156eb36a 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -671,24 +671,37 @@ private extension NotificationDetailsViewController { let hasHomeURL = userBlock.metaLinksHome != nil let hasHomeTitle = userBlock.metaTitlesHome?.isEmpty == false + let isFollowEnabled = userBlock.isActionEnabled(id: FollowAction.actionIdentifier()) - cell.accessoryType = hasHomeURL ? .disclosureIndicator : .none - cell.name = userBlock.text - cell.blogTitle = hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host - cell.isFollowEnabled = userBlock.isActionEnabled(id: FollowAction.actionIdentifier()) - cell.isFollowOn = userBlock.isActionOn(id: FollowAction.actionIdentifier()) - - cell.onFollowClick = { [weak self] in - self?.followSiteWithBlock(userBlock) - } - - cell.onUnfollowClick = { [weak self] in - self?.unfollowSiteWithBlock(userBlock) + if isFollowEnabled { + cell.configure( + avatarURL: userBlock.media.first?.mediaURL, + username: userBlock.text, + blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host, + isFollowed: userBlock.isActionOn(id: FollowAction.actionIdentifier()), + onUserClicked: { [weak self] in + self?.displayContent(blockGroup) + }, + onFollowClicked: { [weak self] followClicked in + if followClicked { + self?.followSiteWithBlock(userBlock) + } else { + self?.unfollowSiteWithBlock(userBlock) + } + }, + parent: self + ) + } else { + cell.configure( + avatarURL: userBlock.media.first?.mediaURL, + username: userBlock.text, + blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host, + onUserClicked: { [weak self] in + self?.displayContent(blockGroup) + }, + parent: self + ) } - - // Download the Gravatar - let mediaURL = userBlock.media.first?.mediaURL - cell.downloadGravatarWithURL(mediaURL) } func setupCommentCell(_ cell: NoteBlockCommentTableViewCell, blockGroup: FormattableContentGroup, at indexPath: IndexPath) { diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift index 78e76ed288e3..e4d1fbd9a40b 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift @@ -1,118 +1,52 @@ import Foundation -import WordPressShared -import WordPressUI -import Gravatar +import SwiftUI class NoteBlockUserTableViewCell: NoteBlockTableViewCell { - typealias EventHandler = (() -> Void) + private var controller: UIHostingController? - // MARK: - Public Properties - @objc var onFollowClick: EventHandler? - @objc var onUnfollowClick: EventHandler? - - @objc var isFollowEnabled: Bool { - set { - if newValue { - innerStackView.addArrangedSubview(btnFollow) - } else { - btnFollow.removeFromSuperview() - } - } - get { - return btnFollow.superview != nil - } - } - @objc var isFollowOn: Bool { - set { - btnFollow.isSelected = newValue - configureAccesibility() - } - get { - return btnFollow.isSelected - } - } - - @objc var name: String? { - set { - nameLabel.text = newValue - } - get { - return nameLabel.text - } + func configure(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void, parent: UIViewController) { + let view = NotificationDetailUserView(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked) + host(view, parent: parent) } - @objc var blogTitle: String? { - set { - blogLabel.text = newValue - } - get { - return blogLabel.text - } - } - - // MARK: - Public Methods - @objc func downloadGravatarWithURL(_ url: URL?) { - if url == gravatarURL { - return - } - - let gravatar = url.flatMap { AvatarURL(url: $0) } - gravatarImageView.downloadGravatar(gravatar, placeholder: .gravatarPlaceholderImage, animate: true) - gravatarURL = url + func configure( + avatarURL: URL?, + username: String?, + blog: String?, + isFollowed: Bool, + onUserClicked: @escaping () -> Void, + onFollowClicked: @escaping (Bool) -> Void, + parent: UIViewController + ) { + let view = NotificationDetailUserView( + avatarURL: avatarURL, + username: username, + blog: blog, + isFollowed: isFollowed, + onUserClicked: onUserClicked, + onFollowClicked: onFollowClicked + ) + host(view, parent: parent) } - // MARK: - View Methods - override func awakeFromNib() { - super.awakeFromNib() - - WPStyleGuide.Notifications.configureFollowButton(btnFollow) - btnFollow.titleLabel?.font = WPStyleGuide.Notifications.blockRegularFont - - backgroundColor = WPStyleGuide.Notifications.blockBackgroundColor - - nameLabel.font = WPStyleGuide.Notifications.blockBoldFont - nameLabel.textColor = WPStyleGuide.Notifications.blockTextColor - - blogLabel.font = WPStyleGuide.Notifications.blockRegularFont - blogLabel.textColor = .neutral(.shade50) - blogLabel.adjustsFontSizeToFitWidth = false - - configureAccesibility() - } + private func host(_ content: NotificationDetailUserView, parent: UIViewController) { + if let controller = controller { + controller.rootView = content + controller.view.layoutIfNeeded() + } else { + let cellViewController = UIHostingController(rootView: content) + controller = cellViewController - // MARK: - IBActions - @IBAction func followWasPressed(_ sender: AnyObject) { - ReachabilityUtils.onAvailableInternetConnectionDo { - configureAccesibility() + parent.addChild(cellViewController) + contentView.addSubview(cellViewController.view) + cellViewController.view.translatesAutoresizingMaskIntoConstraints = false + layout(hostingView: cellViewController.view) - if let listener = isFollowOn ? onUnfollowClick : onFollowClick { - listener() - } - isFollowOn = !isFollowOn + cellViewController.didMove(toParent: parent) } } - // MARK: - Private - private func configureAccesibility() { - isFollowOn ? configureAsSelected() : configureAsUnSelected() - } - - private func configureAsUnSelected() { - btnFollow.accessibilityLabel = Follow.title - btnFollow.accessibilityHint = Follow.hint + func layout(hostingView view: UIView) { + self.contentView.pinSubviewToAllEdges(view) } - - private func configureAsSelected() { - btnFollow.accessibilityLabel = Follow.selectedTitle - btnFollow.accessibilityHint = Follow.selectedHint - } - - fileprivate var gravatarURL: URL? - - // MARK: - IBOutlets - @IBOutlet fileprivate var nameLabel: UILabel! - @IBOutlet fileprivate var blogLabel: UILabel! - @IBOutlet fileprivate var btnFollow: UIButton! - @IBOutlet fileprivate var gravatarImageView: CircularImageView! - @IBOutlet fileprivate var innerStackView: UIStackView! } diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib index 2cd182d66f40..6e555eb9b405 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib @@ -1,9 +1,9 @@ - + - + @@ -15,99 +15,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From ce1ffe8c63365b03cfbef79f3da25f206f5d0ce2 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Thu, 9 May 2024 10:48:47 -0600 Subject: [PATCH 03/11] Remove useless separators for header and user notification detail cells --- .../Views/NoteBlockHeaderTableViewCell.swift | 10 ++++++++++ .../Notifications/Views/NoteBlockTableViewCell.swift | 8 ++++++-- .../Views/NoteBlockUserTableViewCell.swift | 5 +++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift index d7b7128f4f37..f012980bedd6 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift @@ -13,6 +13,16 @@ class NoteBlockHeaderTableViewCell: NoteBlockTableViewCell { private var controller: UIHostingController? + init() { + super.init(style: .default, reuseIdentifier: NoteBlockHeaderTableViewCell.classNameWithoutNamespaces()) + shouldSetSeparators = false + } + + required init?(coder: NSCoder) { + super.init(coder: coder) + shouldSetSeparators = false + } + func configure(post: String, action: @escaping () -> Void, parent: UIViewController) { let content = ContentPreview(text: post, action: action) host(HeaderView(preview: content), parent: parent) diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift index d57c9d23e93a..6a45137e6a1e 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift @@ -41,6 +41,8 @@ class NoteBlockTableViewCell: WPTableViewCell { return view }() + @objc var shouldSetSeparators: Bool = true + // MARK: - Overridden Methods override func layoutSubviews() { @@ -50,8 +52,10 @@ class NoteBlockTableViewCell: WPTableViewCell { override func awakeFromNib() { super.awakeFromNib() - backgroundView = separatorsView - backgroundColor = .listForeground + if shouldSetSeparators { + backgroundView = separatorsView + backgroundColor = .listForeground + } } // MARK: - Public API diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift index e4d1fbd9a40b..d7362dcc431a 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift @@ -4,6 +4,11 @@ import SwiftUI class NoteBlockUserTableViewCell: NoteBlockTableViewCell { private var controller: UIHostingController? + required init?(coder: NSCoder) { + super.init(coder: coder) + shouldSetSeparators = false + } + func configure(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void, parent: UIViewController) { let view = NotificationDetailUserView(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked) host(view, parent: parent) From fc41a45cb5d90b1ca4dc8c159488ad180d6a5b25 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Fri, 10 May 2024 10:36:14 -0600 Subject: [PATCH 04/11] DSButton is used for Follow/Unfollow button on Followers details screen --- .../DesignSystem/Foundation/IconName.swift | 2 -- .../reader.follow.imageset/Contents.json | 16 ---------- .../reader.follow.imageset/reader-follow.pdf | Bin 972 -> 0 bytes .../reader.following.imageset/Contents.json | 16 ---------- .../reader-following.pdf | Bin 1005 -> 0 bytes .../Views/NotificationDetailUserView.swift | 29 +++--------------- 6 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json delete mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/reader-follow.pdf delete mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.following.imageset/Contents.json delete mode 100644 Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.following.imageset/reader-following.pdf diff --git a/Modules/Sources/DesignSystem/Foundation/IconName.swift b/Modules/Sources/DesignSystem/Foundation/IconName.swift index 8d47e92fecd0..4e6287501223 100644 --- a/Modules/Sources/DesignSystem/Foundation/IconName.swift +++ b/Modules/Sources/DesignSystem/Foundation/IconName.swift @@ -24,8 +24,6 @@ public enum IconName: String, CaseIterable { case arrowUp = "arrow.up" case arrowDown = "arrow.down" case vector = "vector" - case readerFollow = "reader.follow" - case readerFollowing = "reader.following" } // MARK: - Load Image diff --git a/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json b/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json deleted file mode 100644 index d443994dae33..000000000000 --- a/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/Contents.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "images" : [ - { - "filename" : "reader-follow.pdf", - "idiom" : "universal" - } - ], - "info" : { - "author" : "xcode", - "version" : 1 - }, - "properties" : { - "preserves-vector-representation" : true, - "template-rendering-intent" : "template" - } -} diff --git a/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/reader-follow.pdf b/Modules/Sources/DesignSystem/Foundation/Icons.xcassets/reader.follow.imageset/reader-follow.pdf deleted file mode 100644 index 27fa36c2d19d7be22ffa9aacd474c8b215267596..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 972 zcmY!laBPWcrI(FQ;PBNHHs<9RbDa8uW zpnwjFMY0JLXfTaFsd?!o845;57F_ynnK>mu=j*%W03GL&nw+1K3er_v0`x^LSH+y% zi3j6d+oe`bidj1ty_e)9e@3M;`-lqq{@_|K9@7MZz!ux`|{a1RR8POx~M?ulWn4F z#MM$`R`5>xz2cjcK~V6-MaOu0-iWQ;v{gPWcrI(FQ;PBNHHs<9RbDa8uW zpnwjFMY0JLXfTaFsd?!o845;bK;>?kIVC{n>$~Lu9p{pooS%{k(p6jn^hGXL#hl!U zzF9{Mcv`>Pwdw`*&i}tC$2;-b+hyzqm*r3JOgS)T|D-uBhfMgYHvLiDdt||i*PK#8 z3+s688RMh^xhF1v^>d;{>PgclOE%4Tu{-19Q|&#MbsIL@FTQ*KY<+T^yf=UA<A9+_l!`^BF@JqOGev?6-B9OTm}jjTn2EUU}kD+Y^so^024E|0481#P{>1w z83W@FP0Yj?n4ZwY49zgr8JJpPs53AG#xt5;BU50Kg^86EC1&QN7J>6-aAs91(8>Bi p`S~RZpo9m^X`Xp$`3j))3{K+3C5c5PV85B08*r(ry863u0RU=dN(BG_ diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift index aab75199fced..1f890fff21fb 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift @@ -96,33 +96,12 @@ private struct FollowButton: View { } var body: some View { - Button(action: { + DSButton( + title: isFollowed ? Follow.selectedTitle : Follow.title, + style: .init(emphasis: isFollowed ? .secondary : .primary, size: .small) + ) { isFollowed.toggle() onFollowClicked(isFollowed) - }) { - HStack(spacing: .DS.Padding.half) { - if isFollowed { - Image.DS.icon(named: .readerFollowing) - .resizable() - .scaledToFit() - .frame(width: 14, height: 14) - .foregroundColor(Color.DS.Foreground.success) - Text(Follow.selectedTitle) - .style(.bodySmall(.regular)) - .accessibilityHint(Follow.selectedHint) - .foregroundStyle(Color.DS.Foreground.success) - } else { - Image.DS.icon(named: .readerFollow) - .resizable() - .scaledToFit() - .frame(width: 14, height: 14) - .foregroundColor(Color.DS.Foreground.secondary) - Text(Follow.title) - .style(.bodySmall(.regular)) - .accessibilityHint(Follow.hint) - .foregroundStyle(Color.DS.Foreground.secondary) - } - } } } } From 1d7ed27a784ace46ca53cd5d4dafe4007d1bf9a2 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Fri, 10 May 2024 10:42:18 -0600 Subject: [PATCH 05/11] Reduce a redundant init function for NotificationDetailUserView --- .../Views/NotificationDetailUserView.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift index 1f890fff21fb..1a790c5d3d39 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift @@ -6,23 +6,19 @@ struct NotificationDetailUserView: View { let config: Configuration - init(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void) { - self.config = Configuration(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked) - } - init( avatarURL: URL?, username: String?, blog: String?, - isFollowed: Bool, + isFollowed: Bool? = nil, onUserClicked: @escaping () -> Void, - onFollowClicked: @escaping (Bool) -> Void + onFollowClicked: @escaping (Bool) -> Void = { _ in } ) { self.config = Configuration( avatarURL: avatarURL, username: username, blog: blog, - followActionConfig: FollowConfig(isFollowed: isFollowed, onFollowClicked: onFollowClicked), + followActionConfig: isFollowed.map { FollowConfig(isFollowed: $0, onFollowClicked: onFollowClicked) }, onUserClicked: onUserClicked ) } From d9779f64bb9779251f2f85339dae6fa83f9b10d7 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Fri, 10 May 2024 10:47:40 -0600 Subject: [PATCH 06/11] Refactor NotificationDetailUserView body to extract nested views --- .../Views/NotificationDetailUserView.swift | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift index 1a790c5d3d39..70bec95320b7 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift @@ -28,20 +28,7 @@ struct NotificationDetailUserView: View { Button(action: config.onUserClicked) { HStack(spacing: .DS.Padding.split) { AvatarsView(style: .single(config.avatarURL)) - VStack(alignment: .leading) { - if let username = config.username { - Text(username) - .style(.bodySmall(.regular)) - .foregroundStyle(Color.DS.Foreground.primary) - .lineLimit(1) - } - if let blog = config.blog { - Text(blog) - .style(.bodySmall(.regular)) - .foregroundStyle(Color.DS.Foreground.secondary) - .lineLimit(1) - } - } + userView Spacer() } } @@ -53,6 +40,27 @@ struct NotificationDetailUserView: View { .padding(.top, .DS.Padding.double) } + private var userView: some View { + VStack(alignment: .leading) { + if let username = config.username { userNameView(username) } + if let blog = config.blog { blogNameView(blog) } + } + } + + private func userNameView(_ name: String) -> some View { + Text(name) + .style(.bodySmall(.regular)) + .foregroundStyle(Color.DS.Foreground.primary) + .lineLimit(1) + } + + private func blogNameView(_ blog: String) -> some View { + Text(blog) + .style(.bodySmall(.regular)) + .foregroundStyle(Color.DS.Foreground.secondary) + .lineLimit(1) + } + struct Configuration { let avatarURL: URL? let username: String? From 5d932346ed332cd4001d6999c08284b8711028d7 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Fri, 10 May 2024 11:10:21 -0600 Subject: [PATCH 07/11] Create specific configure functions for NoteBlockUserTableViewCell and LikeUserTableViewCell --- .../Likes/LikesListController.swift | 5 +- .../NotificationDetailsViewController.swift | 47 ++++++------------- .../Views/LikeUserTableViewCell.swift | 21 +++++++-- .../Views/NoteBlockUserTableViewCell.swift | 35 ++++++++++++-- 4 files changed, 61 insertions(+), 47 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Likes/LikesListController.swift b/WordPress/Classes/ViewRelated/Likes/LikesListController.swift index 1626d574cc44..92d664c4e29d 100644 --- a/WordPress/Classes/ViewRelated/Likes/LikesListController.swift +++ b/WordPress/Classes/ViewRelated/Likes/LikesListController.swift @@ -410,9 +410,7 @@ private extension LikesListController { return UITableViewCell() } cell.configure( - avatarURL: URL(string: user.avatarUrl), - username: user.displayName, - blog: String(format: Constants.usernameFormat, user.username), + user: user, onUserClicked: { [weak self] in self?.delegate?.didSelectUser(user, at: indexPath) }, @@ -438,7 +436,6 @@ private extension LikesListController { static let headerSectionIndex = 0 static let headerRowIndex = 0 static let numberOfHeaderRows = 1 - static let usernameFormat = NSLocalizedString("@%1$@", comment: "Label displaying the user's username preceeded by an '@' symbol. %1$@ is a placeholder for the username.") } struct Strings { diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index f7be156eb36a..1e393aaefc81 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -669,39 +669,20 @@ private extension NotificationDetailsViewController { return } - let hasHomeURL = userBlock.metaLinksHome != nil - let hasHomeTitle = userBlock.metaTitlesHome?.isEmpty == false - let isFollowEnabled = userBlock.isActionEnabled(id: FollowAction.actionIdentifier()) - - if isFollowEnabled { - cell.configure( - avatarURL: userBlock.media.first?.mediaURL, - username: userBlock.text, - blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host, - isFollowed: userBlock.isActionOn(id: FollowAction.actionIdentifier()), - onUserClicked: { [weak self] in - self?.displayContent(blockGroup) - }, - onFollowClicked: { [weak self] followClicked in - if followClicked { - self?.followSiteWithBlock(userBlock) - } else { - self?.unfollowSiteWithBlock(userBlock) - } - }, - parent: self - ) - } else { - cell.configure( - avatarURL: userBlock.media.first?.mediaURL, - username: userBlock.text, - blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host, - onUserClicked: { [weak self] in - self?.displayContent(blockGroup) - }, - parent: self - ) - } + cell.configure( + userBlock: userBlock, + onUserClicked: { [weak self] in + self?.displayContent(blockGroup) + }, + onFollowClicked: { [weak self] followClicked in + if followClicked { + self?.followSiteWithBlock(userBlock) + } else { + self?.unfollowSiteWithBlock(userBlock) + } + }, + parent: self + ) } func setupCommentCell(_ cell: NoteBlockCommentTableViewCell, blockGroup: FormattableContentGroup, at indexPath: IndexPath) { diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift index a52d70874b0b..79b7396bd1fe 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift @@ -6,18 +6,22 @@ class LikeUserTableViewCell: UITableViewCell, NibReusable { private var controller: UIHostingController? - func configure(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void, parent: UIViewController) { - let view = NotificationDetailUserView(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked) - host(view, parent: parent) + func configure(user: LikeUser, onUserClicked: @escaping () -> Void, parent: UIViewController) { + configure( + avatarURL: URL(string: user.avatarUrl), + username: user.displayName, + blog: String(format: Constants.usernameFormat, user.username), + onUserClicked: onUserClicked, + parent: parent) } func configure( avatarURL: URL?, username: String?, blog: String?, - isFollowed: Bool, + isFollowed: Bool? = nil, onUserClicked: @escaping () -> Void, - onFollowClicked: @escaping (Bool) -> Void, + onFollowClicked: @escaping (Bool) -> Void = { _ in }, parent: UIViewController ) { let view = NotificationDetailUserView( @@ -52,3 +56,10 @@ class LikeUserTableViewCell: UITableViewCell, NibReusable { self.contentView.pinSubviewToAllEdges(view) } } + +private extension LikeUserTableViewCell { + + struct Constants { + static let usernameFormat = NSLocalizedString("@%1$@", comment: "Label displaying the user's username preceeded by an '@' symbol. %1$@ is a placeholder for the username.") + } +} diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift index d7362dcc431a..b58098fc94d7 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift @@ -9,18 +9,43 @@ class NoteBlockUserTableViewCell: NoteBlockTableViewCell { shouldSetSeparators = false } - func configure(avatarURL: URL?, username: String?, blog: String?, onUserClicked: @escaping () -> Void, parent: UIViewController) { - let view = NotificationDetailUserView(avatarURL: avatarURL, username: username, blog: blog, onUserClicked: onUserClicked) - host(view, parent: parent) + func configure( + userBlock: FormattableUserContent, + onUserClicked: @escaping () -> Void, + onFollowClicked: @escaping (Bool) -> Void, + parent: UIViewController + ) { + let isFollowEnabled = userBlock.isActionEnabled(id: FollowAction.actionIdentifier()) + let hasHomeTitle = userBlock.metaTitlesHome?.isEmpty == false + + if isFollowEnabled { + configure( + avatarURL: userBlock.media.first?.mediaURL, + username: userBlock.text, + blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host, + isFollowed: userBlock.isActionOn(id: FollowAction.actionIdentifier()), + onUserClicked: onUserClicked, + onFollowClicked: onFollowClicked, + parent: parent + ) + } else { + configure( + avatarURL: userBlock.media.first?.mediaURL, + username: userBlock.text, + blog: hasHomeTitle ? userBlock.metaTitlesHome : userBlock.metaLinksHome?.host, + onUserClicked: onUserClicked, + parent: parent + ) + } } func configure( avatarURL: URL?, username: String?, blog: String?, - isFollowed: Bool, + isFollowed: Bool? = nil, onUserClicked: @escaping () -> Void, - onFollowClicked: @escaping (Bool) -> Void, + onFollowClicked: @escaping (Bool) -> Void = { _ in }, parent: UIViewController ) { let view = NotificationDetailUserView( From c60d69ea170ff8b6dbf350f359e77e487ce89d20 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Mon, 13 May 2024 08:50:42 -0600 Subject: [PATCH 08/11] Remove redundant ImageConfiguration from NotificationDetailUserView --- .../Views/NotificationDetailUserView.swift | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift index 70bec95320b7..948a57506484 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NotificationDetailUserView.swift @@ -110,20 +110,6 @@ private struct FollowButton: View { } } -public struct ImageConfiguration { - let url: URL? - let placeholder: Image? - - public init(url: URL?, placeholder: Image? = nil) { - self.url = url - self.placeholder = placeholder - } - - public init(url: String?, placeholder: Image? = nil) { - self.init(url: URL(string: url ?? ""), placeholder: placeholder) - } -} - #Preview { VStack(alignment: .leading) { NotificationDetailUserView( From a42a63e7f654e6029d18dda82aeb75adcfe9f53c Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Thu, 16 May 2024 10:12:58 -0600 Subject: [PATCH 09/11] Remove redundant LikeUserTableViewCell.xib file --- .../NotificationDetailsViewController.swift | 2 +- .../Views/LikeUserTableViewCell.swift | 2 +- .../Views/LikeUserTableViewCell.xib | 22 ------------------- .../ReaderDetailLikesListController.swift | 2 +- WordPress/WordPress.xcodeproj/project.pbxproj | 6 ----- 5 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index 1e393aaefc81..06d3536855c0 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -384,7 +384,7 @@ extension NotificationDetailsViewController { tableView.register(nib, forCellReuseIdentifier: cellClass.reuseIdentifier()) } - tableView.register(LikeUserTableViewCell.defaultNib, + tableView.register(LikeUserTableViewCell.self, forCellReuseIdentifier: LikeUserTableViewCell.defaultReuseID) } diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift index 79b7396bd1fe..cca3ae7b5a78 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift @@ -1,7 +1,7 @@ import Foundation import SwiftUI -class LikeUserTableViewCell: UITableViewCell, NibReusable { +class LikeUserTableViewCell: UITableViewCell, Reusable { static let estimatedRowHeight: CGFloat = 80 private var controller: UIHostingController? diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib b/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib deleted file mode 100644 index 928aa21a2d18..000000000000 --- a/WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailLikesListController.swift b/WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailLikesListController.swift index c49916b4b31f..42eb5b1cbed8 100644 --- a/WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailLikesListController.swift +++ b/WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailLikesListController.swift @@ -38,7 +38,7 @@ private extension ReaderDetailLikesListController { } func configureTable() { - tableView.register(LikeUserTableViewCell.defaultNib, + tableView.register(LikeUserTableViewCell.self, forCellReuseIdentifier: LikeUserTableViewCell.defaultReuseID) likesListController = LikesListController(tableView: tableView, post: post, parent: self, delegate: self) diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 773fec37226f..c3910892f548 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -2693,8 +2693,6 @@ 98B52AE121F7AF4A006FF6B4 /* StatsDataHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B52AE021F7AF4A006FF6B4 /* StatsDataHelper.swift */; }; 98B88452261E4E09007ED7F8 /* LikeUserTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B88451261E4E09007ED7F8 /* LikeUserTableViewCell.swift */; }; 98B88453261E4E09007ED7F8 /* LikeUserTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98B88451261E4E09007ED7F8 /* LikeUserTableViewCell.swift */; }; - 98B88466261E4E4E007ED7F8 /* LikeUserTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 98B88465261E4E4E007ED7F8 /* LikeUserTableViewCell.xib */; }; - 98B88467261E4E4E007ED7F8 /* LikeUserTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 98B88465261E4E4E007ED7F8 /* LikeUserTableViewCell.xib */; }; 98BAA7C126F925F70073A2F9 /* InlineEditableSingleLineCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 98BAA7BF26F925F60073A2F9 /* InlineEditableSingleLineCell.xib */; }; 98BAA7C226F925F70073A2F9 /* InlineEditableSingleLineCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 98BAA7BF26F925F60073A2F9 /* InlineEditableSingleLineCell.xib */; }; 98BAA7C326F925F70073A2F9 /* InlineEditableSingleLineCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 98BAA7C026F925F70073A2F9 /* InlineEditableSingleLineCell.swift */; }; @@ -8107,7 +8105,6 @@ 98B3FA8521C05BF000148DD4 /* ViewMoreRow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ViewMoreRow.xib; sourceTree = ""; }; 98B52AE021F7AF4A006FF6B4 /* StatsDataHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatsDataHelper.swift; sourceTree = ""; }; 98B88451261E4E09007ED7F8 /* LikeUserTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LikeUserTableViewCell.swift; sourceTree = ""; }; - 98B88465261E4E4E007ED7F8 /* LikeUserTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LikeUserTableViewCell.xib; sourceTree = ""; }; 98BAA7BF26F925F60073A2F9 /* InlineEditableSingleLineCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = InlineEditableSingleLineCell.xib; sourceTree = ""; }; 98BAA7C026F925F70073A2F9 /* InlineEditableSingleLineCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InlineEditableSingleLineCell.swift; sourceTree = ""; }; 98BBB642258047DD0084FF72 /* WordPress 107.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 107.xcdatamodel"; sourceTree = ""; }; @@ -16096,7 +16093,6 @@ isa = PBXGroup; children = ( 98B88451261E4E09007ED7F8 /* LikeUserTableViewCell.swift */, - 98B88465261E4E4E007ED7F8 /* LikeUserTableViewCell.xib */, 2FA37B19215724E900C80377 /* LongPressGestureLabel.swift */, B57AF5F91ACDC73D0075A7D2 /* NoteBlockActionsTableViewCell.swift */, B5C66B731ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib */, @@ -19746,7 +19742,6 @@ C7234A442832C2BA0045C63F /* QRLoginScanningViewController.xib in Resources */, 17222D99261DDDF90047B163 /* black-icon-app-60x60@2x.png in Resources */, 9856A389261FC206008D6354 /* UserProfileUserInfoCell.xib in Resources */, - 98B88466261E4E4E007ED7F8 /* LikeUserTableViewCell.xib in Resources */, 98467A43221CD75200DF51AE /* SiteStatsDetailTableViewController.storyboard in Resources */, FE43DAB126DFAD1C00CFF595 /* CommentContentTableViewCell.xib in Resources */, 43D74ACE20F906DD004AD934 /* InlineEditableNameValueCell.xib in Resources */, @@ -20323,7 +20318,6 @@ FAE4CA6B2732C094003BFDFE /* QuickStartPromptViewController.xib in Resources */, FABB200B2602FC2C00C8785C /* LoginEpilogue.storyboard in Resources */, F41E4E9828F20802001880C6 /* white-on-pink-icon-app-60@3x.png in Resources */, - 98B88467261E4E4E007ED7F8 /* LikeUserTableViewCell.xib in Resources */, FABB200F2602FC2C00C8785C /* TopTotalsCell.xib in Resources */, FABB20112602FC2C00C8785C /* SpaceMono-Bold.ttf in Resources */, F46597E828E6698D00D5F49A /* spectrum-on-black-icon-app-60@2x.png in Resources */, From af5ba03339a174748088f5e92d0e749fb9066f6c Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Thu, 16 May 2024 11:00:03 -0600 Subject: [PATCH 10/11] Remove redundant NoteBlockUserTableViewCell.xib file --- .../NotificationDetailsViewController.swift | 6 ++--- .../Views/NoteBlockUserTableViewCell.swift | 7 +----- .../Views/NoteBlockUserTableViewCell.xib | 22 ------------------- WordPress/WordPress.xcodeproj/project.pbxproj | 6 ----- 4 files changed, 4 insertions(+), 37 deletions(-) delete mode 100644 WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index 06d3536855c0..d11532bc38e3 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -373,7 +373,6 @@ extension NotificationDetailsViewController { NoteBlockActionsTableViewCell.self, NoteBlockCommentTableViewCell.self, NoteBlockImageTableViewCell.self, - NoteBlockUserTableViewCell.self, NoteBlockButtonTableViewCell.self ] @@ -386,7 +385,8 @@ extension NotificationDetailsViewController { tableView.register(LikeUserTableViewCell.self, forCellReuseIdentifier: LikeUserTableViewCell.defaultReuseID) - + tableView.register(NoteBlockUserTableViewCell.self, + forCellReuseIdentifier: NoteBlockUserTableViewCell.defaultReuseID) } /// Configure the delegate and data source for the table view based on notification type. @@ -571,7 +571,7 @@ private extension NotificationDetailsViewController { case .image: return NoteBlockImageTableViewCell.reuseIdentifier() case .user: - return NoteBlockUserTableViewCell.reuseIdentifier() + return NoteBlockUserTableViewCell.defaultReuseID case .button: return NoteBlockButtonTableViewCell.reuseIdentifier() default: diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift index b58098fc94d7..1532148cde24 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift @@ -1,14 +1,9 @@ import Foundation import SwiftUI -class NoteBlockUserTableViewCell: NoteBlockTableViewCell { +class NoteBlockUserTableViewCell: NoteBlockTableViewCell, Reusable { private var controller: UIHostingController? - required init?(coder: NSCoder) { - super.init(coder: coder) - shouldSetSeparators = false - } - func configure( userBlock: FormattableUserContent, onUserClicked: @escaping () -> Void, diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib deleted file mode 100644 index 6e555eb9b405..000000000000 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.xib +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index c3910892f548..14c5c0f48c10 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -2962,7 +2962,6 @@ B5C66B741ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B731ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib */; }; B5C66B761ACF072C00F68370 /* NoteBlockCommentTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B751ACF072C00F68370 /* NoteBlockCommentTableViewCell.xib */; }; B5C66B781ACF073900F68370 /* NoteBlockImageTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B771ACF073900F68370 /* NoteBlockImageTableViewCell.xib */; }; - B5C66B7A1ACF074600F68370 /* NoteBlockUserTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B791ACF074600F68370 /* NoteBlockUserTableViewCell.xib */; }; B5C9401A1DB900DC0079D4FF /* AccountHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C940191DB900DC0079D4FF /* AccountHelper.swift */; }; B5CABB171C0E382C0050AB9F /* PickerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5CABB161C0E382C0050AB9F /* PickerTableViewCell.swift */; }; B5CC05F61962150600975CAC /* Constants.m in Sources */ = {isa = PBXBuildFile; fileRef = B5CC05F51962150600975CAC /* Constants.m */; }; @@ -4285,7 +4284,6 @@ FABB20662602FC2C00C8785C /* ReaderSiteStreamHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = E6D2E15E1B8A9C830000ED14 /* ReaderSiteStreamHeader.xib */; }; FABB20692602FC2C00C8785C /* ReaderTopicsCardCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = C7192ECE25E8432D00C3020D /* ReaderTopicsCardCell.xib */; }; FABB206B2602FC2C00C8785C /* richEmbedTemplate.html in Resources */ = {isa = PBXBuildFile; fileRef = E61507E12220A0FE00213D33 /* richEmbedTemplate.html */; }; - FABB206D2602FC2C00C8785C /* NoteBlockUserTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B791ACF074600F68370 /* NoteBlockUserTableViewCell.xib */; }; FABB20702602FC2C00C8785C /* ReaderListStreamHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = E6D2E1621B8AAA340000ED14 /* ReaderListStreamHeader.xib */; }; FABB20722602FC2C00C8785C /* MyProfileHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = CE1CCB2E2050502B000EE3AC /* MyProfileHeaderView.xib */; }; FABB20762602FC2C00C8785C /* WordPressShare.js in Resources */ = {isa = PBXBuildFile; fileRef = E1AFA8C21E8E34230004A323 /* WordPressShare.js */; }; @@ -8384,7 +8382,6 @@ B5C66B731ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockActionsTableViewCell.xib; sourceTree = ""; }; B5C66B751ACF072C00F68370 /* NoteBlockCommentTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockCommentTableViewCell.xib; sourceTree = ""; }; B5C66B771ACF073900F68370 /* NoteBlockImageTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockImageTableViewCell.xib; sourceTree = ""; }; - B5C66B791ACF074600F68370 /* NoteBlockUserTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockUserTableViewCell.xib; sourceTree = ""; }; B5C940191DB900DC0079D4FF /* AccountHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AccountHelper.swift; sourceTree = ""; }; B5CABB161C0E382C0050AB9F /* PickerTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PickerTableViewCell.swift; sourceTree = ""; }; B5CC05F51962150600975CAC /* Constants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Constants.m; sourceTree = ""; }; @@ -16108,7 +16105,6 @@ B532D4E8199D4357006E4DF6 /* NoteBlockTextTableViewCell.swift */, B5C66B711ACF071000F68370 /* NoteBlockTextTableViewCell.xib */, B52C4C7C199D4CD3009FD823 /* NoteBlockUserTableViewCell.swift */, - B5C66B791ACF074600F68370 /* NoteBlockUserTableViewCell.xib */, 776D09F22BEC01B500DE07A1 /* NotificationDetailUserView.swift */, FEDDD46E26A03DE900F8942B /* ListTableViewCell+Notifications.swift */, ); @@ -19893,7 +19889,6 @@ C7192ECF25E8432D00C3020D /* ReaderTopicsCardCell.xib in Resources */, 17222D8E261DDDF90047B163 /* black-classic-icon-app-76x76.png in Resources */, E61507E22220A0FE00213D33 /* richEmbedTemplate.html in Resources */, - B5C66B7A1ACF074600F68370 /* NoteBlockUserTableViewCell.xib in Resources */, E6D2E1631B8AAA340000ED14 /* ReaderListStreamHeader.xib in Resources */, 8BE6F92A27EE26D30008BDC7 /* BlogDashboardPostCardGhostCell.xib in Resources */, CE1CCB2F2050502B000EE3AC /* MyProfileHeaderView.xib in Resources */, @@ -20417,7 +20412,6 @@ FABB20692602FC2C00C8785C /* ReaderTopicsCardCell.xib in Resources */, F465980928E66A5B00D5F49A /* white-on-blue-icon-app-76.png in Resources */, FABB206B2602FC2C00C8785C /* richEmbedTemplate.html in Resources */, - FABB206D2602FC2C00C8785C /* NoteBlockUserTableViewCell.xib in Resources */, FABB20702602FC2C00C8785C /* ReaderListStreamHeader.xib in Resources */, F465979B28E65FC800D5F49A /* dark-green-icon-app-76@2x.png in Resources */, FABB20722602FC2C00C8785C /* MyProfileHeaderView.xib in Resources */, From 1d6b5eb9c80108286dd897d36738568669204664 Mon Sep 17 00:00:00 2001 From: Artyom Vlasov Date: Thu, 16 May 2024 11:06:46 -0600 Subject: [PATCH 11/11] Remove redundant NoteBlockHeaderTableViewCell.xib file --- .../Likes/LikesListController.swift | 2 +- .../NotificationDetailsViewController.swift | 5 ++-- .../Views/NoteBlockHeaderTableViewCell.swift | 12 +-------- .../Views/NoteBlockHeaderTableViewCell.xib | 25 ------------------- .../Views/NoteBlockTableViewCell.swift | 8 ++---- WordPress/WordPress.xcodeproj/project.pbxproj | 6 ----- 6 files changed, 7 insertions(+), 51 deletions(-) delete mode 100644 WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.xib diff --git a/WordPress/Classes/ViewRelated/Likes/LikesListController.swift b/WordPress/Classes/ViewRelated/Likes/LikesListController.swift index 92d664c4e29d..ea0346825780 100644 --- a/WordPress/Classes/ViewRelated/Likes/LikesListController.swift +++ b/WordPress/Classes/ViewRelated/Likes/LikesListController.swift @@ -357,7 +357,7 @@ extension LikesListController: UITableViewDataSource, UITableViewDelegate { private extension LikesListController { func headerCell() -> NoteBlockHeaderTableViewCell { - guard let cell = tableView.dequeueReusableCell(withIdentifier: NoteBlockHeaderTableViewCell.reuseIdentifier()) as? NoteBlockHeaderTableViewCell, + guard let cell = tableView.dequeueReusableCell(withIdentifier: NoteBlockHeaderTableViewCell.defaultReuseID) as? NoteBlockHeaderTableViewCell, let group = notification?.headerAndBodyContentGroups[Constants.headerRowIndex] else { DDLogError("Error: couldn't get a header cell or FormattableContentGroup.") return NoteBlockHeaderTableViewCell() diff --git a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift index d11532bc38e3..5466ad46ff11 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationDetailsViewController.swift @@ -368,7 +368,6 @@ extension NotificationDetailsViewController { func setupTableViewCells() { let cellClassNames: [NoteBlockTableViewCell.Type] = [ - NoteBlockHeaderTableViewCell.self, NoteBlockTextTableViewCell.self, NoteBlockActionsTableViewCell.self, NoteBlockCommentTableViewCell.self, @@ -385,6 +384,8 @@ extension NotificationDetailsViewController { tableView.register(LikeUserTableViewCell.self, forCellReuseIdentifier: LikeUserTableViewCell.defaultReuseID) + tableView.register(NoteBlockHeaderTableViewCell.self, + forCellReuseIdentifier: NoteBlockHeaderTableViewCell.defaultReuseID) tableView.register(NoteBlockUserTableViewCell.self, forCellReuseIdentifier: NoteBlockUserTableViewCell.defaultReuseID) } @@ -557,7 +558,7 @@ private extension NotificationDetailsViewController { func reuseIdentifierForGroup(_ blockGroup: FormattableContentGroup) -> String { switch blockGroup.kind { case .header: - return NoteBlockHeaderTableViewCell.reuseIdentifier() + return NoteBlockHeaderTableViewCell.defaultReuseID case .footer: return NoteBlockTextTableViewCell.reuseIdentifier() case .subject: diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift index f012980bedd6..caa49ac8f5d0 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.swift @@ -7,22 +7,12 @@ import DesignSystem // MARK: - NoteBlockHeaderTableViewCell // -class NoteBlockHeaderTableViewCell: NoteBlockTableViewCell { +class NoteBlockHeaderTableViewCell: NoteBlockTableViewCell, Reusable { typealias Constants = ContentPreview.Constants typealias Avatar = ContentPreview.ImageConfiguration.Avatar private var controller: UIHostingController? - init() { - super.init(style: .default, reuseIdentifier: NoteBlockHeaderTableViewCell.classNameWithoutNamespaces()) - shouldSetSeparators = false - } - - required init?(coder: NSCoder) { - super.init(coder: coder) - shouldSetSeparators = false - } - func configure(post: String, action: @escaping () -> Void, parent: UIViewController) { let content = ContentPreview(text: post, action: action) host(HeaderView(preview: content), parent: parent) diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.xib b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.xib deleted file mode 100644 index 9c9ddc8f6fcd..000000000000 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockHeaderTableViewCell.xib +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift index 6a45137e6a1e..d57c9d23e93a 100644 --- a/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift +++ b/WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockTableViewCell.swift @@ -41,8 +41,6 @@ class NoteBlockTableViewCell: WPTableViewCell { return view }() - @objc var shouldSetSeparators: Bool = true - // MARK: - Overridden Methods override func layoutSubviews() { @@ -52,10 +50,8 @@ class NoteBlockTableViewCell: WPTableViewCell { override func awakeFromNib() { super.awakeFromNib() - if shouldSetSeparators { - backgroundView = separatorsView - backgroundColor = .listForeground - } + backgroundView = separatorsView + backgroundColor = .listForeground } // MARK: - Public API diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 14c5c0f48c10..6898e98ef3ce 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -2957,7 +2957,6 @@ B5BEA5601C7CE6D700C8035B /* SFHFKeychainUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 292CECFF1027259000BD407D /* SFHFKeychainUtils.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; B5C0CF3D204DA41000DB0362 /* NotificationReplyStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C0CF3C204DA41000DB0362 /* NotificationReplyStore.swift */; }; B5C0CF3F204DB92F00DB0362 /* NotificationReplyStoreTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5C0CF3E204DB92F00DB0362 /* NotificationReplyStoreTests.swift */; }; - B5C66B701ACF06CA00F68370 /* NoteBlockHeaderTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B6F1ACF06CA00F68370 /* NoteBlockHeaderTableViewCell.xib */; }; B5C66B721ACF071100F68370 /* NoteBlockTextTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B711ACF071000F68370 /* NoteBlockTextTableViewCell.xib */; }; B5C66B741ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B731ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib */; }; B5C66B761ACF072C00F68370 /* NoteBlockCommentTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B751ACF072C00F68370 /* NoteBlockCommentTableViewCell.xib */; }; @@ -4184,7 +4183,6 @@ FABB1FB32602FC2C00C8785C /* NoteBlockActionsTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B731ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib */; }; FABB1FB42602FC2C00C8785C /* Pacifico-Regular.ttf in Resources */ = {isa = PBXBuildFile; fileRef = F5A34D0B25DF2F7700C9654B /* Pacifico-Regular.ttf */; }; FABB1FB92602FC2C00C8785C /* RestoreStatusFailedView.xib in Resources */ = {isa = PBXBuildFile; fileRef = FA1CEAD325CA9C40005E7038 /* RestoreStatusFailedView.xib */; }; - FABB1FBA2602FC2C00C8785C /* NoteBlockHeaderTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5C66B6F1ACF06CA00F68370 /* NoteBlockHeaderTableViewCell.xib */; }; FABB1FBB2602FC2C00C8785C /* CollapsableHeaderCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 469CE07024BCFB04003BDC8B /* CollapsableHeaderCollectionViewCell.xib */; }; FABB1FBF2602FC2C00C8785C /* WPTableViewActivityCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5D6C4AF51B603CA3005E3C43 /* WPTableViewActivityCell.xib */; }; FABB1FC12602FC2C00C8785C /* defaultPostTemplate.html in Resources */ = {isa = PBXBuildFile; fileRef = A01C55470E25E0D000D411F2 /* defaultPostTemplate.html */; }; @@ -8377,7 +8375,6 @@ B5B68BD31C19AAED00EB59E0 /* InteractiveNotificationsManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InteractiveNotificationsManager.swift; sourceTree = ""; }; B5C0CF3C204DA41000DB0362 /* NotificationReplyStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationReplyStore.swift; sourceTree = ""; }; B5C0CF3E204DB92F00DB0362 /* NotificationReplyStoreTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationReplyStoreTests.swift; sourceTree = ""; }; - B5C66B6F1ACF06CA00F68370 /* NoteBlockHeaderTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockHeaderTableViewCell.xib; sourceTree = ""; }; B5C66B711ACF071000F68370 /* NoteBlockTextTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockTextTableViewCell.xib; sourceTree = ""; }; B5C66B731ACF071F00F68370 /* NoteBlockActionsTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockActionsTableViewCell.xib; sourceTree = ""; }; B5C66B751ACF072C00F68370 /* NoteBlockCommentTableViewCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NoteBlockCommentTableViewCell.xib; sourceTree = ""; }; @@ -16098,7 +16095,6 @@ B532D4E5199D4357006E4DF6 /* NoteBlockCommentTableViewCell.swift */, B5C66B751ACF072C00F68370 /* NoteBlockCommentTableViewCell.xib */, B532D4E6199D4357006E4DF6 /* NoteBlockHeaderTableViewCell.swift */, - B5C66B6F1ACF06CA00F68370 /* NoteBlockHeaderTableViewCell.xib */, B532D4ED199D4418006E4DF6 /* NoteBlockImageTableViewCell.swift */, B5C66B771ACF073900F68370 /* NoteBlockImageTableViewCell.xib */, B532D4E7199D4357006E4DF6 /* NoteBlockTableViewCell.swift */, @@ -19688,7 +19684,6 @@ F5A34D1125DF2F7F00C9654B /* Pacifico-Regular.ttf in Resources */, FA1CEAD425CA9C40005E7038 /* RestoreStatusFailedView.xib in Resources */, 1761F17B26209AEE000815EF /* open-source-icon-app-60x60@2x.png in Resources */, - B5C66B701ACF06CA00F68370 /* NoteBlockHeaderTableViewCell.xib in Resources */, 1761F18126209AEE000815EF /* jetpack-green-icon-app-60x60@2x.png in Resources */, 801D9513291AB3CF0051993E /* JetpackStatsLogoAnimation_rtl.json in Resources */, 17222DA2261DDDF90047B163 /* pink-classic-icon-app-60x60@3x.png in Resources */, @@ -20228,7 +20223,6 @@ FABB286C2603086900C8785C /* AppImages.xcassets in Resources */, F46597C828E668B900D5F49A /* neumorphic-light-icon-app-60@3x.png in Resources */, FABB1FB92602FC2C00C8785C /* RestoreStatusFailedView.xib in Resources */, - FABB1FBA2602FC2C00C8785C /* NoteBlockHeaderTableViewCell.xib in Resources */, FABB1FBB2602FC2C00C8785C /* CollapsableHeaderCollectionViewCell.xib in Resources */, FE43DAB226DFAD1C00CFF595 /* CommentContentTableViewCell.xib in Resources */, C7234A452832C2BA0045C63F /* QRLoginScanningViewController.xib in Resources */,