frenzy-ios/Reader/Screens/AppSplitViewController.swift

72 lines
2.2 KiB
Swift

//
// 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)
}
}
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 {
delegate.switchToAccount(account)
}
}
}