Review Comments from static to extension
This commit is contained in:
parent
09e59d5b31
commit
b89cc43867
@ -272,6 +272,7 @@
|
|||||||
AAE7270E24AC8B9300A3ED0E /* HeadersH2CaretLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE7270D24AC8B9300A3ED0E /* HeadersH2CaretLink.swift */; };
|
AAE7270E24AC8B9300A3ED0E /* HeadersH2CaretLink.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE7270D24AC8B9300A3ED0E /* HeadersH2CaretLink.swift */; };
|
||||||
AAE96FA225341F6A0037A989 /* ListStoreLocatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */; };
|
AAE96FA225341F6A0037A989 /* ListStoreLocatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */; };
|
||||||
AAE96FA525341F7D0037A989 /* ListStoreLocator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */; };
|
AAE96FA525341F7D0037A989 /* ListStoreLocator.swift in Sources */ = {isa = PBXBuildFile; fileRef = AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */; };
|
||||||
|
AFE4A1D627DFBB6F00C458D0 /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFE4A1D527DFBB6F00C458D0 /* UINavigationController+Extension.swift */; };
|
||||||
BB105859248DEFF70069D008 /* UICollectionViewLeftAlignedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */; };
|
BB105859248DEFF70069D008 /* UICollectionViewLeftAlignedLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */; };
|
||||||
BB1D17E0244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */; };
|
BB1D17E0244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */; };
|
||||||
BB1D17E2244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */; };
|
BB1D17E2244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */; };
|
||||||
@ -855,6 +856,7 @@
|
|||||||
AAE7270D24AC8B9300A3ED0E /* HeadersH2CaretLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadersH2CaretLink.swift; sourceTree = "<group>"; };
|
AAE7270D24AC8B9300A3ED0E /* HeadersH2CaretLink.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadersH2CaretLink.swift; sourceTree = "<group>"; };
|
||||||
AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocatorModel.swift; sourceTree = "<group>"; };
|
AAE96FA125341F6A0037A989 /* ListStoreLocatorModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocatorModel.swift; sourceTree = "<group>"; };
|
||||||
AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocator.swift; sourceTree = "<group>"; };
|
AAE96FA425341F7D0037A989 /* ListStoreLocator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListStoreLocator.swift; sourceTree = "<group>"; };
|
||||||
|
AFE4A1D527DFBB6F00C458D0 /* UINavigationController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Extension.swift"; sourceTree = "<group>"; };
|
||||||
BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionViewLeftAlignedLayout.swift; sourceTree = "<group>"; };
|
BB105858248DEFF60069D008 /* UICollectionViewLeftAlignedLayout.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionViewLeftAlignedLayout.swift; sourceTree = "<group>"; };
|
||||||
BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMediumModel.swift; sourceTree = "<group>"; };
|
BB1D17DF244EAA30001D2002 /* ListDeviceComplexButtonMediumModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMediumModel.swift; sourceTree = "<group>"; };
|
||||||
BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMedium.swift; sourceTree = "<group>"; };
|
BB1D17E1244EAA46001D2002 /* ListDeviceComplexButtonMedium.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListDeviceComplexButtonMedium.swift; sourceTree = "<group>"; };
|
||||||
@ -1529,6 +1531,15 @@
|
|||||||
path = Miscellaneous;
|
path = Miscellaneous;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
AFE4A1D427DFBB2700C458D0 /* NavigationController */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
D2B18B93236214AD00A9AEDC /* NavigationController.swift */,
|
||||||
|
AFE4A1D527DFBB6F00C458D0 /* UINavigationController+Extension.swift */,
|
||||||
|
);
|
||||||
|
path = NavigationController;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
D202AFE2242A5F1400E5BEDF /* Extensions */ = {
|
D202AFE2242A5F1400E5BEDF /* Extensions */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
@ -2066,9 +2077,9 @@
|
|||||||
D29DF11921E68467003B2FB9 /* Containers */ = {
|
D29DF11921E68467003B2FB9 /* Containers */ = {
|
||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
|
AFE4A1D427DFBB2700C458D0 /* NavigationController */,
|
||||||
0ABD1369237B18EE0081388D /* Views */,
|
0ABD1369237B18EE0081388D /* Views */,
|
||||||
D29DF2B621E7BE66003B2FB9 /* SplitViewController */,
|
D29DF2B621E7BE66003B2FB9 /* SplitViewController */,
|
||||||
D2B18B93236214AD00A9AEDC /* NavigationController.swift */,
|
|
||||||
);
|
);
|
||||||
path = Containers;
|
path = Containers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -2631,6 +2642,7 @@
|
|||||||
DBC4391922442197001AB423 /* DashLine.swift in Sources */,
|
DBC4391922442197001AB423 /* DashLine.swift in Sources */,
|
||||||
D2ED27FC254B0E0300A1C293 /* MVMCoreAlertObject+Swift.swift in Sources */,
|
D2ED27FC254B0E0300A1C293 /* MVMCoreAlertObject+Swift.swift in Sources */,
|
||||||
D264FAAA2440F97600D98315 /* CollectionView.swift in Sources */,
|
D264FAAA2440F97600D98315 /* CollectionView.swift in Sources */,
|
||||||
|
AFE4A1D627DFBB6F00C458D0 /* UINavigationController+Extension.swift in Sources */,
|
||||||
AAC23FAD24D92A0D009208DF /* ListThreeColumnSpeedTestModel.swift in Sources */,
|
AAC23FAD24D92A0D009208DF /* ListThreeColumnSpeedTestModel.swift in Sources */,
|
||||||
BBC0C4FF24811DCA0087C44F /* TagModel.swift in Sources */,
|
BBC0C4FF24811DCA0087C44F /* TagModel.swift in Sources */,
|
||||||
01F2C20527C81F9700DC3D36 /* SubNavSwipeAnimator.swift in Sources */,
|
01F2C20527C81F9700DC3D36 /* SubNavSwipeAnimator.swift in Sources */,
|
||||||
|
|||||||
@ -23,7 +23,7 @@ import UIKit
|
|||||||
MVMCoreNavigationHandler.shared()?.viewControllerToPresentOn = navigationController
|
MVMCoreNavigationHandler.shared()?.viewControllerToPresentOn = navigationController
|
||||||
MVMCoreNavigationHandler.shared()?.navigationController = navigationController
|
MVMCoreNavigationHandler.shared()?.navigationController = navigationController
|
||||||
MVMCoreNavigationHandler.shared()?.addDelegate(navigationController)
|
MVMCoreNavigationHandler.shared()?.addDelegate(navigationController)
|
||||||
NavigationController.setNavigationBarUI(navigationController: navigationController, navigationItemModel: NavigationItemModel())
|
navigationController.setNavigationBarUI(with: NavigationItemModel())
|
||||||
return navigationController
|
return navigationController
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,79 +34,6 @@ import UIKit
|
|||||||
return navigationController
|
return navigationController
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Convenience function to return the navigation model of the lowest controller traversing managers if applicable.
|
/// Convenience function to return the navigation model of the lowest controller traversing managers if applicable.
|
||||||
public func getNavigationModel(from viewController: UIViewController) -> NavigationItemModelProtocol? {
|
public func getNavigationModel(from viewController: UIViewController) -> NavigationItemModelProtocol? {
|
||||||
return (viewController as? PageProtocol)?.pageModel?.navigationBar
|
return (viewController as? PageProtocol)?.pageModel?.navigationBar
|
||||||
@ -146,8 +73,8 @@ extension NavigationController: MVMCoreViewManagerProtocol {
|
|||||||
if isDisplayed(viewController: viewController),
|
if isDisplayed(viewController: viewController),
|
||||||
let topViewController = topViewController,
|
let topViewController = topViewController,
|
||||||
let model = getNavigationModel(from: viewController) {
|
let model = getNavigationModel(from: viewController) {
|
||||||
Self.setNavigationItem(navigationController: self, navigationItemModel: model, viewController: topViewController)
|
setNavigationItem(with: model, for: topViewController)
|
||||||
Self.setNavigationBarUI(navigationController: self, navigationItemModel: model)
|
setNavigationBarUI(with: model)
|
||||||
}
|
}
|
||||||
manager?.newDataReceived?(in: viewController)
|
manager?.newDataReceived?(in: viewController)
|
||||||
}
|
}
|
||||||
@ -155,7 +82,7 @@ extension NavigationController: MVMCoreViewManagerProtocol {
|
|||||||
public func willDisplay(_ viewController: UIViewController) {
|
public func willDisplay(_ viewController: UIViewController) {
|
||||||
if let topViewController = topViewController,
|
if let topViewController = topViewController,
|
||||||
let model = getNavigationModel(from: viewController) {
|
let model = getNavigationModel(from: viewController) {
|
||||||
Self.setNavigationItem(navigationController: self, navigationItemModel: model, viewController: topViewController)
|
setNavigationItem(with: model, for: topViewController)
|
||||||
}
|
}
|
||||||
manager?.willDisplay?(viewController)
|
manager?.willDisplay?(viewController)
|
||||||
}
|
}
|
||||||
@ -163,7 +90,7 @@ extension NavigationController: MVMCoreViewManagerProtocol {
|
|||||||
public func displayedViewController(_ viewController: UIViewController) {
|
public func displayedViewController(_ viewController: UIViewController) {
|
||||||
if isDisplayed(viewController: viewController),
|
if isDisplayed(viewController: viewController),
|
||||||
let model = getNavigationModel(from: viewController) {
|
let model = getNavigationModel(from: viewController) {
|
||||||
Self.setNavigationBarUI(navigationController: self, navigationItemModel: model)
|
setNavigationBarUI(with: model)
|
||||||
}
|
}
|
||||||
manager?.displayedViewController?(viewController)
|
manager?.displayedViewController?(viewController)
|
||||||
}
|
}
|
||||||
@ -174,7 +101,7 @@ extension NavigationController: MVMCorePresentationDelegateProtocol {
|
|||||||
guard self == navigationController,
|
guard self == navigationController,
|
||||||
let newViewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController),
|
let newViewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController),
|
||||||
let model = getNavigationModel(from: newViewController) else { return }
|
let model = getNavigationModel(from: newViewController) else { return }
|
||||||
Self.setNavigationItem(navigationController: self, navigationItemModel: model, viewController: viewController)
|
setNavigationItem(with: model, for: viewController)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func navigationController(_ navigationController: UINavigationController, willDisplay viewController: UIViewController) {
|
public func navigationController(_ navigationController: UINavigationController, willDisplay viewController: UIViewController) {
|
||||||
@ -190,7 +117,7 @@ extension NavigationController: MVMCorePresentationDelegateProtocol {
|
|||||||
guard self == navigationController,
|
guard self == navigationController,
|
||||||
let newViewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController) else { return }
|
let newViewController = MVMCoreUIUtility.getViewControllerTraversingManagers(viewController) else { return }
|
||||||
if let model = getNavigationModel(from: newViewController) {
|
if let model = getNavigationModel(from: newViewController) {
|
||||||
Self.setNavigationBarUI(navigationController: self, navigationItemModel: model)
|
setNavigationBarUI(with: model)
|
||||||
}
|
}
|
||||||
manager?.displayedViewController?(newViewController)
|
manager?.displayedViewController?(newViewController)
|
||||||
if let controller = viewController as? (UIViewController & MVMCoreViewManagerViewControllerProtocol) {
|
if let controller = viewController as? (UIViewController & MVMCoreViewManagerViewControllerProtocol) {
|
||||||
@ -0,0 +1,87 @@
|
|||||||
|
//
|
||||||
|
// UINavigationController+Extension.swift
|
||||||
|
// MVMCoreUI
|
||||||
|
//
|
||||||
|
// Created by Scott Pfeil on 3/14/22.
|
||||||
|
// Copyright © 2022 Verizon Wireless. All rights reserved.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
public extension UINavigationController {
|
||||||
|
|
||||||
|
/// Convenience function for setting the navigation item.
|
||||||
|
func setNavigationItem(with model: NavigationItemModelProtocol, for viewController: UIViewController) {
|
||||||
|
viewController.navigationItem.title = model.title
|
||||||
|
viewController.navigationItem.accessibilityLabel = model.title
|
||||||
|
viewController.navigationItem.hidesBackButton = model.hidesSystemBackButton
|
||||||
|
viewController.navigationItem.leftItemsSupplementBackButton = !model.hidesSystemBackButton
|
||||||
|
setNavigationButtons(with: model, for: viewController)
|
||||||
|
setNavigationTitleView(with: model, for: viewController)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience function for setting the navigation buttons.
|
||||||
|
func setNavigationButtons(with model: NavigationItemModelProtocol, for viewController: UIViewController) {
|
||||||
|
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||||
|
var leftItems: [UIBarButtonItem] = []
|
||||||
|
if model.hidesSystemBackButton,
|
||||||
|
model.alwaysShowBackButton != false {
|
||||||
|
if let backButtonModel = model.backButton,
|
||||||
|
MVMCoreNavigationHandler.shared()?.getViewControllers(for: self)?.count ?? 0 > 1 || model.alwaysShowBackButton ?? false {
|
||||||
|
leftItems.append(backButtonModel.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||||
|
}
|
||||||
|
if let leftItemModels = model.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 = model.additionalRightButtons {
|
||||||
|
for item in rightItemModels {
|
||||||
|
rightItems.append(item.createNavigationItemButton(delegateObject: delegate, additionalData: nil))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
viewController.navigationItem.rightBarButtonItems = rightItems.count > 0 ? rightItems : nil
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience function for setting the navigation titleView.
|
||||||
|
func setNavigationTitleView(with model: NavigationItemModelProtocol, for viewController: UIViewController) {
|
||||||
|
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
|
||||||
|
if let titleViewModel = model.titleView,
|
||||||
|
let molecule = ModelRegistry.createMolecule(titleViewModel, delegateObject: delegate, additionalData: nil) {
|
||||||
|
viewController.navigationItem.titleView = molecule
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a ShadowImage based on the line property of NavigationItemModelProtocol
|
||||||
|
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
|
||||||
|
func setNavigationBarUI(with model: NavigationItemModelProtocol) {
|
||||||
|
let navigationBar = navigationBar
|
||||||
|
let font = MFStyler.fontBoldBodySmall(false)
|
||||||
|
let backgroundColor = model.backgroundColor?.uiColor
|
||||||
|
let tint = model.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.shadowColor = model.line?.backgroundColor?.uiColor ?? .clear
|
||||||
|
appearance.shadowImage = getNavigationBarShadowImage(for: model)?.withRenderingMode(.alwaysTemplate)
|
||||||
|
navigationBar.standardAppearance = appearance
|
||||||
|
navigationBar.scrollEdgeAppearance = appearance
|
||||||
|
|
||||||
|
setNavigationBarHidden(model.hidden, animated: true)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -12,18 +12,13 @@ import Foundation
|
|||||||
public extension MVMCoreUISplitViewController {
|
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.
|
/// 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.
|
||||||
static func setNavigationBarUI(for viewController: UIViewController, navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol) {
|
func setNavigationBar(for viewController: UIViewController, navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol) {
|
||||||
guard let splitView = MVMCoreUISplitViewController.main(),
|
guard navigationController == self.navigationController,
|
||||||
navigationController == splitView.navigationController,
|
viewController == getCurrentDetailViewController() else {
|
||||||
viewController == MVMCoreUISplitViewController.main()?.getCurrentDetailViewController() else {
|
|
||||||
/// Not the split view navigation controller, skip split functions.
|
/// Not the split view navigation controller, skip split functions.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
splitView.set(for: viewController, navigationController: navigationController, navigationItemModel: navigationItemModel)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the navigation item for the view controller based on the model and splitview controller
|
|
||||||
private func set(for viewController: UIViewController, navigationController: UINavigationController, navigationItemModel: NavigationItemModelProtocol) {
|
|
||||||
setLeftPanelIsAccessible((viewController as? MVMCoreUIDetailViewProtocol)?.isLeftPanelAccessible?() ?? false, for: viewController, updateNavigationButtons: false)
|
setLeftPanelIsAccessible((viewController as? MVMCoreUIDetailViewProtocol)?.isLeftPanelAccessible?() ?? false, for: viewController, updateNavigationButtons: false)
|
||||||
setRightPanelIsAccessible((viewController as? MVMCoreUIDetailViewProtocol)?.isRightPanelAccessible?() ?? false, for: viewController, updateNavigationButtons: false)
|
setRightPanelIsAccessible((viewController as? MVMCoreUIDetailViewProtocol)?.isRightPanelAccessible?() ?? false, for: viewController, updateNavigationButtons: false)
|
||||||
|
|
||||||
@ -121,7 +116,7 @@ public extension MVMCoreUISplitViewController {
|
|||||||
guard let navigationController = navigationController,
|
guard let navigationController = navigationController,
|
||||||
navigationController.isDisplayed(viewController: viewController),
|
navigationController.isDisplayed(viewController: viewController),
|
||||||
let model = navigationController.getNavigationModel(from: viewController) else { return }
|
let model = navigationController.getNavigationModel(from: viewController) else { return }
|
||||||
set(for: viewController, navigationController: navigationController, navigationItemModel: model)
|
setNavigationBar(for: viewController, navigationController: navigationController, navigationItemModel: model)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user