From 7fb22648c08d732fa3547ae4843490c65de995f1 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 9 Jan 2020 16:27:02 -0500 Subject: [PATCH] Container updates --- .../CollectionCellMoleculeProtocol.swift | 4 +-- .../ListItemModelProtocol.swift | 4 +-- .../Models/Molecules/CarouselItemModel.swift | 32 +++++++++---------- .../Molecules/DropDownListItemModel.swift | 26 +++++++-------- MVMCoreUI/Molecules/Items/ListItemModel.swift | 31 +++++++----------- .../Items/MoleculeCollectionViewCell.swift | 4 +-- .../Items/MoleculeTableViewCell.swift | 9 ++++++ MVMCoreUI/Molecules/Items/TableViewCell.swift | 13 ++------ MVMCoreUI/Molecules/Scroller.swift | 2 +- 9 files changed, 57 insertions(+), 68 deletions(-) diff --git a/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift b/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift index e18c8907..3dbdc694 100644 --- a/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/CollectionCellMoleculeProtocol.swift @@ -8,7 +8,7 @@ import Foundation -public protocol CollectionCellMoleculeProtocol: ContainerMoleculeProtocol { +public protocol CollectionCellMoleculeProtocol: ContainerModelProtocol, MoleculeProtocol { var peakingUI: Bool? {get} - var peakingArrowColor: String? {get} + var peakingArrowColor: Color? {get} } diff --git a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift index 59bec9ae..53bf51ea 100644 --- a/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/ListItemModelProtocol.swift @@ -8,7 +8,7 @@ import Foundation -public protocol ListItemModelProtocol: ContainerMoleculeProtocol { +public protocol ListItemModelProtocol: ContainerModelProtocol, Model { var molecule: MoleculeProtocol { get } - var separator: LineModel? { get set } + var line: LineModel? { get set } } diff --git a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift index 1ccf898f..e86b89c3 100644 --- a/MVMCoreUI/Models/Molecules/CarouselItemModel.swift +++ b/MVMCoreUI/Models/Molecules/CarouselItemModel.swift @@ -9,31 +9,31 @@ import Foundation -@objcMembers public class CarouselItemModel: ContainerMoleculeProtocol { +@objcMembers public class CarouselItemModel: MoleculeContainerModel, CollectionCellMoleculeProtocol { public static var identifier: String = "carouselItem" - public var molecule: MoleculeProtocol public var backgroundColor: Color? - - public init(molecule: MoleculeProtocol) { - self.molecule = molecule - } - - enum CodingKeys: String, CodingKey { - case moleculeName - case molecule + public var peakingUI: Bool? + public var peakingArrowColor: Color? + + enum CarouselItemCodingKeys: String, CodingKey { case backgroundColor + case peakingUI + case peakingArrowColor } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + let typeContainer = try decoder.container(keyedBy: CarouselItemCodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + peakingUI = try typeContainer.decodeIfPresent(Bool.self, forKey: .peakingUI) + peakingArrowColor = try typeContainer.decodeIfPresent(Color.self, forKey: .peakingArrowColor) + try super.init(from: decoder) } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: CarouselItemCodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) - try container.encodeModelIfPresent(molecule, forKey: .molecule) + try container.encodeIfPresent(peakingUI, forKey: .peakingUI) + try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor) } } diff --git a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift index 260e7063..1ef1ca1f 100644 --- a/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift +++ b/MVMCoreUI/Models/Molecules/DropDownListItemModel.swift @@ -8,42 +8,38 @@ import Foundation -@objcMembers public class DropDownListItemModel: ListItemModelProtocol { +@objcMembers public class DropDownListItemModel: MoleculeContainerModel, ListItemModelProtocol { public static var identifier: String = "dropDownListItem" - public var molecule: MoleculeProtocol public var molecules: [[ListItemModel]] public var backgroundColor: Color? - public var separator: LineModel? + public var line: LineModel? public var dropDown: DropDownModel public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) { - self.molecule = molecule self.molecules = molecules self.dropDown = dropDown + super.init(with: molecule) } - enum CodingKeys: String, CodingKey { - case molecule - case moleculeName + enum DropDownCodingKeys: String, CodingKey { case molecules - case separator + case line case backgroundColor case dropDown } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + let typeContainer = try decoder.container(keyedBy: DropDownCodingKeys.self) self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules) - self.separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) + self.line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) self.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown) + try super.init(from: decoder) } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encodeModel(molecule, forKey: .molecule) - try container.encode(moleculeName, forKey: .moleculeName) + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: DropDownCodingKeys.self) try container.encode(molecules, forKey: .molecules) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encode(dropDown, forKey: .dropDown) diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index bdff2842..bef2cb84 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -9,46 +9,39 @@ import Foundation import MVMCore -@objcMembers public class ListItemModel: ListItemModelProtocol { +@objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol { public static var identifier: String = "listItem" - public var molecule: MoleculeProtocol public var backgroundColor: Color? public var action: ActionProtocol? public var hideArrow: Bool? - public var separator: LineModel? + public var line: LineModel? public var style: String? - public init(molecule: MoleculeProtocol) { - self.molecule = molecule - } - - enum CodingKeys: String, CodingKey { - case moleculeName - case molecule + enum ListItemCodingKeys: String, CodingKey { case backgroundColor case action case hideArrow - case separator + case line case style } required public init(from decoder: Decoder) throws { - let typeContainer = try decoder.container(keyedBy: CodingKeys.self) - molecule = try typeContainer.decodeMolecule(codingKey: .molecule) + let typeContainer = try decoder.container(keyedBy: ListItemCodingKeys.self) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) - separator = try typeContainer.decodeIfPresent(LineModel.self, forKey: .separator) + line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) style = try typeContainer.decodeIfPresent(String.self, forKey: .style) + try super.init(from: decoder) } - public func encode(to encoder: Encoder) throws { - var container = encoder.container(keyedBy: CodingKeys.self) - try container.encode(moleculeName, forKey: .moleculeName) - try container.encodeModelIfPresent(molecule, forKey: .molecule) + public override func encode(to encoder: Encoder) throws { + try super.encode(to: encoder) + var container = encoder.container(keyedBy: ListItemCodingKeys.self) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encodeModelIfPresent(action, forKey: .action) try container.encodeIfPresent(hideArrow, forKey: .hideArrow) - try container.encodeIfPresent(separator, forKey: .separator) + try container.encodeIfPresent(line, forKey: .line) try container.encodeIfPresent(style, forKey: .style) } } diff --git a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift index b976ca64..1603c876 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeCollectionViewCell.swift @@ -69,7 +69,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) { - guard let collectionModel = model as? CollectionCellMoleculeProtocol else { + guard let collectionModel = model as? CarouselItemModel else { return } @@ -82,7 +82,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi // Handles peaking. allowsPeaking = collectionModel.peakingUI ?? false if let peakingArrowColor = collectionModel.peakingArrowColor { - let color = UIColor.mfGet(forHex: peakingArrowColor) + let color = peakingArrowColor.uiColor peakingLeftArrow.tintColor = color peakingRightArrow.tintColor = color } diff --git a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift index 9bfab3f3..40222f03 100644 --- a/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/MoleculeTableViewCell.swift @@ -38,4 +38,13 @@ import UIKit } return theClass.requiredModules?(moleculeJSON, delegateObject: delegateObject, error: error) } + + public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + guard let moleculeModel = (molecule as? MoleculeContainerModel)?.molecule, + let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol.Type, + let height = classType.estimatedHeight(forRow: moleculeModel, delegateObject: delegateObject) else { + return 80 + } + return max(2 * PaddingDefaultVerticalSpacing3, height) + } } diff --git a/MVMCoreUI/Molecules/Items/TableViewCell.swift b/MVMCoreUI/Molecules/Items/TableViewCell.swift index ba017c4e..9fbad78b 100644 --- a/MVMCoreUI/Molecules/Items/TableViewCell.swift +++ b/MVMCoreUI/Molecules/Items/TableViewCell.swift @@ -177,7 +177,7 @@ import UIKit } // override the separator - if let separator = model.separator { + if let separator = model.line { addSeparatorsIfNeeded() bottomSeparatorView?.setWithModel(separator, nil, nil) } @@ -193,19 +193,10 @@ import UIKit backgroundColor = .white } - public static func estimatedHeight(forRow molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { - guard let moleculeModel = (molecule as? ContainerMoleculeProtocol)?.molecule, - let classType = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(moleculeModel) as? ModelMoleculeViewProtocol.Type, - let height = classType.estimatedHeight(forRow: moleculeModel, delegateObject: delegateObject) else { - return 80 - } - return max(2 * PaddingDefaultVerticalSpacing3, height) - } - - public class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? { return molecule?.moleculeName ?? "" } + // MARK: - Arrow /// Adds the standard mvm style caret to the accessory view @objc public func addCaretViewAccessory() { diff --git a/MVMCoreUI/Molecules/Scroller.swift b/MVMCoreUI/Molecules/Scroller.swift index 01477158..4be1025a 100644 --- a/MVMCoreUI/Molecules/Scroller.swift +++ b/MVMCoreUI/Molecules/Scroller.swift @@ -34,7 +34,7 @@ import UIKit setUpDefaultWithModel(model, delegateObject, additionalData) guard let model = model, - let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule else { + let moleculeModel = (model as? MoleculeContainerModel)?.molecule else { return }