Merge remote-tracking branch 'origin/develop' into feature/ONEAPP-7249

This commit is contained in:
Hedden, Kyle Matthew 2024-05-21 20:12:21 -04:00
commit ab8b457772
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" }
public var id: String = UUID().uuidString
private let defaultHidesSystemBackButton = true
open var title: String?
open var hidden = false
open var line: LineModel? = LineModel(type: .secondary)
open var hidesSystemBackButton = true
open var hidden: Bool?
open var line: LineModel?
open var hidesSystemBackButton: Bool?
open var style: NavigationItemStyle?
private var _backgroundColor: Color?
open var _backgroundColor: Color?
open var backgroundColor: Color? {
get {
if let backgroundColor = _backgroundColor { return backgroundColor }
@ -41,8 +39,8 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
_backgroundColor = newValue
}
}
private var _tintColor: Color?
open var _tintColor: Color?
open var tintColor: Color {
get {
if let tintColor = _tintColor { return tintColor }
@ -54,7 +52,6 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
_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
open var alwaysShowBackButton: Bool?
open var backButton: (NavigationButtonModelProtocol & MoleculeModelProtocol)?
@ -62,7 +59,7 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
open var additionalLeftButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
open var additionalRightButtons: [(NavigationButtonModelProtocol & MoleculeModelProtocol)]?
open var titleView: MoleculeModelProtocol?
open var titleOffset: UIOffset? = UIOffset(horizontal: -CGFloat.greatestFiniteMagnitude, vertical: 0)
open var titleOffset: UIOffset?
//--------------------------------------------------
// MARK: - Initializer
@ -100,27 +97,18 @@ open class NavigationItemModel: NavigationItemModelProtocol, MoleculeModelProtoc
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
id = try typeContainer.decodeIfPresent(String.self, forKey: .id) ?? UUID().uuidString
title = try typeContainer.decodeIfPresent(String.self, forKey: .title)
if let hidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidden) {
self.hidden = hidden
}
hidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidden)
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
_tintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .tintColor)
if let line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) {
self.line = line
}
if let hidesSystemBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidesSystemBackButton) {
self.hidesSystemBackButton = hidesSystemBackButton
}
line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line)
hidesSystemBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidesSystemBackButton)
alwaysShowBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .alwaysShowBackButton)
backButton = try typeContainer.decodeModelIfPresent(codingKey: .backButton)
additionalLeftButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalLeftButtons)
additionalRightButtons = try typeContainer.decodeModelsIfPresent(codingKey: .additionalRightButtons)
titleView = try typeContainer.decodeModelIfPresent(codingKey: .titleView)
style = try typeContainer.decodeIfPresent(NavigationItemStyle.self, forKey: .style)
if let titleOffset = try typeContainer.decodeIfPresent(UIOffset.self, forKey: .titleOffset) {
self.titleOffset = titleOffset
}
line?.inverted = style == .dark
titleOffset = try typeContainer.decodeIfPresent(UIOffset.self, forKey: .titleOffset)
}
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(moleculeName, forKey: .moleculeName)
try container.encodeIfPresent(title, forKey: .title)
try container.encode(hidden, forKey: .hidden)
try container.encodeIfPresent(_backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(hidden, forKey: .hidden)
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
try container.encodeIfPresent(_tintColor, forKey: .tintColor)
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.encodeModelIfPresent(backButton, forKey: .backButton)
try container.encodeModelsIfPresent(additionalLeftButtons, forKey: .additionalLeftButtons)

View File

@ -10,11 +10,11 @@ import Foundation
public protocol NavigationItemModelProtocol {
var title: String? { get set }
var hidden: Bool { get set }
var hidden: Bool? { get set }
var backgroundColor: Color? { get set }
var tintColor: Color { get set }
var line: LineModel? { get set }
var hidesSystemBackButton: Bool { get set }
var hidesSystemBackButton: Bool? { get set }
var alwaysShowBackButton: Bool? { get set }
var backButton: (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.accessibilityLabel = model.title
viewController.navigationItem.hidesBackButton = model.hidesSystemBackButton
viewController.navigationItem.leftItemsSupplementBackButton = !model.hidesSystemBackButton
viewController.navigationItem.hidesBackButton = model.hidesSystemBackButton ?? true
viewController.navigationItem.leftItemsSupplementBackButton = !viewController.navigationItem.hidesBackButton
setNavigationButtons(with: model, for: viewController)
setNavigationTitleView(with: model, for: viewController, coordinatingWith: pageBehaviorController)
@ -38,7 +38,7 @@ public extension UINavigationController {
func setNavigationButtons(with model: NavigationItemModelProtocol, for viewController: UIViewController) {
let delegate = (viewController as? MVMCoreViewControllerProtocol)?.delegateObject?() as? MVMCoreUIDelegateObject
var leftItems: [UIBarButtonItem] = []
if model.hidesSystemBackButton,
if model.hidesSystemBackButton ?? true,
model.alwaysShowBackButton != false {
if let backButtonModel = model.backButton,
NavigationHandler.shared().getViewControllers(for: self).count > 1 || model.alwaysShowBackButton ?? false {
@ -102,7 +102,7 @@ public extension UINavigationController {
navigationBar.standardAppearance = appearance
navigationBar.scrollEdgeAppearance = appearance
setNavigationBarHidden(model.hidden, animated: false)
setNavigationBarHidden(model.hidden ?? false, animated: false)
}
@objc @MainActor

View File

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