Files
Pulse/Sources/PulseUI/Views/MainViewController.swift
2023-04-18 19:17:14 -04:00

55 lines
1.6 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 20202023 Alexander Grebenyuk (github.com/kean).
#if os(iOS)
import Foundation
import UIKit
import Pulse
import SwiftUI
public final class MainViewController: UIViewController {
private let environment: ConsoleEnvironment
public static var isAutomaticAppearanceOverrideRemovalEnabled = true
public init(store: LoggerStore = .shared) {
self.environment = ConsoleEnvironment(store: store)
super.init(nibName: nil, bundle: nil)
if MainViewController.isAutomaticAppearanceOverrideRemovalEnabled {
removeAppearanceOverrides()
}
let console = ConsoleView(environment: environment)
let vc = UIHostingController(rootView: NavigationView { console })
addChild(vc)
view.addSubview(vc.view)
vc.view.pinToSuperview()
}
@available(*, deprecated, message: "onDismiss parameter is deprecated")
public convenience init(store: LoggerStore = .shared, onDismiss: @escaping () -> Void) {
self.init(store: store)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
private var isAppearanceCleanupNeeded = true
private func removeAppearanceOverrides() {
guard isAppearanceCleanupNeeded else { return }
isAppearanceCleanupNeeded = false
let appearance = UINavigationBar.appearance(whenContainedInInstancesOf: [MainViewController.self])
appearance.tintColor = nil
appearance.barTintColor = nil
appearance.titleTextAttributes = nil
appearance.isTranslucent = true
}
#endif