mvm_core_ui/MVMCoreUI/Containers/NavigationController.swift
Pfeil, Scott Robert 76aaa8c881 fix navigation bar
2020-04-07 16:55:42 -04:00

73 lines
3.8 KiB
Swift

//
// NavigationController.swift
// MVMCoreUI
//
// Created by Scott Pfeil on 10/24/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import UIKit
@objcMembers open class NavigationController: UINavigationController {
public var separatorView: Line?
public static func navigationController() -> Self? {
return MVMCoreActionUtility.initializerClassCheck(MVMCoreUISession.sharedGlobal()?.navigationController, classToVerify: self) as? Self
}
public static func style(_ navigationBar: UINavigationBar) {
UIColor.mfSetBackgroundColor(forNavigationBar: .white, navigationBar: navigationBar, transparent: false)
navigationBar.shadowImage = UIImage()
navigationBar.isOpaque = true
navigationBar.tintColor = .black
navigationBar.titleTextAttributes = [NSAttributedString.Key.font: MFStyler.fontBoldBodySmall(false)];
}
public static func setupNavigationController() -> Self? {
let navigationController = self.init()
style(navigationController.navigationBar)
navigationController.separatorView = Line(pinTo: navigationController.navigationBar, edge: .bottom, useMargin: false)
navigationController.separatorView?.setStyle(.standard)
MVMCoreUISession.sharedGlobal()?.navigationController = navigationController
MVMCoreNavigationHandler.shared()?.viewControllerToPresentOn = navigationController
MVMCoreNavigationHandler.shared()?.navigationController = navigationController
return navigationController
}
public static func setupNavigationControllerAsMainController() -> Self? {
guard let navigationController = setupNavigationController() else { return nil }
MVMCoreUISession.sharedGlobal()?.setup(asStandardLoadViewDelegate: navigationController)
return navigationController
}
public static func set(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) {
viewController.navigationItem.title = navigationItemModel.title
viewController.navigationItem.accessibilityLabel = navigationItemModel.title
viewController.navigationItem.hidesBackButton = !navigationItemModel.systemBackButton
navigationController.setNavigationBarHidden(navigationItemModel.hidden, animated: true)
UIColor.setBackgroundColor(navigationItemModel.backgroundColor?.uiColor ?? .white, for: navigationController.navigationBar, isTransparent: navigationItemModel.transparent)
let tint = navigationItemModel.tintColor.uiColor
navigationController.navigationBar.tintColor = tint
// Have the navigation title match the tint color
navigationController.navigationBar.titleTextAttributes?.updateValue(tint, forKey: .foregroundColor)
// Update icons if main navigation controller.
if navigationController == MVMCoreUISession.sharedGlobal()?.navigationController,
navigationController.topViewController == viewController {
// Update line.
MVMCoreUISession.sharedGlobal()?.navigationController?.separatorView?.setStyle(navigationItemModel.line?.type ?? .standard)
}
if navigationController == MVMCoreUISplitViewController.main()?.navigationController,
navigationController.topViewController == viewController {
// Update Panels
MVMCoreUISplitViewController.main()?.setLeftPanelIsAccessible(navigationItemModel.showLeftPanelButton ?? false, for: viewController)
MVMCoreUISplitViewController.main()?.setRightPanelIsAccessible(navigationItemModel.showRightPanelButton ?? false, for: viewController)
MVMCoreUISession.sharedGlobal()?.splitViewController?.setNavigationIconColor(tint)
}
}
}