Container updates

This commit is contained in:
Pfeil, Scott Robert 2020-01-09 16:27:02 -05:00
parent 391e3a635d
commit 7fb22648c0
9 changed files with 57 additions and 68 deletions

View File

@ -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}
}

View File

@ -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 }
}

View File

@ -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)
}
}

View File

@ -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)

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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() {

View File

@ -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
}