remove
This commit is contained in:
parent
e4c69d59f7
commit
21ee88c5f4
@ -1,213 +0,0 @@
|
||||
//
|
||||
// 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, MVMCoreViewManagerViewControllerProtocol {
|
||||
public weak var manager: (UIViewController & MVMCoreViewManagerProtocol)?
|
||||
|
||||
/// Getter for the main navigation controller
|
||||
public static func navigationController() -> Self? {
|
||||
return MVMCoreActionUtility.initializerClassCheck(MVMCoreUISession.sharedGlobal()?.navigationController, classToVerify: self) as? Self
|
||||
}
|
||||
|
||||
/// Sets up the application with a navigation controller
|
||||
public static func setupNavigationController() -> Self? {
|
||||
let navigationController = self.init()
|
||||
MVMCoreUISession.sharedGlobal()?.navigationController = navigationController
|
||||
MVMCoreNavigationHandler.shared()?.viewControllerToPresentOn = navigationController
|
||||
MVMCoreNavigationHandler.shared()?.navigationController = navigationController
|
||||
MVMCoreNavigationHandler.shared()?.addDelegate(navigationController)
|
||||
navigationController.setNavigationBarUI(with: NavigationItemModel())
|
||||
return navigationController
|
||||
}
|
||||
|
||||
/// Sets up the application with a navigation controller as the main container.
|
||||
public static func setupNavigationControllerAsMainController() -> Self? {
|
||||
guard let navigationController = setupNavigationController() else { return nil }
|
||||
MVMCoreUISession.sharedGlobal()?.setup(asStandardLoadViewDelegate: navigationController)
|
||||
return navigationController
|
||||
}
|
||||
|
||||
<<<<<<< HEAD:MVMCoreUI/Containers/NavigationController.swift
|
||||
/// Convenience function for setting the navigation item.
|
||||
public static func setNavigationItem(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) {
|
||||
viewController.navigationItem.title = navigationItemModel.title
|
||||
viewController.navigationItem.accessibilityLabel = navigationItemModel.title
|
||||
viewController.navigationItem.hidesBackButton = navigationItemModel.hidesSystemBackButton
|
||||
viewController.navigationItem.leftItemsSupplementBackButton = !navigationItemModel.hidesSystemBackButton
|
||||
setNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController)
|
||||
setNavigationTitleView(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController)
|
||||
}
|
||||
|
||||
/// Convenience function for setting the navigation buttons.
|
||||
public static func setNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol, viewController: UIViewController) {
|
||||
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||
var leftItems: [UIBarButtonItem] = []
|
||||
if navigationItemModel.hidesSystemBackButton,
|
||||
navigationItemModel.alwaysShowBackButton != false {
|
||||
if let backButtonModel = navigationItemModel.backButton,
|
||||
MVMCoreNavigationHandler.shared()?.getViewControllers(for: navigationController)?.count ?? 0 > 1 || navigationItemModel.alwaysShowBackButton ?? false {
|
||||
leftItems.append(backButtonModel.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||
}
|
||||
if let leftItemModels = navigationItemModel.additionalLeftButtons {
|
||||
for item in leftItemModels {
|
||||
leftItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||
}
|
||||
}
|
||||
}
|
||||
viewController.navigationItem.leftBarButtonItems = leftItems.count > 0 ? leftItems : nil
|
||||
|
||||
var rightItems: [UIBarButtonItem] = []
|
||||
if let rightItemModels = navigationItemModel.additionalRightButtons {
|
||||
for item in rightItemModels {
|
||||
rightItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||
}
|
||||
}
|
||||
viewController.navigationItem.rightBarButtonItems = rightItems.count > 0 ? rightItems : nil
|
||||
}
|
||||
|
||||
static func getNavigationBarShadowImage(for navigationItemModel: NavigationItemModelProtocol) -> UIImage? {
|
||||
guard let thickness = navigationItemModel.line?.thickness,
|
||||
let backgroundColor = navigationItemModel.line?.backgroundColor else { return nil }
|
||||
return backgroundColor.uiColor.image(CGSize(width: thickness, height: thickness))
|
||||
}
|
||||
|
||||
/// Convenience function for setting the navigation bar ui, except for the buttons.
|
||||
public static func setNavigationBarUI(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol) {
|
||||
let navigationBar = navigationController.navigationBar
|
||||
let font = MFStyler.fontBoldBodySmall(false)
|
||||
let backgroundColor = navigationItemModel.backgroundColor?.uiColor
|
||||
let tint = navigationItemModel.tintColor.uiColor
|
||||
navigationBar.tintColor = tint
|
||||
|
||||
let appearance = UINavigationBarAppearance()
|
||||
appearance.configureWithOpaqueBackground()
|
||||
appearance.titleTextAttributes = [NSAttributedString.Key.font: font,
|
||||
NSAttributedString.Key.foregroundColor: tint];
|
||||
appearance.backgroundColor = backgroundColor
|
||||
appearance.titleTextAttributes.updateValue(tint, forKey: .foregroundColor)
|
||||
appearance.titlePositionAdjustment = navigationItemModel.titleOffset ?? .zero
|
||||
appearance.shadowColor = navigationItemModel.line?.backgroundColor?.uiColor ?? .clear
|
||||
appearance.shadowImage = getNavigationBarShadowImage(for: navigationItemModel)?.withRenderingMode(.alwaysTemplate)
|
||||
navigationBar.standardAppearance = appearance
|
||||
navigationBar.scrollEdgeAppearance = appearance
|
||||
|
||||
navigationController.setNavigationBarHidden(navigationItemModel.hidden, animated: true)
|
||||
}
|
||||
|
||||
/// Convenience function for setting the navigation titleView.
|
||||
public static func setNavigationTitleView(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) {
|
||||
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||
if let titleViewModel = navigationItemModel?.titleView, let molecule = ModelRegistry.createMolecule(titleViewModel, delegateObject: delegate, additionalData: nil) {
|
||||
viewController.navigationItem.titleView = molecule
|
||||
}
|
||||
}
|
||||
|
||||
=======
|
||||
>>>>>>> feature/develop_mvp_3:MVMCoreUI/Containers/NavigationController/NavigationController.swift
|
||||
/// Convenience function to return the navigation model of the lowest controller traversing managers if applicable.
|
||||
public func getNavigationModel(from viewController: UIViewController) -> NavigationItemModelProtocol? {
|
||||
return (viewController as? PageProtocol)?.pageModel?.navigationBar
|
||||
}
|
||||
|
||||
/// Verifies the controller is the currently displayed controller.
|
||||
public func isDisplayed(viewController: UIViewController) -> Bool {
|
||||
guard let topViewController = topViewController,
|
||||
viewController == MVMCoreUIUtility.getViewControllerTraversingManagers(topViewController) else {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
extension NavigationController: MVMCoreViewManagerProtocol {
|
||||
public func getCurrentViewController() -> UIViewController? {
|
||||
guard let topViewController = topViewController else { return nil }
|
||||
return MVMCoreUIUtility.getViewControllerTraversingManagers(topViewController)
|
||||
}
|
||||
|
||||
public func containsPage(withPageType pageType: String?) -> Bool {
|
||||
for controller in viewControllers {
|
||||
if let manager = controller as? MVMCoreViewManagerProtocol,
|
||||
manager.containsPage(withPageType: pageType) {
|
||||
return true
|
||||
} else if let controller = controller as? MVMCoreViewControllerProtocol,
|
||||
controller.pageType == pageType {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
public func newDataReceived(in viewController: UIViewController) {
|
||||
|
||||
if isDisplayed(viewController: viewController),
|
||||
let topViewController = topViewController,
|
||||
let model = getNavigationModel(from: viewController) {
|
||||
setNavigationItem(with: model, for: topViewController)
|
||||
setNavigationBarUI(with: model)
|
||||
}
|
||||
manager?.newDataReceived?(in: viewController)
|
||||
}
|
||||
|
||||
public func willDisplay(_ viewController: UIViewController) {
|
||||
if let topViewController = topViewController,
|
||||
let model = getNavigationModel(from: viewController) {
|
||||
setNavigationItem(with: model, for: topViewController)
|
||||
}
|
||||
manager?.willDisplay?(viewController)
|
||||
}
|
||||
|
||||
public func displayedViewController(_ viewController: UIViewController) {
|
||||
if isDisplayed(viewController: viewController),
|
||||
let model = getNavigationModel(from: viewController) {
|
||||
setNavigationBarUI(with: model)
|
||||
}
|
||||
manager?.displayedViewController?(viewController)
|
||||
}
|
||||
}
|
||||
|
||||
extension NavigationController: MVMCorePresentationDelegateProtocol {
|
||||
public func navigationController(_ navigationController: UINavigationController, prepareDisplayFor viewController: UIViewController) {
|
||||
guard self == navigationController,
|
||||
let newViewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController),
|
||||
let model = getNavigationModel(from: newViewController) else { return }
|
||||
setNavigationItem(with: model, for: viewController)
|
||||
}
|
||||
|
||||
public func navigationController(_ navigationController: UINavigationController, willDisplay viewController: UIViewController) {
|
||||
guard self == navigationController,
|
||||
let newViewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController) else { return }
|
||||
if let controller = viewController as? (UIViewController & MVMCoreViewManagerViewControllerProtocol) {
|
||||
MVMCoreViewManagerViewControllerProtocolHelper.helpSetManager(self, viewController: controller)
|
||||
}
|
||||
manager?.willDisplay?(newViewController)
|
||||
}
|
||||
|
||||
public func navigationController(_ navigationController: UINavigationController, displayedViewController viewController: UIViewController) {
|
||||
guard self == navigationController,
|
||||
let newViewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController) else { return }
|
||||
if let model = getNavigationModel(from: newViewController) {
|
||||
setNavigationBarUI(with: model)
|
||||
}
|
||||
manager?.displayedViewController?(newViewController)
|
||||
if let controller = viewController as? (UIViewController & MVMCoreViewManagerViewControllerProtocol) {
|
||||
controller.viewControllerReady?(inManager: self)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension UIColor {
|
||||
func image(_ size: CGSize = CGSize(width: 1, height: 1)) -> UIImage {
|
||||
return UIGraphicsImageRenderer(size: size).image { rendererContext in
|
||||
self.setFill()
|
||||
rendererContext.fill(CGRect(origin: .zero, size: size))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,168 +0,0 @@
|
||||
//
|
||||
// MVMCoreUISplitViewController+Extension.swift
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Scott Pfeil on 6/18/20.
|
||||
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
// Navigation bar update functions
|
||||
public extension MVMCoreUISplitViewController {
|
||||
|
||||
/// Convenience function. Sets the navigation and split view properties for the view controller. Panel access is determined if view controller is a detail view protocol.
|
||||
func setNavigationBar(for viewController: UIViewController, navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol) {
|
||||
guard navigationController == self.navigationController,
|
||||
viewController == getCurrentDetailViewController() else {
|
||||
/// Not the split view navigation controller, skip split functions.
|
||||
return
|
||||
}
|
||||
|
||||
setLeftPanelIsAccessible((viewController as? MVMCoreUIDetailViewProtocol)?.isLeftPanelAccessible?() ?? false, for: viewController, updateNavigationButtons: false)
|
||||
setRightPanelIsAccessible((viewController as? MVMCoreUIDetailViewProtocol)?.isRightPanelAccessible?() ?? false, for: viewController, updateNavigationButtons: false)
|
||||
|
||||
setLeftNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController)
|
||||
setRightNavigationButtons(navigationController: navigationController, navigationItemModel: navigationItemModel, viewController: viewController)
|
||||
|
||||
setNavigationIconColor(navigationItemModel.tintColor.uiColor)
|
||||
}
|
||||
|
||||
/// Sets the left navigation items for the view controller based on model and splitview.
|
||||
func setLeftNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) {
|
||||
guard let topViewController = navigationController.topViewController else { return }
|
||||
|
||||
var leftItems: [UIBarButtonItem] = []
|
||||
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||
|
||||
// Add back button first.
|
||||
if navigationItemModel?.hidesSystemBackButton == true {
|
||||
var showBackButton: Bool
|
||||
if let forceBackButton = navigationItemModel?.alwaysShowBackButton {
|
||||
showBackButton = forceBackButton
|
||||
} else {
|
||||
showBackButton = MVMCoreNavigationHandler.shared()?.getViewControllers(for: navigationController)?.count ?? 0 > 1
|
||||
}
|
||||
if showBackButton {
|
||||
if let backButtonModel = navigationItemModel?.backButton {
|
||||
leftItems.append(backButtonModel.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||
} else if let backButton = backButton {
|
||||
// Default to legacy if we have default back button.
|
||||
leftItems.append(backButton)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the panel button after the back button.
|
||||
if let panelButton = leftPanelButton,
|
||||
leftPanelIsAccessible,
|
||||
!leftPanelStaysExtended() {
|
||||
leftItems.append(panelButton)
|
||||
}
|
||||
|
||||
// Add other model buttons
|
||||
if let leftItemModels = navigationItemModel?.additionalLeftButtons {
|
||||
for item in leftItemModels {
|
||||
leftItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||
}
|
||||
}
|
||||
|
||||
// Add any buttons added by the splitview.
|
||||
if let additionalLeftButtons = additionalLeftButtons(for: viewController) {
|
||||
leftItems.append(contentsOf: additionalLeftButtons)
|
||||
}
|
||||
|
||||
topViewController.navigationItem.setLeftBarButtonItems(leftItems.count > 0 ? leftItems : nil, animated: !DisableAnimations.boolValue)
|
||||
}
|
||||
|
||||
/// Sets the right navigation items for the view controller based on model and splitview.
|
||||
func setRightNavigationButtons(navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol?, viewController: UIViewController) {
|
||||
guard let topViewController = navigationController.topViewController else { return }
|
||||
|
||||
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||
var rightItems: [UIBarButtonItem] = []
|
||||
|
||||
// Add the panel button first.
|
||||
if let panelButton = rightPanelButton,
|
||||
rightPanelIsAccessible,
|
||||
!rightPanelStaysExtended() {
|
||||
rightItems.append(panelButton)
|
||||
}
|
||||
|
||||
// Add other model buttons
|
||||
if let rightItemModels = navigationItemModel?.additionalRightButtons {
|
||||
for item in rightItemModels {
|
||||
rightItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||
}
|
||||
}
|
||||
|
||||
// Add any buttons added by the splitview.
|
||||
if let additionalRightButtons = additionalRightButtons(for: viewController) {
|
||||
rightItems.append(contentsOf: additionalRightButtons)
|
||||
}
|
||||
|
||||
topViewController.navigationItem.setRightBarButtonItems(rightItems.count > 0 ? rightItems : nil, animated: !DisableAnimations.boolValue)
|
||||
}
|
||||
|
||||
@objc func navigationBarModelExists() -> Bool {
|
||||
// Legacy Navigation
|
||||
guard let currentViewController = getCurrentDetailViewController(),
|
||||
let _ = navigationController?.getNavigationModel(from: currentViewController) else { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
/// Convenience function to update the navigation bar if the controller is the current lowest controller.
|
||||
@objc func updateNavigationBarFor(viewController: UIViewController) {
|
||||
guard let navigationController = navigationController,
|
||||
navigationController.isDisplayed(viewController: viewController),
|
||||
let model = navigationController.getNavigationModel(from: viewController) else { return }
|
||||
<<<<<<< HEAD
|
||||
set(for: viewController, navigationController: navigationController, navigationItemModel: model)
|
||||
guard !(topAlertView?.overridingStatusBar() ?? false) else { return }
|
||||
setStatusBarForCurrentViewController()
|
||||
}
|
||||
|
||||
/// Returns the bar style for the background color. Light if on a dark background, otherwise default.
|
||||
func getStatusBarStyle(for backgroundColor: UIColor?) -> UIStatusBarStyle {
|
||||
var greyScale: CGFloat = 0
|
||||
if backgroundColor?.getWhite(&greyScale, alpha: nil) == true,
|
||||
greyScale < 0.5 { return .lightContent }
|
||||
return .default
|
||||
}
|
||||
|
||||
/// Updates the status bar background color and style.
|
||||
@objc func setStatusBarForCurrentViewController() {
|
||||
let viewController = getCurrentViewController() as? MVMCoreUIDetailViewProtocol
|
||||
let backgroundColor = viewController?.defaultStatusBarBackgroundColor?() ??
|
||||
navigationController?.navigationBar.standardAppearance.backgroundColor ??
|
||||
statusBarView?.backgroundColor
|
||||
|
||||
let style = viewController?.defaultStatusBarStyle?() ??
|
||||
getStatusBarStyle(for: backgroundColor)
|
||||
|
||||
setStatusBarBackgroundColor(backgroundColor, style: style)
|
||||
=======
|
||||
setNavigationBar(for: viewController, navigationController: navigationController, navigationItemModel: model)
|
||||
>>>>>>> feature/develop_mvp_3
|
||||
}
|
||||
}
|
||||
|
||||
extension MVMCoreUISplitViewController: MVMCoreViewManagerProtocol {
|
||||
public func getCurrentViewController() -> UIViewController? {
|
||||
navigationController?.getCurrentViewController()
|
||||
}
|
||||
|
||||
public func containsPage(withPageType pageType: String?) -> Bool {
|
||||
navigationController?.containsPage(withPageType: pageType) ?? false
|
||||
}
|
||||
|
||||
public func displayedViewController(_ viewController: UIViewController) {
|
||||
setupPanels()
|
||||
updateNavigationBarFor(viewController: viewController)
|
||||
}
|
||||
|
||||
public func newDataReceived(in viewController: UIViewController) {
|
||||
updateNavigationBarFor(viewController: viewController)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user