// // AppSplitViewController.swift // Reader // // Created by Shadowfacts on 1/14/22. // import UIKit #if targetEnvironment(macCatalyst) import AppKit #endif class AppSplitViewController: UISplitViewController { private let fervorController: FervorController private var secondaryNav: UINavigationController! init(fervorController: FervorController) { self.fervorController = fervorController super.init(style: .doubleColumn) } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func viewDidLoad() { super.viewDidLoad() preferredDisplayMode = .oneBesideSecondary preferredSplitBehavior = .tile presentsWithGesture = true showsSecondaryOnlyButton = true primaryBackgroundStyle = .sidebar maximumPrimaryColumnWidth = 500 let sidebarHome = HomeViewController(fervorController: fervorController) sidebarHome.enableStretchyMenu = false sidebarHome.itemsDelegate = self let sidebarNav = UINavigationController(rootViewController: sidebarHome) sidebarNav.navigationBar.prefersLargeTitles = true setViewController(sidebarNav, for: .primary) secondaryNav = UINavigationController() secondaryNav.isNavigationBarHidden = true secondaryNav.view.backgroundColor = .appBackground setViewController(secondaryNav, for: .secondary) let home = HomeViewController(fervorController: fervorController) home.delegate = self let nav = AppNavigationController(rootViewController: home) setViewController(nav, for: .compact) } func showItemList(_ type: ItemListType) { let column: Column if traitCollection.horizontalSizeClass == .compact { column = .compact } else { column = .primary } let nav = viewController(for: column) as! UINavigationController let home = nav.viewControllers.first! as! HomeViewController home.selectItem(type) } } extension AppSplitViewController: ItemsViewControllerDelegate { func showReadItem(_ item: Item) { secondaryNav.setViewControllers([ReadViewController(item: item, fervorController: fervorController)], animated: false) } } extension AppSplitViewController: HomeViewControllerDelegate { func switchToAccount(_ account: LocalData.Account) { if let delegate = view.window?.windowScene?.delegate as? SceneDelegate { Task { @MainActor in await delegate.switchToAccount(account) } } } }