Skip to content

Commit 46d183f

Browse files
authored
Add scroll-to-top button to Reader streams (#23957)
2 parents f0e5730 + 2069c49 commit 46d183f

File tree

9 files changed

+53
-81
lines changed

9 files changed

+53
-81
lines changed

RELEASE-NOTES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
* [*] Show selected filter in the Discover navigation bar [#23956]
2020
* [*] Enable fast deceleration for filters on the Discover tab [#23954]
2121
* [*] Disable universal links support for QR code login. You can only scan the codes using the app now. [#23953]
22+
* [*] Add scroll-to-top button to Reader streams [#23957]
23+
2224

2325
25.6
2426
-----

WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Foundation
55

66
case createSheetShown
77
case createSheetActionTapped
8-
case createAnnouncementModalShown
98

109
// Media Editor
1110
case mediaEditorShown
@@ -117,6 +116,7 @@ import Foundation
117116
case readerCommentTextCopied
118117
case readerPostContextMenuButtonTapped
119118
case readerAddSiteToFavoritesTapped
119+
case readerButtonScrollToTopTapped
120120

121121
// Stats - Empty Stats nudges
122122
case statsPublicizeNudgeShown
@@ -625,8 +625,6 @@ import Foundation
625625
return "create_sheet_shown"
626626
case .createSheetActionTapped:
627627
return "create_sheet_action_tapped"
628-
case .createAnnouncementModalShown:
629-
return "create_announcement_modal_shown"
630628
// Media Editor
631629
case .mediaEditorShown:
632630
return "media_editor_shown"
@@ -819,6 +817,8 @@ import Foundation
819817
return "reader_post_context_menu_button_tapped"
820818
case .readerAddSiteToFavoritesTapped:
821819
return "reader_add_site_to_favorites_tapped"
820+
case .readerButtonScrollToTopTapped:
821+
return "reader_button_scroll_to_top_tapped"
822822

823823
// Stats - Empty Stats nudges
824824
case .statsPublicizeNudgeShown:

WordPress/Classes/ViewRelated/Reader/Cards/ReaderPostCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ private final class ReaderPostCellView: UIView {
168168
avatarView.widthAnchor.constraint(equalToConstant: ReaderPostCell.avatarSize),
169169
avatarView.heightAnchor.constraint(equalToConstant: ReaderPostCell.avatarSize),
170170
avatarView.centerYAnchor.constraint(equalTo: timeLabel.centerYAnchor),
171-
avatarView.trailingAnchor.constraint(equalTo: headerView.leadingAnchor, constant: -8),
171+
avatarView.trailingAnchor.constraint(equalTo: headerView.leadingAnchor, constant: -9),
172172

173173
headerView.topAnchor.constraint(equalTo: topAnchor, constant: 6),
174174
headerView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: insets.left),

WordPress/Classes/ViewRelated/Reader/Cards/ReaderStreamBaseCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import UIKit
22

33
class ReaderStreamBaseCell: UITableViewCell {
4-
static let insets = UIEdgeInsets(top: 0, left: 44, bottom: 0, right: 16)
4+
static let insets = UIEdgeInsets(top: 0, left: 46, bottom: 0, right: 16)
55

66
var isCompact: Bool = true {
77
didSet {

WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,16 @@ import AutomatticTracks
6565
return refreshControl
6666
}()
6767

68+
private lazy var buttonScrollToTop = ReaderButtonScrollToTop.make { [weak self] in
69+
self?.tableView.scrollToTop(animated: true)
70+
}
71+
6872
let titleView = ReaderNavigationCustomTitleView()
6973

7074
private let loadMoreThreashold = 5
7175
private let refreshInterval = 300
7276
private var cleanupAndRefreshAfterScrolling = false
7377
private let recentlyBlockedSitePostObjectIDs = NSMutableArray()
74-
private let heightForFooterView = CGFloat(44)
7578
private let estimatedHeightsCache = NSCache<AnyObject, AnyObject>()
7679
private var isFeed = false
7780
private var syncIsFillingGap = false
@@ -303,6 +306,7 @@ import AutomatticTracks
303306
setupTableView()
304307
setupFooterView()
305308
setupContentHandler()
309+
setupButtonScrollToTop()
306310

307311
observeNetworkStatus()
308312

@@ -493,9 +497,14 @@ import AutomatticTracks
493497
content.initializeContent(tableView: tableView, delegate: self)
494498
}
495499

500+
private func setupButtonScrollToTop() {
501+
view.addSubview(buttonScrollToTop)
502+
buttonScrollToTop.pinEdges([.leading, .bottom], to: view.safeAreaLayoutGuide, insets: isCompact ? UIEdgeInsets(horizontal: 8, vertical: 16) : UIEdgeInsets(.all, 20))
503+
}
504+
496505
private func setupFooterView() {
497506
var frame = footerView.frame
498-
frame.size.height = heightForFooterView
507+
frame.size.height = 44
499508
footerView.frame = frame
500509
tableView.tableFooterView = footerView
501510
footerView.isHidden = true
@@ -1661,6 +1670,7 @@ extension ReaderStreamViewController: UITableViewDelegate, JPScrollViewDelegate
16611670
layoutEmptyStateView()
16621671
processJetpackBannerVisibility(scrollView)
16631672
titleView.updateAlpha(in: scrollView)
1673+
buttonScrollToTop.setButtonHidden(scrollView.contentOffset.y < view.bounds.height / 3, animated: true)
16641674
}
16651675
}
16661676

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import UIKit
2+
3+
final class ReaderButtonScrollToTop: UIButton {
4+
private var isButtonHidden = false
5+
6+
static func make(closure: @escaping () -> Void) -> ReaderButtonScrollToTop {
7+
var configuration = UIButton.Configuration.bordered()
8+
configuration.image = UIImage(systemName: "arrow.up")?
9+
.withConfiguration(UIImage.SymbolConfiguration(pointSize: 12, weight: .regular))
10+
configuration.cornerStyle = .capsule
11+
configuration.baseBackgroundColor = .secondarySystemBackground
12+
configuration.baseForegroundColor = .label
13+
configuration.contentInsets = .init(top: 10, leading: 10, bottom: 10, trailing: 10)
14+
15+
return ReaderButtonScrollToTop(configuration: configuration, primaryAction: .init { _ in
16+
closure()
17+
WPAnalytics.track(.readerButtonScrollToTopTapped)
18+
})
19+
}
20+
21+
func setButtonHidden(_ isHidden: Bool, animated: Bool) {
22+
guard isButtonHidden != isHidden else { return }
23+
isButtonHidden = isHidden
24+
25+
UIView.animate(withDuration: animated ? 0.33 : 0.0) {
26+
self.alpha = isHidden ? 0 : 1
27+
self.isUserInteractionEnabled = !isHidden
28+
}
29+
}
30+
31+
override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
32+
bounds.insetBy(dx: -8, dy: -10).contains(point)
33+
}
34+
}

WordPress/Classes/ViewRelated/System/Floating Create Button/FancyAlertViewController+CreateButtonAnnouncement.swift

Lines changed: 0 additions & 62 deletions
This file was deleted.

WordPress/Resources/AppImages.xcassets/Illustrations/wp-illustration-ia-announcement.imageset/Contents.json

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)