89 lines
3.5 KiB
Swift
89 lines
3.5 KiB
Swift
//
|
|
// CarouselModel.swift
|
|
// MVMCoreUI
|
|
//
|
|
// Created by Suresh, Kamlesh on 11/25/19.
|
|
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
|
|
@objcMembers public class CarouselModel: MoleculeModelProtocol {
|
|
//--------------------------------------------------
|
|
// MARK: - Properties
|
|
//--------------------------------------------------
|
|
|
|
public static var identifier: String {
|
|
return "carousel"
|
|
}
|
|
|
|
public var backgroundColor: Color?
|
|
public var molecules: [CarouselItemModel]
|
|
public var moleculeName: String?
|
|
public var spacing: Float?
|
|
public var border: Bool?
|
|
public var loop: Bool?
|
|
public var height: Float?
|
|
public var itemWidthPercent: Float?
|
|
public var itemAlignment: String?
|
|
public var pagingMolecule: CarouselPagingModelProtocol?
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Initializer
|
|
//--------------------------------------------------
|
|
|
|
public init(molecules: [CarouselItemModel]) {
|
|
self.molecules = molecules
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Keys
|
|
//--------------------------------------------------
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case moleculeName
|
|
case backgroundColor
|
|
case molecules
|
|
case spacing
|
|
case border
|
|
case loop
|
|
case height
|
|
case itemWidthPercent
|
|
case itemAlignment
|
|
case pagingMolecule
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Codec
|
|
//--------------------------------------------------
|
|
|
|
required public init(from decoder: Decoder) throws {
|
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
|
moleculeName = try typeContainer.decodeIfPresent(String.self, forKey: .moleculeName)
|
|
molecules = try typeContainer.decode([CarouselItemModel].self, forKey: .molecules)
|
|
backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor)
|
|
spacing = try typeContainer.decodeIfPresent(Float.self, forKey: .spacing)
|
|
border = try typeContainer.decodeIfPresent(Bool.self, forKey: .border)
|
|
loop = try typeContainer.decodeIfPresent(Bool.self, forKey: .loop)
|
|
height = try typeContainer.decodeIfPresent(Float.self, forKey: .height)
|
|
itemWidthPercent = try typeContainer.decodeIfPresent(Float.self, forKey: .itemWidthPercent)
|
|
itemAlignment = try typeContainer.decodeIfPresent(String.self, forKey: .itemAlignment)
|
|
pagingMolecule = try typeContainer.decodeMoleculeIfPresent(codingKey: .pagingMolecule) as? CarouselPagingModelProtocol
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(moleculeName, forKey: .moleculeName)
|
|
try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor)
|
|
try container.encodeIfPresent(molecules, forKey: .molecules)
|
|
try container.encodeIfPresent(spacing, forKey: .spacing)
|
|
try container.encodeIfPresent(border, forKey: .border)
|
|
try container.encodeIfPresent(loop, forKey: .loop)
|
|
try container.encodeIfPresent(height, forKey: .height)
|
|
try container.encodeIfPresent(itemWidthPercent, forKey: .itemWidthPercent)
|
|
try container.encodeIfPresent(itemAlignment, forKey: .itemAlignment)
|
|
try container.encodeModelIfPresent(pagingMolecule, forKey: .pagingMolecule)
|
|
}
|
|
}
|