Container updates
This commit is contained in:
parent
391e3a635d
commit
7fb22648c0
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public protocol CollectionCellMoleculeProtocol: ContainerMoleculeProtocol {
|
public protocol CollectionCellMoleculeProtocol: ContainerModelProtocol, MoleculeProtocol {
|
||||||
var peakingUI: Bool? {get}
|
var peakingUI: Bool? {get}
|
||||||
var peakingArrowColor: String? {get}
|
var peakingArrowColor: Color? {get}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public protocol ListItemModelProtocol: ContainerMoleculeProtocol {
|
public protocol ListItemModelProtocol: ContainerModelProtocol, Model {
|
||||||
var molecule: MoleculeProtocol { get }
|
var molecule: MoleculeProtocol { get }
|
||||||
var separator: LineModel? { get set }
|
var line: LineModel? { get set }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,31 +9,31 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
@objcMembers public class CarouselItemModel: ContainerMoleculeProtocol {
|
@objcMembers public class CarouselItemModel: MoleculeContainerModel, CollectionCellMoleculeProtocol {
|
||||||
public static var identifier: String = "carouselItem"
|
public static var identifier: String = "carouselItem"
|
||||||
public var molecule: MoleculeProtocol
|
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
|
public var peakingUI: Bool?
|
||||||
public init(molecule: MoleculeProtocol) {
|
public var peakingArrowColor: Color?
|
||||||
self.molecule = molecule
|
|
||||||
}
|
enum CarouselItemCodingKeys: String, CodingKey {
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
|
||||||
case moleculeName
|
|
||||||
case molecule
|
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
|
case peakingUI
|
||||||
|
case peakingArrowColor
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CarouselItemCodingKeys.self)
|
||||||
molecule = try typeContainer.decodeMolecule(codingKey: .molecule)
|
|
||||||
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
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 {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
try super.encode(to: encoder)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
var container = encoder.container(keyedBy: CarouselItemCodingKeys.self)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeModelIfPresent(molecule, forKey: .molecule)
|
try container.encodeIfPresent(peakingUI, forKey: .peakingUI)
|
||||||
|
try container.encodeIfPresent(peakingArrowColor, forKey: .peakingArrowColor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,42 +8,38 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class DropDownListItemModel: ListItemModelProtocol {
|
@objcMembers public class DropDownListItemModel: MoleculeContainerModel, ListItemModelProtocol {
|
||||||
public static var identifier: String = "dropDownListItem"
|
public static var identifier: String = "dropDownListItem"
|
||||||
public var molecule: MoleculeProtocol
|
|
||||||
public var molecules: [[ListItemModel]]
|
public var molecules: [[ListItemModel]]
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var separator: LineModel?
|
public var line: LineModel?
|
||||||
public var dropDown: DropDownModel
|
public var dropDown: DropDownModel
|
||||||
|
|
||||||
public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) {
|
public init(molecule: MoleculeProtocol, molecules: [[ListItemModel]], dropDown: DropDownModel) {
|
||||||
self.molecule = molecule
|
|
||||||
self.molecules = molecules
|
self.molecules = molecules
|
||||||
self.dropDown = dropDown
|
self.dropDown = dropDown
|
||||||
|
super.init(with: molecule)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum DropDownCodingKeys: String, CodingKey {
|
||||||
case molecule
|
|
||||||
case moleculeName
|
|
||||||
case molecules
|
case molecules
|
||||||
case separator
|
case line
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case dropDown
|
case dropDown
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: DropDownCodingKeys.self)
|
||||||
molecule = try typeContainer.decodeMolecule(codingKey: .molecule)
|
|
||||||
self.molecules = try typeContainer.decode([[ListItemModel]].self, forKey: .molecules)
|
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.backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown)
|
self.dropDown = try typeContainer.decode(DropDownModel.self, forKey: .dropDown)
|
||||||
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
try super.encode(to: encoder)
|
||||||
try container.encodeModel(molecule, forKey: .molecule)
|
var container = encoder.container(keyedBy: DropDownCodingKeys.self)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
|
||||||
try container.encode(molecules, forKey: .molecules)
|
try container.encode(molecules, forKey: .molecules)
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encode(dropDown, forKey: .dropDown)
|
try container.encode(dropDown, forKey: .dropDown)
|
||||||
|
|||||||
@ -9,46 +9,39 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import MVMCore
|
import MVMCore
|
||||||
|
|
||||||
@objcMembers public class ListItemModel: ListItemModelProtocol {
|
@objcMembers public class ListItemModel: MoleculeContainerModel, ListItemModelProtocol {
|
||||||
public static var identifier: String = "listItem"
|
public static var identifier: String = "listItem"
|
||||||
public var molecule: MoleculeProtocol
|
|
||||||
public var backgroundColor: Color?
|
public var backgroundColor: Color?
|
||||||
public var action: ActionProtocol?
|
public var action: ActionProtocol?
|
||||||
public var hideArrow: Bool?
|
public var hideArrow: Bool?
|
||||||
public var separator: LineModel?
|
public var line: LineModel?
|
||||||
public var style: String?
|
public var style: String?
|
||||||
|
|
||||||
public init(molecule: MoleculeProtocol) {
|
enum ListItemCodingKeys: String, CodingKey {
|
||||||
self.molecule = molecule
|
|
||||||
}
|
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
|
||||||
case moleculeName
|
|
||||||
case molecule
|
|
||||||
case backgroundColor
|
case backgroundColor
|
||||||
case action
|
case action
|
||||||
case hideArrow
|
case hideArrow
|
||||||
case separator
|
case line
|
||||||
case style
|
case style
|
||||||
}
|
}
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: ListItemCodingKeys.self)
|
||||||
molecule = try typeContainer.decodeMolecule(codingKey: .molecule)
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
||||||
action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type)
|
action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type)
|
||||||
hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow)
|
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)
|
style = try typeContainer.decodeIfPresent(String.self, forKey: .style)
|
||||||
|
try super.init(from: decoder)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func encode(to encoder: Encoder) throws {
|
public override func encode(to encoder: Encoder) throws {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
try super.encode(to: encoder)
|
||||||
try container.encode(moleculeName, forKey: .moleculeName)
|
var container = encoder.container(keyedBy: ListItemCodingKeys.self)
|
||||||
try container.encodeModelIfPresent(molecule, forKey: .molecule)
|
|
||||||
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
||||||
try container.encodeModelIfPresent(action, forKey: .action)
|
try container.encodeModelIfPresent(action, forKey: .action)
|
||||||
try container.encodeIfPresent(hideArrow, forKey: .hideArrow)
|
try container.encodeIfPresent(hideArrow, forKey: .hideArrow)
|
||||||
try container.encodeIfPresent(separator, forKey: .separator)
|
try container.encodeIfPresent(line, forKey: .line)
|
||||||
try container.encodeIfPresent(style, forKey: .style)
|
try container.encodeIfPresent(style, forKey: .style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -69,7 +69,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
|
|||||||
|
|
||||||
|
|
||||||
public func setWithModel(_ model: MoleculeProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [String : AnyHashable]?) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ open class MoleculeCollectionViewCell: UICollectionViewCell, MVMCoreUIMoleculeVi
|
|||||||
// Handles peaking.
|
// Handles peaking.
|
||||||
allowsPeaking = collectionModel.peakingUI ?? false
|
allowsPeaking = collectionModel.peakingUI ?? false
|
||||||
if let peakingArrowColor = collectionModel.peakingArrowColor {
|
if let peakingArrowColor = collectionModel.peakingArrowColor {
|
||||||
let color = UIColor.mfGet(forHex: peakingArrowColor)
|
let color = peakingArrowColor.uiColor
|
||||||
peakingLeftArrow.tintColor = color
|
peakingLeftArrow.tintColor = color
|
||||||
peakingRightArrow.tintColor = color
|
peakingRightArrow.tintColor = color
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,4 +38,13 @@ import UIKit
|
|||||||
}
|
}
|
||||||
return theClass.requiredModules?(moleculeJSON, delegateObject: delegateObject, error: error)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -177,7 +177,7 @@ import UIKit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// override the separator
|
// override the separator
|
||||||
if let separator = model.separator {
|
if let separator = model.line {
|
||||||
addSeparatorsIfNeeded()
|
addSeparatorsIfNeeded()
|
||||||
bottomSeparatorView?.setWithModel(separator, nil, nil)
|
bottomSeparatorView?.setWithModel(separator, nil, nil)
|
||||||
}
|
}
|
||||||
@ -193,19 +193,10 @@ import UIKit
|
|||||||
backgroundColor = .white
|
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? {
|
public class func name(forReuse molecule: MoleculeProtocol?, delegateObject: MVMCoreUIDelegateObject?) -> String? {
|
||||||
return molecule?.moleculeName ?? ""
|
return molecule?.moleculeName ?? ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Arrow
|
// MARK: - Arrow
|
||||||
/// Adds the standard mvm style caret to the accessory view
|
/// Adds the standard mvm style caret to the accessory view
|
||||||
@objc public func addCaretViewAccessory() {
|
@objc public func addCaretViewAccessory() {
|
||||||
|
|||||||
@ -34,7 +34,7 @@ import UIKit
|
|||||||
setUpDefaultWithModel(model, delegateObject, additionalData)
|
setUpDefaultWithModel(model, delegateObject, additionalData)
|
||||||
|
|
||||||
guard let model = model,
|
guard let model = model,
|
||||||
let moleculeModel = (model as? ContainerMoleculeProtocol)?.molecule else {
|
let moleculeModel = (model as? MoleculeContainerModel)?.molecule else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user