From 654e02ff8e69319a5a1f4a4f2de4903972c71a39 Mon Sep 17 00:00:00 2001 From: Subhankar Acharya Date: Mon, 27 Jul 2020 10:34:56 +0530 Subject: [PATCH] map to model registry --- MVMCoreUI/Atomic/MoleculeObjectMapping.swift | 1 + .../ListThreeColumnBillChanges.swift | 86 +++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift index e8c6af54..af394c62 100644 --- a/MVMCoreUI/Atomic/MoleculeObjectMapping.swift +++ b/MVMCoreUI/Atomic/MoleculeObjectMapping.swift @@ -191,6 +191,7 @@ import Foundation MoleculeObjectMapping.shared()?.register(viewClass: ListTwoColumnDropdownSelectors.self, viewModelClass: ListTwoColumnDropdownSelectorsModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListThreeColumnInternationalData.self, viewModelClass: ListThreeColumnInternationalDataModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListThreeColumnDataUsage.self, viewModelClass: ListThreeColumnDataUsageModel.self) + MoleculeObjectMapping.shared()?.register(viewClass: ListThreeColumnBillChanges.self, viewModelClass: ListThreeColumnBillChangesModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListFourColumnDataUsageListItem.self, viewModelClass: ListFourColumnDataUsageListItemModel.self) MoleculeObjectMapping.shared()?.register(viewClass: ListProgressBarThin.self, viewModelClass: ListProgressBarThinModel.self) diff --git a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnBillChanges.swift b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnBillChanges.swift index f5250072..8802a458 100644 --- a/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnBillChanges.swift +++ b/MVMCoreUI/Atomic/Molecules/DesignedComponents/List/ThreeColumn/ListThreeColumnBillChanges.swift @@ -7,3 +7,89 @@ // import Foundation + +@objcMembers open class ListThreeColumnBillChanges: TableViewCell { + //----------------------------------------------------- + // MARK: - Outlets + //------------------------------------------------------- + public let leftLabel = Label(fontStyle: .RegularBodySmall) + public let centerLabel = Label(fontStyle: .RegularBodySmall) + public let rightLabel = Label(fontStyle: .RegularBodySmall) + var stack: Stack + + //------------------------------------------------------ + // MARK: - Initializers + //------------------------------------------------------ + + public override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + stack = Stack.createStack(with: [(view: leftLabel, model: StackItemModel(percent: 40, horizontalAlignment: .leading)), + (view: centerLabel, model: StackItemModel(percent: 37, horizontalAlignment: .leading)), + (view: rightLabel, model: StackItemModel(percent: 23, horizontalAlignment: .leading))], + axis: .horizontal) + super.init(style: style, reuseIdentifier: reuseIdentifier) + } + + public required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + //------------------------------------------------------ + // MARK: - Lifecycle + //------------------------------------------------------ + + open override func setupView() { + super.setupView() + leftLabel.numberOfLines = 1 + centerLabel.numberOfLines = 1 + rightLabel.numberOfLines = 1 + addMolecule(stack) + stack.restack() + } + + //-------------------------------------------------- + // MARK: - ModelMoleculeViewProtocol + //-------------------------------------------------- + + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + super.set(with: model, delegateObject, additionalData) + guard let model = model as? ListThreeColumnBillChangesModel else { return } + leftLabel.set(with: model.leftLabel, delegateObject, additionalData) + centerLabel.set(with: model.centerLabel, delegateObject, additionalData) + rightLabel.set(with: model.rightLabel, delegateObject, additionalData) + updateAccessibilityLabel() + } + + open override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat { + return 121 + } + + open override func reset() { + super.reset() + leftLabel.setFontStyle(.RegularBodySmall) + centerLabel.setFontStyle(.RegularBodySmall) + rightLabel.setFontStyle(.RegularBodySmall) + } + + //-------------------------------------------------- + // MARK: - Accessibility + //-------------------------------------------------- + + func updateAccessibilityLabel() { + isAccessibilityElement = true + var message = "" + + if let leftText = leftLabel.text, !leftText.isEmpty { + message += leftText + ", " + } + + if let centerText = centerLabel.text, !centerText.isEmpty { + message += centerText + ", " + } + + if let rightText = rightLabel.text, !rightText.isEmpty { + message += rightText + } + + accessibilityLabel = message + } +}