120 lines
5.0 KiB
Swift
120 lines
5.0 KiB
Swift
//
|
|
// NavigationItemModelProtocol.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Scott Pfeil on 3/12/20.
|
|
// Copyright © 2020 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import Foundation
|
|
|
|
public protocol NavigationItemModelProtocol: MoleculeModelProtocol {
|
|
var title: String? { get set }
|
|
var titleView: MoleculeModelProtocol? { get set }
|
|
var hidden: Bool { get set }
|
|
var backgroundColor: Color? { get set }
|
|
var transparent: Bool { get set }
|
|
var tintColor: Color { get set }
|
|
var systemBackButton: Bool? { get set }
|
|
var showLeftPanelButton: Bool? { get set }
|
|
var showRightPanelButton: Bool? { get set }
|
|
var additionalLeftItems: [NavigationItemButtonModel]? { get set }
|
|
var additionalRightItems: [NavigationItemButtonModel]? { get set }
|
|
}
|
|
|
|
public class NavigationItemButtonModel: Codable {
|
|
var imageName: String
|
|
var action: ActionModelProtocol
|
|
|
|
public init(with imageName: String, action: ActionModelProtocol) {
|
|
self.imageName = imageName
|
|
self.action = action
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case imageName
|
|
case action
|
|
}
|
|
|
|
required public init(from decoder: Decoder) throws {
|
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
|
imageName = try typeContainer.decode(String.self, forKey: .imageName)
|
|
action = try typeContainer.decodeModel(codingKey: .action)
|
|
}
|
|
|
|
open func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(imageName, forKey: .imageName)
|
|
try container.encodeModel(action, forKey: .action)
|
|
}
|
|
}
|
|
|
|
public class NavigationItemModel: NavigationItemModelProtocol {
|
|
public class var identifier: String {
|
|
return "navigationItem"
|
|
}
|
|
|
|
public var title: String?
|
|
public var titleView: MoleculeModelProtocol?
|
|
public var hidden: Bool
|
|
public var backgroundColor: Color?
|
|
public var transparent: Bool
|
|
public var tintColor: Color
|
|
public var systemBackButton: Bool?
|
|
public var showLeftPanelButton: Bool?
|
|
public var showRightPanelButton: Bool?
|
|
public var additionalLeftItems: [NavigationItemButtonModel]?
|
|
public var additionalRightItems: [NavigationItemButtonModel]?
|
|
|
|
init() {
|
|
hidden = false
|
|
transparent = false
|
|
backgroundColor = Color(uiColor: .white)
|
|
tintColor = Color(uiColor: .black)
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case title
|
|
case titleView
|
|
case hidden
|
|
case backgroundColor
|
|
case transparent
|
|
case tintColor
|
|
case systemBackButton
|
|
case showLeftPanelButton
|
|
case showRightPanelButton
|
|
case additionalLeftItems
|
|
case additionalRightItems
|
|
}
|
|
|
|
required public init(from decoder: Decoder) throws {
|
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
|
title = try typeContainer.decodeIfPresent(String.self, forKey: .title)
|
|
titleView = try typeContainer.decodeModelIfPresent(codingKey: .titleView)
|
|
hidden = try typeContainer.decodeIfPresent(Bool.self, forKey: .hidden) ?? false
|
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) ?? Color(uiColor: .white)
|
|
transparent = try typeContainer.decodeIfPresent(Bool.self, forKey: .transparent) ?? false
|
|
tintColor = try typeContainer.decodeIfPresent(Color.self, forKey: .tintColor) ?? Color(uiColor: .black)
|
|
systemBackButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .systemBackButton) ?? false
|
|
showLeftPanelButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .showLeftPanelButton)
|
|
showRightPanelButton = try typeContainer.decodeIfPresent(Bool.self, forKey: .showRightPanelButton)
|
|
additionalLeftItems = try typeContainer.decodeIfPresent([NavigationItemButtonModel].self, forKey: .additionalLeftItems)
|
|
additionalRightItems = try typeContainer.decodeIfPresent([NavigationItemButtonModel].self, forKey: .additionalRightItems)
|
|
}
|
|
|
|
open func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encodeIfPresent(title, forKey: .title)
|
|
try container.encodeModelIfPresent(titleView, forKey: .titleView)
|
|
try container.encode(hidden, forKey: .hidden)
|
|
try container.encode(backgroundColor, forKey: .backgroundColor)
|
|
try container.encode(transparent, forKey: .transparent)
|
|
try container.encode(tintColor, forKey: .tintColor)
|
|
try container.encodeIfPresent(systemBackButton, forKey: .systemBackButton)
|
|
try container.encode(showLeftPanelButton, forKey: .showLeftPanelButton)
|
|
try container.encode(showRightPanelButton, forKey: .showRightPanelButton)
|
|
try container.encodeIfPresent(additionalLeftItems, forKey: .additionalLeftItems)
|
|
try container.encodeIfPresent(additionalRightItems, forKey: .additionalRightItems)
|
|
}
|
|
}
|