-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Posts & Pages: New design for pages cells #21842
Merged
kean
merged 7 commits into
task/ui-modernization-posts-and-pages
from
task/pages-new-cells
Oct 23, 2023
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
904cafc
Remove unused code
kean 0e37d08
Add new page cell design
kean b800ee3
Remove PageListTableViewCell
kean e07fef1
Remove the Undo button
kean 37a4a3b
Fix crash
kean cebcffa
Update Homepage template cell design
kean a69c864
Fix margins and separator insets
kean File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import Foundation | ||
import UIKit | ||
import Combine | ||
|
||
final class PageListCell: UITableViewCell, Reusable { | ||
|
||
// MARK: - Views | ||
|
||
private let titleLabel = UILabel() | ||
private let badgeIconView = UIImageView() | ||
private let badgesLabel = UILabel() | ||
private let featuredImageView = CachedAnimatedImageView() | ||
private let ellipsisButton = UIButton(type: .custom) | ||
private var cancellables: [AnyCancellable] = [] | ||
|
||
// MARK: - Properties | ||
|
||
private lazy var imageLoader = ImageLoader(imageView: featuredImageView, loadingIndicator: SolidColorActivityIndicator()) | ||
|
||
// MARK: - Initializers | ||
|
||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
setupViews() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
// MARK: - Public | ||
|
||
override func prepareForReuse() { | ||
super.prepareForReuse() | ||
|
||
cancellables = [] | ||
imageLoader.prepareForReuse() | ||
} | ||
|
||
func configure(with viewModel: PageListItemViewModel) { | ||
viewModel.$title.sink { [titleLabel] in | ||
titleLabel.attributedText = $0 | ||
}.store(in: &cancellables) | ||
|
||
badgeIconView.image = viewModel.badgeIcon | ||
badgeIconView.isHidden = viewModel.badgeIcon == nil | ||
badgesLabel.text = viewModel.badges | ||
|
||
imageLoader.prepareForReuse() | ||
featuredImageView.isHidden = viewModel.imageURL == nil | ||
if let imageURL = viewModel.imageURL { | ||
let host = MediaHost(with: viewModel.page) { error in | ||
WordPressAppDelegate.crashLogging?.logError(error) | ||
} | ||
imageLoader.loadImage(with: imageURL, from: host, preferredSize: Constants.imageSize) | ||
} | ||
} | ||
|
||
// MARK: - Setup | ||
|
||
private func setupViews() { | ||
setupLabels() | ||
setupFeaturedImageView() | ||
setupEllipsisButton() | ||
|
||
let badgesStackView = UIStackView(arrangedSubviews: [ | ||
badgeIconView, badgesLabel, UIView() | ||
]) | ||
badgesStackView.alignment = .bottom | ||
badgesStackView.spacing = 2 | ||
|
||
let labelsStackView = UIStackView(arrangedSubviews: [ | ||
titleLabel, badgesStackView | ||
]) | ||
labelsStackView.spacing = 4 | ||
labelsStackView.axis = .vertical | ||
|
||
let contentStackView = UIStackView(arrangedSubviews: [ | ||
labelsStackView, featuredImageView, ellipsisButton | ||
]) | ||
contentStackView.spacing = 8 | ||
contentStackView.alignment = .center | ||
contentStackView.isLayoutMarginsRelativeArrangement = true | ||
contentStackView.directionalLayoutMargins = NSDirectionalEdgeInsets(top: 12, leading: 16, bottom: 12, trailing: 16) | ||
|
||
NSLayoutConstraint.activate([ | ||
badgeIconView.heightAnchor.constraint(equalToConstant: 18), | ||
badgeIconView.heightAnchor.constraint(equalTo: badgeIconView.widthAnchor, multiplier: 1) | ||
]) | ||
|
||
contentView.addSubview(contentStackView) | ||
contentStackView.translatesAutoresizingMaskIntoConstraints = false | ||
contentView.pinSubviewToAllEdges(contentStackView) | ||
} | ||
|
||
private func setupLabels() { | ||
titleLabel.translatesAutoresizingMaskIntoConstraints = false | ||
titleLabel.adjustsFontForContentSizeCategory = true | ||
titleLabel.numberOfLines = 1 | ||
|
||
badgeIconView.tintColor = UIColor.secondaryLabel | ||
|
||
badgesLabel.font = WPStyleGuide.fontForTextStyle(.footnote) | ||
badgesLabel.textColor = UIColor.secondaryLabel | ||
} | ||
|
||
private func setupFeaturedImageView() { | ||
featuredImageView.translatesAutoresizingMaskIntoConstraints = false | ||
featuredImageView.contentMode = .scaleAspectFill | ||
featuredImageView.layer.masksToBounds = true | ||
featuredImageView.layer.cornerRadius = 5 | ||
|
||
NSLayoutConstraint.activate([ | ||
featuredImageView.widthAnchor.constraint(equalToConstant: Constants.imageSize.width), | ||
featuredImageView.heightAnchor.constraint(equalToConstant: Constants.imageSize.height), | ||
]) | ||
} | ||
|
||
private func setupEllipsisButton() { | ||
ellipsisButton.translatesAutoresizingMaskIntoConstraints = false | ||
ellipsisButton.setImage(UIImage(named: "more-horizontal-mobile"), for: .normal) | ||
ellipsisButton.tintColor = .listIcon | ||
|
||
NSLayoutConstraint.activate([ | ||
ellipsisButton.widthAnchor.constraint(equalToConstant: 24) | ||
]) | ||
} | ||
} | ||
|
||
private enum Constants { | ||
static let imageSize = CGSize(width: 44, height: 44) | ||
} |
68 changes: 68 additions & 0 deletions
68
WordPress/Classes/ViewRelated/Pages/PageListItemViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import Foundation | ||
|
||
final class PageListItemViewModel { | ||
let page: Page | ||
@Published var title: NSAttributedString | ||
let badgeIcon: UIImage? | ||
let badges: String | ||
let imageURL: URL? | ||
let accessibilityIdentifier: String? | ||
|
||
init(page: Page) { | ||
self.page = page | ||
self.title = makeContentAttributedString(for: page) | ||
self.badgeIcon = makeBadgeIcon(for: page) | ||
self.badges = makeBadgesString(for: page) | ||
self.imageURL = page.featuredImageURL | ||
self.accessibilityIdentifier = page.slugForDisplay() | ||
} | ||
} | ||
|
||
private func makeContentAttributedString(for page: Page) -> NSAttributedString { | ||
let page = page.hasRevision() ? page.revision : page | ||
let title = page?.titleForDisplay() ?? "" | ||
return NSAttributedString(string: title, attributes: [ | ||
.font: WPStyleGuide.fontForTextStyle(.callout, fontWeight: .semibold), | ||
.foregroundColor: UIColor.text | ||
]) | ||
} | ||
|
||
private func makeBadgeIcon(for page: Page) -> UIImage? { | ||
if page.isSiteHomepage { | ||
return UIImage(named: "home") | ||
} | ||
if page.isSitePostsPage { | ||
return UIImage(named: "posts") | ||
} | ||
return nil | ||
} | ||
|
||
private func makeBadgesString(for page: Page) -> String { | ||
var badges: [String] = [] | ||
if page.isSiteHomepage { | ||
badges.append(Strings.badgeHomepage) | ||
} else if page.isSitePostsPage { | ||
badges.append(Strings.badgePosts) | ||
} | ||
if let displayDate = page.displayDate() { | ||
badges.append(displayDate.capitalized) | ||
} | ||
if page.hasPrivateState { | ||
badges.append(Strings.badgePrivatePage) | ||
} | ||
if page.hasPendingReviewState { | ||
badges.append(Strings.badgePendingReview) | ||
} | ||
if page.hasLocalChanges() { | ||
badges.append(Strings.badgeLocalChanges) | ||
} | ||
return badges.joined(separator: " · ") | ||
} | ||
|
||
private enum Strings { | ||
static let badgeHomepage = NSLocalizedString("pageList.badgeHomepage", value: "Homepage", comment: "Badge for page cells") | ||
static let badgePosts = NSLocalizedString("pageList.badgePosts", value: "Posts page", comment: "Badge for page cells") | ||
static let badgePrivatePage = NSLocalizedString("pageList.badgePrivate", value: "Private", comment: "Badge for page cells") | ||
static let badgePendingReview = NSLocalizedString("pageList.badgePendingReview", value: "Pending review", comment: "Badge for page cells") | ||
static let badgeLocalChanges = NSLocalizedString("pageList.badgeLocalChanges", value: "Local changes", comment: "Badge for page cells") | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you mentioned already, we'll need to prepend dates with "Published", "Edited", or "Scheduled". When we do, I think we can drop .capitalized as well as the .capitalizeFirstWord in PostListItemViewModel
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove it once we add these labels.