Changed TableViewCell to Container in Molecule class and ListItemModelProtocol to MoleculeModelProtocol

This commit is contained in:
Kruthika KP 2020-02-06 18:43:53 +05:30
parent 8ca15468f4
commit 5f2abffba0
2 changed files with 44 additions and 41 deletions

View File

@ -9,42 +9,25 @@
import Foundation
import UIKit
@objcMembers public class LeftVariableIconRightCaretList : TableViewCell {
@objcMembers public class LeftVariableIconRightCaretList : Container {
//-----------------------------------------------------
// MARK: - Outlets
//-------------------------------------------------------
let leftImage = MFLoadImageView()
let leftLabel = Label.commonLabelB2(true)
let rightLabel = Label.commonLabelB2(true)
let leftLabel = Label(frame: .zero)
let rightLabel = Label(frame: .zero)
//------------------------------------------------------
// MARK: - Properties
//-------------------------------------------------------
let spaceBetweenLabels : CGFloat = 40
let horizontalPadding : CGFloat = 12
let rightLabelTrailing : CGFloat = 20
let cellHeight : CGFloat = 60
let spaceBetweenLabels : CGFloat = 180
let horizontalPadding : CGFloat = 14
let imageSize : CGFloat = 30
//------------------------------------------------------
// MARK: - Initialization
//--------------------------------------------------------
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setupView()
}
required public init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setupView()
}
//-----------------------------------------------------
// MARK: - View Lifecycle
//-------------------------------------------------------
@ -63,28 +46,29 @@ import UIKit
return
}
addSubview(leftImage)
addSubview(leftLabel)
addSubview(rightLabel)
let container = MVMCoreUICommonViewsUtility.commonView()
addAndContain(container)
container.addSubview(leftImage)
container.addSubview(leftLabel)
container.addSubview(rightLabel)
contentView.heightAnchor.constraint(equalToConstant: cellHeight).isActive = true
self.translatesAutoresizingMaskIntoConstraints = false
leftImage.leadingAnchor.constraint(equalTo: layoutMarginsGuide.leadingAnchor).isActive = true
leftImage.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
leftImage.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
leftImage.leadingAnchor.constraint(equalTo: container.leadingAnchor).isActive = true
leftImage.topAnchor.constraint(equalTo: container.topAnchor).isActive = true
leftImage.bottomAnchor.constraint(equalTo: container.bottomAnchor).isActive = true
leftImage.widthAnchor.constraint(equalToConstant: imageSize).isActive = true
leftImage.heightAnchor.constraint(equalToConstant: imageSize).isActive = true
leftLabel.leadingAnchor.constraint(equalTo: leftImage.trailingAnchor, constant: horizontalPadding).isActive = true
leftLabel.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
leftLabel.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
leftLabel.topAnchor.constraint(equalTo: container.topAnchor).isActive = true
leftLabel.bottomAnchor.constraint(equalTo: container.bottomAnchor).isActive = true
rightLabel.leadingAnchor.constraint(greaterThanOrEqualTo: leftLabel.trailingAnchor, constant: spaceBetweenLabels).isActive = true
rightLabel.topAnchor.constraint(equalTo: layoutMarginsGuide.topAnchor).isActive = true
rightLabel.bottomAnchor.constraint(equalTo: layoutMarginsGuide.bottomAnchor).isActive = true
layoutMarginsGuide.trailingAnchor.constraint(equalTo: rightLabel.trailingAnchor, constant: rightLabelTrailing).isActive = true
rightLabel.leadingAnchor.constraint(equalTo: leftLabel.trailingAnchor,constant: spaceBetweenLabels).isActive = true
rightLabel.topAnchor.constraint(equalTo: container.topAnchor).isActive = true
rightLabel.bottomAnchor.constraint(equalTo: container.bottomAnchor).isActive = true
}
//----------------------------------------------------
@ -99,10 +83,6 @@ import UIKit
rightLabel.reset()
}
open func setAsMolecule() {
setupView()
}
public override func setWithModel(_ model: MoleculeModelProtocol?, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable : Any]?) {
super.setWithModel(model, delegateObject, additionalData)

View File

@ -8,7 +8,7 @@
import Foundation
public class LeftVariableIconRightCaretListModel: ListItemModelProtocol {
public class LeftVariableIconRightCaretListModel: MoleculeModelProtocol {
public var horizontalAlignment: UIStackView.Alignment?
public var verticalAlignment: UIStackView.Alignment?
@ -19,7 +19,7 @@ public class LeftVariableIconRightCaretListModel: ListItemModelProtocol {
public var line: LineModel? = LineModel(type: .standard)
public var hideArrow: Bool? = false
public var hideArrow: Bool?
public var backgroundColor: Color?
public static var identifier: String = "listLVImg"
@ -35,5 +35,28 @@ public class LeftVariableIconRightCaretListModel: ListItemModelProtocol {
self.rightLabel = rightLabel
}
private enum CodingKeys: String, CodingKey {
case moleculeName
case leftLabel
case rightLabel
case image
}
required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
leftLabel = try typeContainer.decode(LabelModel.self, forKey: .leftLabel)
rightLabel = try typeContainer.decode(LabelModel.self, forKey: .rightLabel)
image = try typeContainer.decode(ImageViewModel.self, forKey: .image)
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(LeftVariableIconRightCaretListModel.identifier, forKey: .moleculeName)
try container.encode(leftLabel, forKey: .leftLabel)
try container.encode(rightLabel, forKey: .rightLabel)
try container.encodeIfPresent(image, forKey: .image)
}
}