-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Notifications Refresh] Redesign Likes and Follows details content (#…
- Loading branch information
Showing
11 changed files
with
294 additions
and
432 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 46 additions & 46 deletions
92
WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,65 @@ | ||
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! | ||
|
||
class LikeUserTableViewCell: UITableViewCell, Reusable { | ||
static let estimatedRowHeight: CGFloat = 80 | ||
private typealias Style = WPStyleGuide.Notifications | ||
|
||
// MARK: - View | ||
private var controller: UIHostingController<NotificationDetailUserView>? | ||
|
||
override func awakeFromNib() { | ||
super.awakeFromNib() | ||
configureCell() | ||
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) | ||
} | ||
|
||
// 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? = nil, | ||
onUserClicked: @escaping () -> Void, | ||
onFollowClicked: @escaping (Bool) -> Void = { _ in }, | ||
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) | ||
func layout(hostingView view: UIView) { | ||
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.") | ||
} | ||
|
||
} |
91 changes: 0 additions & 91 deletions
91
WordPress/Classes/ViewRelated/Notifications/Views/LikeUserTableViewCell.xib
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.