Merge branch 'feature/navigation_patterns' into 'develop'

Digital ACT191 story ONEAPP-7459 - Navigation Patterns

### Summary
Changes to allow for setting navigation items by pattern.

### JIRA Ticket
https://onejira.verizon.com/browse/ONEAPP-7459

Co-authored-by: Scott Pfeil <Scott.Pfeil3@verizonwireless.com>

See merge request https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui/-/merge_requests/1115
This commit is contained in:
Hedden, Kyle Matthew 2024-05-22 00:11:56 +00:00
commit 0efbb231c3
4 changed files with 23 additions and 35 deletions

View File

@ -20,16 +20,14 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
open class var identifier: String { "navigationBar" } open class var identifier: String { "navigationBar" }
public var id: String = UUID().uuidString public var id: String = UUID().uuidString
private let defaultHidesSystemBackButton = true
open var title: String? open var title: String?
open var hidden = false open var hidden: Bool?
open var line: LineModel? = LineModel(type: .secondary) open var line: LineModel?
open var hidesSystemBackButton = true open var hidesSystemBackButton: Bool?
open var style: NavigationItemStyle? open var style: NavigationItemStyle?
private var _backgroundColor: Color? open var _backgroundColor: Color?
open var backgroundColor: Color? { open var backgroundColor: Color? {
get { get {
if let backgroundColor = _backgroundColor { return backgroundColor } if let backgroundColor = _backgroundColor { return backgroundColor }
@ -41,8 +39,8 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
_backgroundColor = newValue _backgroundColor = newValue
} }
} }
private var _tintColor: Color? open var _tintColor: Color?
open var tintColor: Color { open var tintColor: Color {
get { get {
if let tintColor = _tintColor { return tintColor } if let tintColor = _tintColor { return tintColor }
@ -54,7 +52,6 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
_tintColor = newValue _tintColor = newValue
} }
} }
/// If true, we add the button in the backButton property. If false we do not add the button. If nil, we add the button if the controller is not the bottom of the stack /// If true, we add the button in the backButton property. If false we do not add the button. If nil, we add the button if the controller is not the bottom of the stack
open var alwaysShowBackButton: Bool? open var alwaysShowBackButton: Bool?
open var backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol)? open var backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol)?
@ -62,7 +59,7 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
open var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? open var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
open var additionalRightButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? open var additionalRightButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
open var titleView: MoleculeModelProtocol? open var titleView: MoleculeModelProtocol?
open var titleOffset: UIOffset? = UIOffset(horizontal: -CGFloat.greatestFiniteMagnitude, vertical: 0) open var titleOffset: UIOffset?
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Initializer // MARK: - Initializer
@ -100,27 +97,18 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
title = try typeContainer.decodeIfPresent(String.self, forKey: .title) title = try typeContainer.decodeIfPresent(String.self, forKey: .title)
if let hidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidden) { hidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidden)
self.hidden = hidden
}
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
_tintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .tintColor) _tintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .tintColor)
if let line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) { line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
self.line = line hidesSystemBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidesSystemBackButton)
}
if let hidesSystemBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidesSystemBackButton) {
self.hidesSystemBackButton = hidesSystemBackButton
}
alwaysShowBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .alwaysShowBackButton) alwaysShowBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .alwaysShowBackButton)
backButton = try typeContainer.decodeModelIfPresent(codingKey: .backButton) backButton = try typeContainer.decodeModelIfPresent(codingKey: .backButton)
additionalLeftButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalLeftButtons) additionalLeftButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalLeftButtons)
additionalRightButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalRightButtons) additionalRightButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalRightButtons)
titleView = try typeContainer.decodeModelIfPresent(codingKey: .titleView) titleView = try typeContainer.decodeModelIfPresent(codingKey: .titleView)
style = try typeContainer.decodeIfPresent(NavigationItemStyle.self, forKey: .style) style = try typeContainer.decodeIfPresent(NavigationItemStyle.self, forKey: .style)
if let titleOffset = try typeContainer.decodeIfPresent(UIOffset.self, forKey: .titleOffset) { titleOffset = try typeContainer.decodeIfPresent(UIOffset.self, forKey: .titleOffset)
self.titleOffset = titleOffset
}
line?.inverted = style == .dark
} }
open func encode(to encoder: Encoder) throws { open func encode(to encoder: Encoder) throws {
@ -128,11 +116,11 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
try container.encode(id, forKey: .id) try container.encode(id, forKey: .id)
try container.encode(moleculeName, forKey: .moleculeName) try container.encode(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(title, forKey: .title) try container.encodeIfPresent(title, forKey: .title)
try container.encode(hidden, forKey: .hidden) try container.encodeIfPresent(hidden, forKey: .hidden)
try container.encodeIfPresent(_backgroundColor, forKey: .backgroundColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(_tintColor, forKey: .tintColor) try container.encodeIfPresent(_tintColor, forKey: .tintColor)
try container.encodeIfPresent(line, forKey: .line) try container.encodeIfPresent(line, forKey: .line)
try container.encode(hidesSystemBackButton, forKey: .hidesSystemBackButton) try container.encodeIfPresent(hidesSystemBackButton, forKey: .hidesSystemBackButton)
try container.encodeIfPresent(alwaysShowBackButton, forKey: .alwaysShowBackButton) try container.encodeIfPresent(alwaysShowBackButton, forKey: .alwaysShowBackButton)
try container.encodeModelIfPresent(backButton, forKey: .backButton) try container.encodeModelIfPresent(backButton, forKey: .backButton)
try container.encodeModelsIfPresent(additionalLeftButtons, forKey: .additionalLeftButtons) try container.encodeModelsIfPresent(additionalLeftButtons, forKey: .additionalLeftButtons)

View File

@ -10,11 +10,11 @@ import Foundation
public protocol NavigationItemModelProtocol { public protocol NavigationItemModelProtocol {
var title: String? { get set } var title: String? { get set }
var hidden: Bool { get set } var hidden: Bool? { get set }
var backgroundColor: Color? { get set } var backgroundColor: Color? { get set }
var tintColor: Color { get set } var tintColor: Color { get set }
var line: LineModel? { get set } var line: LineModel? { get set }
var hidesSystemBackButton: Bool { get set } var hidesSystemBackButton: Bool? { get set }
var alwaysShowBackButton: Bool? { get set } var alwaysShowBackButton: Bool? { get set }
var backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol)? { get set } var backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol)? { get set }
var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? { get set } var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]? { get set }

View File

@ -23,8 +23,8 @@ public extension UINavigationController {
viewController.navigationItem.title = model.title viewController.navigationItem.title = model.title
viewController.navigationItem.accessibilityLabel = model.title viewController.navigationItem.accessibilityLabel = model.title
viewController.navigationItem.hidesBackButton = model.hidesSystemBackButton viewController.navigationItem.hidesBackButton = model.hidesSystemBackButton ?? true
viewController.navigationItem.leftItemsSupplementBackButton = !model.hidesSystemBackButton viewController.navigationItem.leftItemsSupplementBackButton = !viewController.navigationItem.hidesBackButton
setNavigationButtons(with: model, for: viewController) setNavigationButtons(with: model, for: viewController)
setNavigationTitleView(with: model, for: viewController, coordinatingWith: pageBehaviorController) setNavigationTitleView(with: model, for: viewController, coordinatingWith: pageBehaviorController)
@ -38,7 +38,7 @@ public extension UINavigationController {
func setNavigationButtons(with model: NavigationItemModelProtocol, for viewController: UIViewController) { func setNavigationButtons(with model: NavigationItemModelProtocol, for viewController: UIViewController) {
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
var leftItems: [UIBarButtonItem] = [] var leftItems: [UIBarButtonItem] = []
if model.hidesSystemBackButton, if model.hidesSystemBackButton ?? true,
model.alwaysShowBackButton != false { model.alwaysShowBackButton != false {
if let backButtonModel = model.backButton, if let backButtonModel = model.backButton,
NavigationHandler.shared().getViewControllers(for: self).count > 1 || model.alwaysShowBackButton ?? false { NavigationHandler.shared().getViewControllers(for: self).count > 1 || model.alwaysShowBackButton ?? false {
@ -102,7 +102,7 @@ public extension UINavigationController {
navigationBar.standardAppearance = appearance navigationBar.standardAppearance = appearance
navigationBar.scrollEdgeAppearance = appearance navigationBar.scrollEdgeAppearance = appearance
setNavigationBarHidden(model.hidden, animated: false) setNavigationBarHidden(model.hidden ?? false, animated: false)
} }
@objc @MainActor @objc @MainActor

View File

@ -119,7 +119,7 @@ public extension MVMCoreUISplitViewController {
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
// Add back button first. // Add back button first.
if navigationItemModel?.hidesSystemBackButton == true { if navigationItemModel?.hidesSystemBackButton ?? true {
var showBackButton: Bool var showBackButton: Bool
if let forceBackButton = navigationItemModel?.alwaysShowBackButton { if let forceBackButton = navigationItemModel?.alwaysShowBackButton {
showBackButton = forceBackButton showBackButton = forceBackButton