Skip to content

Commit

Permalink
Enable quick access to notifications from Reader (#23882)
Browse files Browse the repository at this point in the history
* Enable quick access to notifications from Reader

* Fix spacing

* Update release notes
  • Loading branch information
kean authored Dec 11, 2024
1 parent 629899b commit 9e972b6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 25 deletions.
2 changes: 2 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* [*] [internal] Update Gravatar SDK to 3.0.0 [#23701]
* [*] Use the Gravatar Quick Editor to update the avatar [#23729]
* [*] (Hidden under a feature flag) User Management for self-hosted sites. [#23768]
* [*] Enable quick access to notifications from Reader on iPad [#23882]
* [*] Add support for restricted posts in Reader [#23853]

25.5
-----
Expand Down
8 changes: 6 additions & 2 deletions WordPress/Classes/System/Root View/ReaderPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,17 @@ final class ReaderPresenter: NSObject, SplitViewDisplayable {
if screen == .discover {
return ReaderDiscoverViewController(topic: topic)
} else {
return ReaderStreamViewController.controllerWithTopic(topic)
let streamVC = ReaderStreamViewController.controllerWithTopic(topic)
streamVC.isNotificationsBarButtonEnabled = true
return streamVC
}
} else {
return makeErrorViewController() // This should never happen
}
case .saved:
return ReaderStreamViewController.controllerForContentType(.saved)
let streamVC = ReaderStreamViewController.controllerForContentType(.saved)
streamVC.isNotificationsBarButtonEnabled = true
return streamVC
case .search:
return ReaderSearchViewController()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,33 +286,15 @@ final class MySiteViewController: UIViewController, UIScrollViewDelegate, NoSite
navigationController?.navigationBar.accessibilityIdentifier = "my-site-navigation-bar"

if isSidebarModeEnabled {
navigationItem.rightBarButtonItems = makeRegularClassSizeNavigationItems()

notificationsButtonViewModel.$image.dropFirst()
.receive(on: DispatchQueue.main) // Skip on hop
.sink { [weak self] _ in
guard let self else { return }
self.navigationItem.rightBarButtonItems = self.makeRegularClassSizeNavigationItems()
}.store(in: &cancellables)
notificationsButtonViewModel.$image.sink { [weak self] in
guard let self else { return }
self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: $0, style: .plain, target: self, action: #selector(buttonShowNotificationsTapped))
}.store(in: &cancellables)
}
}

private func makeRegularClassSizeNavigationItems() -> [UIBarButtonItem] {
return [
UIBarButtonItem(image: notificationsButtonViewModel.image, style: .plain, target: self, action: #selector(buttonShowNotificationsTapped))
]
}

@objc private func buttonShowNotificationsTapped(_ sender: UIBarButtonItem) {
let notificationsVC = UIStoryboard(name: "Notifications", bundle: nil).instantiateInitialViewController() as! NotificationsViewController
notificationsVC.isSidebarModeEnabled = true

let navigationVC = UINavigationController(rootViewController: notificationsVC)
navigationVC.modalPresentationStyle = .popover
navigationVC.preferredContentSize = CGSize(width: 375, height: 800)
navigationVC.popoverPresentationController?.sourceItem = sender
navigationVC.popoverPresentationController?.permittedArrowDirections = [.up]
present(navigationVC, animated: true)
NotificationsViewController.showInPopover(from: self, sourceItem: sender)
}

private func configureNavBarAppearance(animated: Bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,18 @@ class NotificationsViewController: UIViewController, UITableViewDataSource, UITa

// MARK: - View Lifecycle

static func showInPopover(from presentingVC: UIViewController, sourceItem: UIPopoverPresentationControllerSourceItem) {
let notificationsVC = UIStoryboard(name: "Notifications", bundle: nil).instantiateInitialViewController() as! NotificationsViewController
notificationsVC.isSidebarModeEnabled = true

let navigationVC = UINavigationController(rootViewController: notificationsVC)
navigationVC.modalPresentationStyle = .popover
navigationVC.preferredContentSize = CGSize(width: 375, height: 800)
navigationVC.popoverPresentationController?.sourceItem = sourceItem
navigationVC.popoverPresentationController?.permittedArrowDirections = [.up]
presentingVC.present(navigationVC, animated: true)
}

required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ReaderDiscoverViewController: UIViewController, ReaderDiscoverHeaderViewDe
private let tags: ManagedObjectsObserver<ReaderTagTopic>
private let viewContext: NSManagedObjectContext
private var cancellables: [AnyCancellable] = []
private let notificationsButtonViewModel = NotificationsButtonViewModel()
private var notificationsButtonCancellable: AnyCancellable?

init(topic: ReaderAbstractTopic) {
wpAssert(ReaderHelpers.topicIsDiscover(topic))
Expand Down Expand Up @@ -42,8 +44,29 @@ class ReaderDiscoverViewController: UIViewController, ReaderDiscoverHeaderViewDe
showSelectInterestsIfNeeded()
}

override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)

setupNotificationsBarButtonItem()
}

private func setupNavigation() {
navigationItem.largeTitleDisplayMode = .never
setupNotificationsBarButtonItem()
}

private func setupNotificationsBarButtonItem() {
notificationsButtonCancellable = nil
if traitCollection.horizontalSizeClass == .regular {
notificationsButtonCancellable = notificationsButtonViewModel.$image.sink { [weak self] in
guard let self else { return }
self.navigationItem.rightBarButtonItems = [UIBarButtonItem(image: $0, style: .plain, target: self, action: #selector(buttonShowNotificationsTapped))]
}
}
}

@objc private func buttonShowNotificationsTapped(_ sender: UIBarButtonItem) {
NotificationsViewController.showInPopover(from: self, sourceItem: sender)
}

private func setupHeaderView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ import AutomatticTracks
private var didBumpStats = false
@Lazy private var titleView = ReaderNavigationCustomTitleView()
internal let scrollViewTranslationPublisher = PassthroughSubject<Bool, Never>()
private let notificationsButtonViewModel = NotificationsButtonViewModel()
private var notificationsButtonCancellable: AnyCancellable?

/// Content management
let content = ReaderTableContent()
Expand Down Expand Up @@ -176,6 +178,7 @@ import AutomatticTracks
private var showConfirmation = true

var isEmbeddedInDiscover = false
var isNotificationsBarButtonEnabled = false
var preferredTableHeaderView: UIView?

var isCompact = true {
Expand Down Expand Up @@ -350,13 +353,28 @@ import AutomatticTracks
super.traitCollectionDidChange(previousTraitCollection)

isCompact = traitCollection.horizontalSizeClass == .compact
setupNotificationsBarButtonItem()
}

private func didChangeIsCompact(_ isCompact: Bool) {
(tableView.tableHeaderView as? ReaderBaseHeaderView)?.isCompact = isCompact
tableView.reloadData()
}

private func setupNotificationsBarButtonItem() {
notificationsButtonCancellable = nil
if isNotificationsBarButtonEnabled && traitCollection.horizontalSizeClass == .regular {
notificationsButtonCancellable = notificationsButtonViewModel.$image.sink { [weak self] in
guard let self else { return }
self.navigationItem.rightBarButtonItems = [UIBarButtonItem(image: $0, style: .plain, target: self, action: #selector(buttonShowNotificationsTapped))]
}
}
}

@objc private func buttonShowNotificationsTapped(_ sender: UIBarButtonItem) {
NotificationsViewController.showInPopover(from: self, sourceItem: sender)
}

// MARK: - Topic acquisition

/// Fetches a site topic for the value of the `siteID` property.
Expand Down

0 comments on commit 9e972b6

Please sign in to comment.