Tusker/Tusker/Screens/Preferences/PreferencesNavigationContro...

37 lines
1.1 KiB
Swift
Raw Normal View History

//
// PreferencesHostingController.swift
// Tusker
//
// Created by Shadowfacts on 11/17/19.
// Copyright © 2019 Shadowfacts. All rights reserved.
//
import UIKit
import SwiftUI
class PreferencesNavigationController: UINavigationController {
init(mastodonController: MastodonController) {
let view = PreferencesView(currentAccount: mastodonController.accountInfo!)
let hostingController = UIHostingController(rootView: view)
super.init(rootViewController: hostingController)
hostingController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// workaround for onDisappear not being called when a modally presented UIHostingController is dismissed
NotificationCenter.default.post(name: .preferencesChanged, object: nil)
}
@objc func donePressed() {
dismiss(animated: true)
}
}