-
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
Reader: Fix cropped recommended sites #23802
Merged
+199
−494
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d9eaad5
Integrate new ReaderRecommendedSitesCell
kean 273c559
Implement subscribe/unsubscribe flow
kean c82d792
Implement show details
kean faf3f6b
Remove ReaderRecommendedSiteCardCell
kean 69c785c
Remove ReaderSitesCardCell
kean acdc2e3
Remove ReaderTopicsTableCardCell
kean 6f93f74
Add vertical spacing for recommended sites
kean 9acbf09
Revert size change
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
Next
Next commit
Integrate new ReaderRecommendedSitesCell
commit d9eaad590b8c83f23c2138e44796ffc0b5fcc0ab
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
130 changes: 130 additions & 0 deletions
130
WordPress/Classes/ViewRelated/Reader/Cards/ReaderRecommendedSitesCell.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,130 @@ | ||
import SwiftUI | ||
import UIKit | ||
import WordPressUI | ||
|
||
final class ReaderRecommendedSitesCell: UITableViewCell { | ||
private let sitesStackView = UIStackView(axis: .vertical, spacing: 16, []) | ||
|
||
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { | ||
super.init(style: style, reuseIdentifier: reuseIdentifier) | ||
|
||
setupView() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("Not implemented") | ||
} | ||
|
||
override func prepareForReuse() { | ||
super.prepareForReuse() | ||
|
||
for view in sitesStackView.subviews { | ||
view.removeFromSuperview() | ||
} | ||
} | ||
|
||
private func setupView() { | ||
selectionStyle = .none | ||
|
||
let backgroundView = UIView() | ||
backgroundView.backgroundColor = .secondarySystemBackground | ||
backgroundView.layer.cornerRadius = 8 | ||
|
||
contentView.addSubview(backgroundView) | ||
backgroundView.pinEdges(insets: UIEdgeInsets(horizontal: 16, vertical: 0)) | ||
|
||
let titleLabel = UILabel() | ||
titleLabel.font = .preferredFont(forTextStyle: .subheadline) | ||
titleLabel.textColor = .secondaryLabel | ||
titleLabel.text = Strings.title | ||
|
||
let stackView = UIStackView(axis: .vertical, spacing: 16, [titleLabel, sitesStackView]) | ||
|
||
backgroundView.addSubview(stackView) | ||
stackView.pinEdges(insets: { | ||
var insets = UIEdgeInsets(.all, 16) | ||
insets.right = 6 // Buttons insets take care of it | ||
return insets | ||
}()) | ||
} | ||
|
||
func configure(with sites: [ReaderSiteTopic]) { | ||
for site in sites { | ||
let siteView = makeSiteView(for: site) | ||
sitesStackView.addArrangedSubview(siteView) | ||
} | ||
} | ||
|
||
private func makeSiteView(for site: ReaderSiteTopic) -> UIView { | ||
let view = ReaderRecommendedSitesCellView() | ||
view.configure(with: site) | ||
return view | ||
} | ||
} | ||
|
||
/// Presentation-agnostic view for displaying post cells. | ||
private final class ReaderRecommendedSitesCellView: UIView { | ||
let siteIconView = SiteIconHostingView() | ||
let titleLabel = UILabel() | ||
let subtitleLabel = UILabel() | ||
let buttonSubscribe = UIButton(configuration: { | ||
var configuration = UIButton.Configuration.plain() | ||
configuration.image = UIImage(systemName: "plus.circle") | ||
configuration.baseForegroundColor = UIAppColor.brand | ||
configuration.contentInsets = .zero | ||
return configuration | ||
}()) | ||
|
||
private let iconSize: SiteIconViewModel.Size = .regular | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: .zero) | ||
|
||
titleLabel.font = .preferredFont(forTextStyle: .callout).withWeight(.medium) | ||
subtitleLabel.font = .preferredFont(forTextStyle: .footnote) | ||
subtitleLabel.textColor = .secondaryLabel | ||
|
||
NSLayoutConstraint.activate([ | ||
siteIconView.widthAnchor.constraint(equalToConstant: iconSize.width), | ||
siteIconView.heightAnchor.constraint(equalToConstant: iconSize.width), | ||
]) | ||
|
||
NSLayoutConstraint.activate([ | ||
buttonSubscribe.widthAnchor.constraint(equalToConstant: 40), | ||
buttonSubscribe.heightAnchor.constraint(equalToConstant: 40), | ||
]) | ||
|
||
buttonSubscribe.setContentCompressionResistancePriority(.required, for: .horizontal) | ||
|
||
let stackView = UIStackView(alignment: .center, spacing: 6, [ | ||
siteIconView, | ||
UIStackView(axis: .vertical, alignment: .leading, spacing: 2, [ | ||
titleLabel, subtitleLabel, | ||
]), | ||
buttonSubscribe | ||
]) | ||
stackView.setCustomSpacing(14, after: siteIconView) | ||
addSubview(stackView) | ||
stackView.pinEdges() | ||
|
||
buttonSubscribe.addTarget(self, action: #selector(buttonSubscribeTapped), for: .touchUpInside) | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
func configure(with site: ReaderSiteTopic) { | ||
siteIconView.setIcon(with: .init(readerSiteTopic: site, size: iconSize)) | ||
titleLabel.text = site.title | ||
subtitleLabel.text = site.siteDescription | ||
} | ||
|
||
@objc private func buttonSubscribeTapped() { | ||
// TODO: implement | ||
} | ||
} | ||
|
||
private enum Strings { | ||
static let title = NSLocalizedString("reader.suggested.blogs.title", value: "Blogs to subscribe to", comment: "A suggestion of topics the user might want to subscribe to") | ||
} |
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
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.
Nitpick: may as well rename the label
size:
->pixelSize:
😄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.
It's actually size in points 🤦
This is how it's used:
I'm going to revert it.
Yeah, it's a low-level method. The app uses
SiteIconViewModel.Size
enum in most cases. It also ensures that you don't create too many different variants of the the same icon but off by a few points.