Skip to content

DRY notifications stack storyboard and initial VC access #24464

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

Merged
merged 2 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions WordPress/Classes/Apps/Reader/ReaderTabViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ final class ReaderTabViewController: UITabBarController, UITabBarControllerDeleg
}

private func makeNotificationsViewController() -> UIViewController {
let notificationsVC = UIStoryboard(name: "Notifications", bundle: Bundle(for: Self.self))
.instantiateInitialViewController() as! NotificationsViewController
let notificationsVC = Notifications.instantiateInitialViewController()
notificationsVC.tabBarItem = UITabBarItem(
title: Strings.notifications,
image: UIImage(named: "tab-bar-notifications"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class NotificationsSplitViewContent: SplitViewDisplayable {
var secondary: UINavigationController

init() {
notificationsViewController = UIStoryboard(name: "Notifications", bundle: nil).instantiateInitialViewController() as! NotificationsViewController
notificationsViewController = Notifications.instantiateInitialViewController()
supplementary = UINavigationController(rootViewController: notificationsViewController)
secondary = UINavigationController()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ 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
let notificationsVC = Notifications.instantiateInitialViewController()
notificationsVC.isSidebarModeEnabled = true

let navigationVC = UINavigationController(rootViewController: notificationsVC)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import Foundation
import WordPressShared

// This facilitates showing the CommentDetailViewController within the context of Notifications.
enum Notifications {
private static let storyboardName = "Notifications"

static let storyboard = UIStoryboard(
name: Notifications.storyboardName,
bundle: Bundle(for: NotificationsViewController.self)
)

static func instantiateInitialViewController() -> NotificationsViewController {
storyboard.instantiateInitialViewController() as! NotificationsViewController
}
}

/// Facilitates showing the `CommentDetailViewController` within the context of Notifications.
protocol CommentDetailsNotificationDelegate: AnyObject {
func previousNotificationTapped(current: Notification?)
func nextNotificationTapped(current: Notification?)
Expand Down Expand Up @@ -76,10 +88,9 @@ private extension NotificationCommentDetailCoordinator {
}

func showNotificationDetails(with notification: Notification) {
let storyboard = UIStoryboard(name: Notifications.storyboardName, bundle: nil)

guard let viewController,
let notificationDetailsViewController = storyboard.instantiateViewController(withIdentifier: Notifications.viewControllerName) as? NotificationDetailsViewController else {
let notificationDetailsViewController = Notifications.storyboard
.instantiateViewController(withIdentifier: NotificationDetailsViewController.classNameWithoutNamespaces()) as? NotificationDetailsViewController else {
DDLogError("NotificationCommentDetailCoordinator: missing view controller.")
return
}
Expand Down Expand Up @@ -125,12 +136,6 @@ private extension NotificationCommentDetailCoordinator {
let properties = ["notification_type": notification.type ?? "unknown"]
WPAnalytics.track(.openedNotificationDetails, withProperties: properties)
}

enum Notifications {
static let storyboardName = "Notifications"
static let viewControllerName = NotificationDetailsViewController.classNameWithoutNamespaces()
}

}

// MARK: - CommentDetailsNotificationDelegate
Expand Down