Skip to content

Commit 2f39128

Browse files
authored
Reader: Minor Improvements (#23700)
* Add ReaderStreamTitleView.makeForFollowing * Add ReaderNavigationCustomTitleView to fake navigation title appearance with animation * Fix an issue with scrollViewToTop after selecting interests * Add dot * Add custom titles for Recent * Implement only for Recent * Add custom header in Discover * Fix title for Saved * Fix background color fo site icon placeholders in the Reader menu * Fix an issue with chevron in sidebar showing wrong icon when collapsed * Extract ReaderPostToolbarViewModel * Use Sans font for site details * Integrate new title when showing sites * Add white background and border to avatars * Fix add tag presentation * Reduce spacing for buttons in Subscriptions view * Remove subscription URLs in compact mode
1 parent ecbf1d4 commit 2f39128

16 files changed

+158
-47
lines changed

WordPress/Classes/System/ReaderPresenter.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
143143
case .addTag:
144144
let addTagVC = UIHostingController(rootView: ReaderTagsAddTagView())
145145
addTagVC.modalPresentationStyle = .formSheet
146-
addTagVC.preferredContentSize = CGSize(width: 420, height: 124)
146+
let preferredHeight: CGFloat = 124
147+
addTagVC.sheetPresentationController?.detents = [.custom(resolver: { _ in
148+
preferredHeight
149+
})]
150+
addTagVC.preferredContentSize = CGSize(width: 420, height: preferredHeight)
147151
sidebar.present(addTagVC, animated: true, completion: nil)
148152
case .discoverTags:
149153
let tags = viewContext.allObjects(

WordPress/Classes/Utility/Media/ImageView.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ final class ImageView: UIView {
1919
var isErrorViewEnabled = true
2020
var loadingStyle = LoadingStyle.background
2121

22+
/// The background color to use when the image is loaded.
23+
var successBackgroundColor = UIColor.clear
24+
2225
override init(frame: CGRect) {
2326
super.init(frame: frame)
2427

@@ -69,7 +72,7 @@ final class ImageView: UIView {
6972
case .success(let image):
7073
imageView.configure(image: image)
7174
imageView.isHidden = false
72-
backgroundColor = .clear
75+
backgroundColor = successBackgroundColor
7376
case .failure:
7477
if isErrorViewEnabled {
7578
makeErrorView().isHidden = false

WordPress/Classes/Utility/SharedStrings.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,9 @@ enum SharedStrings {
2727

2828
enum Reader {
2929
static let unfollow = NSLocalizedString("reader.button.unfollow", value: "Unfollow", comment: "Reader sidebar button title")
30+
static let recent = NSLocalizedString("reader.recent.title", value: "Recent", comment: "Used in multiple contexts, usually as a screen title")
31+
static let discover = NSLocalizedString("reader.discover.title", value: "Discover", comment: "Used in multiple contexts, usually as a screen title")
32+
static let saved = NSLocalizedString("reader.saved.title", value: "Saved", comment: "Used in multiple contexts, usually as a screen title")
33+
static let likes = NSLocalizedString("reader.likes.title", value: "Likes", comment: "Used in multiple contexts, usually as a screen title")
3034
}
3135
}

WordPress/Classes/ViewRelated/Reader/ReaderDiscoverHeaderView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ protocol ReaderDiscoverHeaderViewDelegate: AnyObject {
55
}
66

77
final class ReaderDiscoverHeaderView: UIView, UITextViewDelegate {
8-
private let titleView = ReaderStreamTitleView()
8+
private let titleView = ReaderStreamTitleView(insets: nil)
99
private let channelsStackView = UIStackView(spacing: 8, [])
1010
private var channelViews: [ReaderDiscoverChannelView] = []
1111

@@ -25,9 +25,9 @@ final class ReaderDiscoverHeaderView: UIView, UITextViewDelegate {
2525

2626
let stackView = UIStackView(axis: .vertical, spacing: 8, [titleView, scrollView])
2727
addSubview(stackView)
28-
stackView.pinEdges(insets: UIEdgeInsets(top: 16, left: 16, bottom: 8, right: 16))
28+
stackView.pinEdges(insets: ReaderStreamTitleView.preferredInsets)
2929

30-
titleView.titleLabel.text = Strings.title
30+
titleView.titleLabel.text = SharedStrings.Reader.discover
3131
titleView.detailsTextView.attributedText = {
3232
guard let details = try? NSMutableAttributedString(markdown: Strings.details) else {
3333
return nil
@@ -204,7 +204,6 @@ enum ReaderDiscoverChannel: Hashable {
204204
}
205205

206206
private enum Strings {
207-
static let title = NSLocalizedString("reader.discover.header.title", value: "Discover", comment: "Header view title")
208207
static let details = NSLocalizedString("reader.discover.header.title", value: "Explore popular blogs that inspire, educate, and entertain based on your [interests](/interests).", comment: "Reader Discover header view details label. The text has a Markdown URL: [interests](/interests). Only the text in the square brackets needs to be translated: [<translate_this>](/interests).")
209208
static let editInterests = NSLocalizedString("reader.editInterests.title", value: "Edit Interests", comment: "Screen title")
210209
}

WordPress/Classes/ViewRelated/Reader/ReaderDiscoverViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,16 @@ class ReaderDiscoverViewController: UIViewController, ReaderDiscoverHeaderViewDe
9393

9494
if FeatureFlag.readerReset.enabled {
9595
// Important to set before `viewDidLoad`
96-
streamVC.isReaderResetDiscoverEnabled = true
96+
streamVC.isEmbeddedInDiscover = true
9797
streamVC.setHeaderView(headerView)
9898
}
9999

100100
addChild(streamVC)
101101
view.addSubview(streamVC.view)
102102
streamVC.view.pinEdges()
103103
streamVC.didMove(toParent: self)
104+
105+
navigationItem.titleView = streamVC.navigationItem.titleView // important
104106
}
105107

106108
/// TODO: (tech-debt) the app currently stores the responses from the `/discover`

WordPress/Classes/ViewRelated/Reader/ReaderPostCell.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ private final class ReaderPostCellView: UIView {
132132
private func setupStyle() {
133133
avatarView.layer.cornerRadius = ReaderPostCell.avatarSize / 2
134134
avatarView.layer.masksToBounds = true
135+
avatarView.successBackgroundColor = UIColor.white
136+
avatarView.layer.borderWidth = 0.5
137+
avatarView.layer.borderColor = UIColor.opaqueSeparator.withAlphaComponent(0.5).cgColor
135138
avatarView.isErrorViewEnabled = false
136139

137140
buttonAuthor.maximumContentSizeCategory = .accessibilityLarge
@@ -299,6 +302,11 @@ private final class ReaderPostCellView: UIView {
299302
imageView.setImage(with: imageURL)
300303
}
301304

305+
configureToolbar(with: viewModel.toolbar)
306+
configureToolbarAccessibility(with: viewModel.toolbar)
307+
}
308+
309+
private func configureToolbar(with viewModel: ReaderPostToolbarViewModel) {
302310
buttons.bookmark.configuration = {
303311
var configuration = buttons.bookmark.configuration ?? .plain()
304312
configuration.image = UIImage(systemName: viewModel.isBookmarked ? "bookmark.fill" : "bookmark")
@@ -320,8 +328,6 @@ private final class ReaderPostCellView: UIView {
320328
return configuration
321329
}()
322330
}
323-
324-
configureAccessibility(with: viewModel)
325331
}
326332

327333
private func setAvatar(with viewModel: ReaderPostCellViewModel) {
@@ -401,7 +407,7 @@ private extension ReaderPostCellView {
401407
buttons.like.accessibilityIdentifier = "reader-like-button"
402408
}
403409

404-
func configureAccessibility(with viewModel: ReaderPostCellViewModel) {
410+
func configureToolbarAccessibility(with viewModel: ReaderPostToolbarViewModel) {
405411
buttons.bookmark.accessibilityLabel = viewModel.isBookmarked ? NSLocalizedString("reader.post.buttonRemoveBookmark.accessibilityLint", value: "Remove bookmark", comment: "Button accessibility label") : NSLocalizedString("reader.post.buttonBookmark.accessibilityLabel", value: "Bookmark", comment: "Button accessibility label")
406412
buttons.reblog.accessibilityLabel = NSLocalizedString("reader.post.buttonReblog.accessibilityLabel", value: "Reblog", comment: "Button accessibility label")
407413
buttons.comment.accessibilityLabel = {

WordPress/Classes/ViewRelated/Reader/ReaderPostCellViewModel.swift

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,7 @@ final class ReaderPostCellViewModel {
1212
let imageURL: URL?
1313

1414
// Footer (Buttons)
15-
let isBookmarked: Bool
16-
let isCommentsEnabled: Bool
17-
let commentCount: Int
18-
let isLikesEnabled: Bool
19-
let likeCount: Int
20-
let isLiked: Bool
15+
let toolbar: ReaderPostToolbarViewModel
2116

2217
weak var viewController: ReaderStreamViewController?
2318

@@ -32,7 +27,6 @@ final class ReaderPostCellViewModel {
3227
self.post = post
3328

3429
let isP2 = (topic as? ReaderSiteTopic)?.isP2Type == true
35-
3630
if isP2 {
3731
self.author = post.authorDisplayName ?? ""
3832
} else {
@@ -42,15 +36,7 @@ final class ReaderPostCellViewModel {
4236
self.title = post.titleForDisplay() ?? ""
4337
self.details = post.contentPreviewForDisplay() ?? ""
4438
self.imageURL = post.featuredImageURLForDisplay()
45-
46-
self.isBookmarked = post.isSavedForLater
47-
48-
self.isCommentsEnabled = post.isCommentsEnabled
49-
self.commentCount = post.commentCount?.intValue ?? 0
50-
51-
self.isLikesEnabled = post.isLikesEnabled()
52-
self.likeCount = post.likeCount?.intValue ?? 0
53-
self.isLiked = post.isLiked()
39+
self.toolbar = ReaderPostToolbarViewModel.make(post: post)
5440

5541
if isP2 {
5642
self.avatarURL = post.authorAvatarURL.flatMap(URL.init)
@@ -75,12 +61,14 @@ final class ReaderPostCellViewModel {
7561
self.title = "Discovering the Wonders of the Wild"
7662
self.details = "Lorem ipsum dolor sit amet. Non omnis quia et natus voluptatum et eligendi voluptate vel iusto fuga sit repellendus molestiae aut voluptatem blanditiis ad neque sapiente. Id galisum distinctio quo enim aperiam non veritatis vitae et ducimus rerum."
7763
self.imageURL = URL(string: "https://picsum.photos/1260/630.jpg")
78-
self.isBookmarked = false
79-
self.isLikesEnabled = true
80-
self.likeCount = 9000
81-
self.isCommentsEnabled = true
82-
self.commentCount = 213
83-
self.isLiked = true
64+
self.toolbar = ReaderPostToolbarViewModel(
65+
isBookmarked: false,
66+
isCommentsEnabled: true,
67+
commentCount: 9000,
68+
isLikesEnabled: true,
69+
likeCount: 213,
70+
isLiked: true
71+
)
8472
}
8573

8674
static func mock() -> ReaderPostCellViewModel {
@@ -113,3 +101,23 @@ final class ReaderPostCellViewModel {
113101
ReaderLikeAction().execute(with: post)
114102
}
115103
}
104+
105+
struct ReaderPostToolbarViewModel {
106+
let isBookmarked: Bool
107+
let isCommentsEnabled: Bool
108+
let commentCount: Int
109+
let isLikesEnabled: Bool
110+
let likeCount: Int
111+
let isLiked: Bool
112+
113+
static func make(post: ReaderPost) -> ReaderPostToolbarViewModel {
114+
ReaderPostToolbarViewModel(
115+
isBookmarked: post.isSavedForLater,
116+
isCommentsEnabled: post.isCommentsEnabled,
117+
commentCount: post.commentCount?.intValue ?? 0,
118+
isLikesEnabled: post.isLikesEnabled(),
119+
likeCount: post.likeCount?.intValue ?? 0,
120+
isLiked: post.isLiked()
121+
)
122+
}
123+
}

WordPress/Classes/ViewRelated/Reader/ReaderSidebarSubscriptionsSection.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ struct ReaderSidebarSubscriptionsSection: View {
1818
Text(site.title)
1919
} icon: {
2020
SiteIconView(viewModel: SiteIconViewModel(readerSiteTopic: site, size: .small))
21-
.environment(\.siteIconBackgroundColor, Color(.systemBackground))
2221
.frame(width: 28, height: 28)
2322
}
2423
.lineLimit(1)

WordPress/Classes/ViewRelated/Reader/ReaderSidebarViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ private struct ReaderSidebarView: View {
108108
}
109109
makeSection(Strings.lists, isExpanded: $isSectionListsExpanded) {
110110
ReaderSidebarListsSection(viewModel: viewModel)
111+
.environment(\.siteIconBackgroundColor, Color(viewModel.isCompact ? .secondarySystemBackground : .systemBackground))
111112
}
112113
makeSection(Strings.tags, isExpanded: $isSectionTagsExpanded) {
113114
ReaderSidebarTagsSection(viewModel: viewModel)
@@ -160,7 +161,7 @@ private struct ReaderSidebarSection<Content: View>: View {
160161
.font(.subheadline.weight(.semibold))
161162
.foregroundStyle(.secondary)
162163
Spacer()
163-
Image(systemName: "chevron.down")
164+
Image(systemName: isExpanded ? "chevron.down" : "chevron.right")
164165
.font(.system(size: 14).weight(.semibold))
165166
.foregroundStyle(AppColor.brand)
166167
}

WordPress/Classes/ViewRelated/Reader/ReaderSiteHeaderView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct ReaderSiteHeader: View {
9494
}
9595
VStack(alignment: .leading, spacing: 4) {
9696
Text(viewModel.title)
97-
.font(Font(WPStyleGuide.serifFontForTextStyle(.title2, fontWeight: .semibold)))
97+
.font(Font(WPStyleGuide.fontForTextStyle(.title1, fontWeight: .semibold)))
9898
Text(viewModel.siteUrl)
9999
.font(.subheadline)
100100
}

0 commit comments

Comments
 (0)