From e4dc439d1cce72e81ba3c5c6d4329ada08b0df59 Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Thu, 16 Apr 2020 15:45:24 +0530 Subject: [PATCH 1/4] updated Code as per confluence page color changes --- MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift | 6 +++++- MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift | 4 ++-- MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index ff3452fb..e408b50f 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -69,6 +69,10 @@ open class RadioBox: Control { subTextLabel.text = model.subText isOutOfStock = model.strikethrough subTextLabelHeightConstraint?.isActive = (subTextLabel.text?.count ?? 0) == 0 + if let boxesModel = additionalData?["radioboxesmodel"] as? RadioBoxesModel{ + backgroundColor = model.backgroundColor?.uiColor ?? (boxesModel.backgroundColor?.uiColor ?? UIColor.white) + accentColor = model.selectedAccentColor?.uiColor ?? (boxesModel.selectedAccentColor?.uiColor ?? UIColor.mvmRed) + } } // MARK: - State Handling @@ -134,7 +138,7 @@ open class RadioBox: Control { let topLineLayer = CAShapeLayer() topLineLayer.fillColor = nil - topLineLayer.strokeColor = UIColor.mvmRed.cgColor + topLineLayer.strokeColor = accentColor.cgColor topLineLayer.lineWidth = 4 topLineLayer.path = topLinePath.cgPath layer.addSublayer(topLineLayer) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift index b2a23c6a..fe47ac29 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift @@ -11,8 +11,8 @@ import Foundation public static var identifier: String = "radioBox" public var text: String public var subText: String? - public var backgroundColor: Color? = Color(uiColor: .white) - public var selectedAccentColor = Color(uiColor: .mvmRed) + public var backgroundColor: Color? + public var selectedAccentColor: Color? public var selected: Bool = false public var enabled: Bool = true public var strikethrough: Bool = false diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift index 4b42e9a8..8d05adac 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift @@ -16,6 +16,8 @@ open class RadioBoxes: View { private let boxHeight: CGFloat = 64.0 private let itemSpacing: CGFloat = 8.0 private var numberOfColumns: CGFloat = 2.0 + private var radioBoxesmodel: RadioBoxesModel! + private var delegateObject: MVMCoreUIDelegateObject? @@ -48,6 +50,7 @@ open class RadioBoxes: View { self.delegateObject = delegateObject guard let radioBoxesModel = model as? RadioBoxesModel else { return } + radioBoxesmodel = radioBoxesModel boxes = radioBoxesModel.boxes FormValidator.setupValidation(for: radioBoxesModel, delegate: delegateObject?.formHolderDelegate) @@ -118,8 +121,9 @@ extension RadioBoxes: UICollectionViewDataSource { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioBoxCollectionViewCell", for: indexPath) as? RadioBoxCollectionViewCell else { fatalError() } + let additionalData: [AnyHashable : RadioBoxesModel] = ["radioboxesmodel":radioBoxesmodel] cell.radioBox.isUserInteractionEnabled = false - cell.set(with: molecule, delegateObject, nil) + cell.set(with: molecule, delegateObject, additionalData) cell.updateView(size ?? collectionView.bounds.width) if molecule.selected { collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically) From c830c388dea8c7114f23ada0fc0c79503182cd7e Mon Sep 17 00:00:00 2001 From: Damodaram <> Date: Thu, 16 Apr 2020 16:06:04 +0530 Subject: [PATCH 2/4] model keys Updated --- MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift | 6 +++--- MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift index 8d05adac..61449d78 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift @@ -16,7 +16,7 @@ open class RadioBoxes: View { private let boxHeight: CGFloat = 64.0 private let itemSpacing: CGFloat = 8.0 private var numberOfColumns: CGFloat = 2.0 - private var radioBoxesmodel: RadioBoxesModel! + private var radioBoxesModel: RadioBoxesModel! private var delegateObject: MVMCoreUIDelegateObject? @@ -50,7 +50,7 @@ open class RadioBoxes: View { self.delegateObject = delegateObject guard let radioBoxesModel = model as? RadioBoxesModel else { return } - radioBoxesmodel = radioBoxesModel + self.radioBoxesModel = radioBoxesModel boxes = radioBoxesModel.boxes FormValidator.setupValidation(for: radioBoxesModel, delegate: delegateObject?.formHolderDelegate) @@ -121,7 +121,7 @@ extension RadioBoxes: UICollectionViewDataSource { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioBoxCollectionViewCell", for: indexPath) as? RadioBoxCollectionViewCell else { fatalError() } - let additionalData: [AnyHashable : RadioBoxesModel] = ["radioboxesmodel":radioBoxesmodel] + let additionalData: [AnyHashable : RadioBoxesModel] = ["radioboxesmodel":radioBoxesModel] cell.radioBox.isUserInteractionEnabled = false cell.set(with: molecule, delegateObject, additionalData) cell.updateView(size ?? collectionView.bounds.width) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift index 28c4fab5..55c29e35 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift @@ -27,7 +27,7 @@ import Foundation private enum CodingKeys: String, CodingKey { case moleculeName case selectedAccentColor - case backgroundColor + case backgroundColor = "boxesColor" case boxes case fieldKey case groupName From ca0f527c7b1d9d1484208e7630155b5ca861405b Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 16 Apr 2020 13:46:25 -0400 Subject: [PATCH 3/4] Code cleanup --- .../Atomic/Atoms/Selectors/RadioBox.swift | 13 ++++++++---- .../RadioBoxCollectionViewCell.swift | 7 ++++++- .../Atoms/Selectors/RadioBoxModel.swift | 10 +++------ .../Atomic/Atoms/Selectors/RadioBoxes.swift | 21 ++++++++++++------- .../Atoms/Selectors/RadioBoxesModel.swift | 7 +++++-- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift index e408b50f..785d6ae6 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBox.swift @@ -60,7 +60,7 @@ open class RadioBox: Control { // MARK: - MoleculeViewProtocol - public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) guard let model = model as? RadioBoxModel else { return } isSelected = model.selected @@ -69,12 +69,17 @@ open class RadioBox: Control { subTextLabel.text = model.subText isOutOfStock = model.strikethrough subTextLabelHeightConstraint?.isActive = (subTextLabel.text?.count ?? 0) == 0 - if let boxesModel = additionalData?["radioboxesmodel"] as? RadioBoxesModel{ - backgroundColor = model.backgroundColor?.uiColor ?? (boxesModel.backgroundColor?.uiColor ?? UIColor.white) - accentColor = model.selectedAccentColor?.uiColor ?? (boxesModel.selectedAccentColor?.uiColor ?? UIColor.mvmRed) + if let color = model.selectedAccentColor?.uiColor { + accentColor = color } } + open override func reset() { + super.reset() + backgroundColor = .white + accentColor = .mvmRed + } + // MARK: - State Handling open override func draw(_ layer: CALayer, in ctx: CGContext) { diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxCollectionViewCell.swift index c90b5e92..c6f5474e 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxCollectionViewCell.swift @@ -8,7 +8,12 @@ import Foundation open class RadioBoxCollectionViewCell: CollectionViewCell { - let radioBox = RadioBox() + public let radioBox = RadioBox() + + open override func reset() { + super.reset() + backgroundColor = .clear + } open override func setupView() { super.setupView() diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift index fe47ac29..986eefac 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxModel.swift @@ -34,12 +34,8 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) text = try typeContainer.decode(String.self, forKey: .text) subText = try typeContainer.decodeIfPresent(String.self, forKey: .subText) - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) { - selectedAccentColor = color - } - if let color = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) { - backgroundColor = color - } + selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) + backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) if let isSelected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected) { selected = isSelected } @@ -58,7 +54,7 @@ import Foundation try container.encode(moleculeName, forKey: .moleculeName) try container.encode(text, forKey: .text) try container.encodeIfPresent(subText, forKey: .subText) - try container.encode(selectedAccentColor, forKey: .selectedAccentColor) + try container.encodeIfPresent(selectedAccentColor, forKey: .selectedAccentColor) try container.encodeIfPresent(backgroundColor, forKey: .backgroundColor) try container.encode(selected, forKey: .selected) try container.encode(enabled, forKey: .enabled) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift index 61449d78..ef648f06 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift @@ -18,7 +18,6 @@ open class RadioBoxes: View { private var numberOfColumns: CGFloat = 2.0 private var radioBoxesModel: RadioBoxesModel! - private var delegateObject: MVMCoreUIDelegateObject? /// The models for the molecules. @@ -45,7 +44,7 @@ open class RadioBoxes: View { } // MARK: - MoleculeViewProtocol - public override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { + open override func set(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?, _ additionalData: [AnyHashable: Any]?) { super.set(with: model, delegateObject, additionalData) self.delegateObject = delegateObject @@ -121,9 +120,17 @@ extension RadioBoxes: UICollectionViewDataSource { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RadioBoxCollectionViewCell", for: indexPath) as? RadioBoxCollectionViewCell else { fatalError() } - let additionalData: [AnyHashable : RadioBoxesModel] = ["radioboxesmodel":radioBoxesModel] + cell.reset() cell.radioBox.isUserInteractionEnabled = false - cell.set(with: molecule, delegateObject, additionalData) + + if let color = radioBoxesModel?.boxesColor { + cell.radioBox.backgroundColor = color.uiColor + } + if let color = radioBoxesModel?.selectedAccentColor { + cell.radioBox.accentColor = color.uiColor + } + + cell.set(with: molecule, delegateObject, nil) cell.updateView(size ?? collectionView.bounds.width) if molecule.selected { collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically) @@ -134,18 +141,18 @@ extension RadioBoxes: UICollectionViewDataSource { } extension RadioBoxes: UICollectionViewDelegate { - public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { + open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { guard let molecule = boxes?[indexPath.row] else { return false } return molecule.enabled } - public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let cell = collectionView.cellForItem(at: indexPath) as? RadioBoxCollectionViewCell else { return } cell.radioBox.selectBox() _ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) } - public func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { + open func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) { guard let cell = collectionView.cellForItem(at: indexPath) as? RadioBoxCollectionViewCell else { return } cell.radioBox.deselectBox() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift index 55c29e35..5b568910 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxesModel.swift @@ -9,9 +9,10 @@ import Foundation @objcMembers public class RadioBoxesModel: MoleculeModelProtocol, FormFieldProtocol { public static var identifier: String = "radioBoxes" + public var boxes: [RadioBoxModel] public var backgroundColor: Color? public var selectedAccentColor: Color? - public var boxes: [RadioBoxModel] + public var boxesColor: Color? public var fieldKey: String? public var groupName: String = FormValidator.defaultGroupName public var baseValue: AnyHashable? @@ -27,7 +28,8 @@ import Foundation private enum CodingKeys: String, CodingKey { case moleculeName case selectedAccentColor - case backgroundColor = "boxesColor" + case backgroundColor + case boxesColor case boxes case fieldKey case groupName @@ -37,6 +39,7 @@ import Foundation let typeContainer = try decoder.container(keyedBy: CodingKeys.self) selectedAccentColor = try typeContainer.decodeIfPresent(Color.self, forKey: .selectedAccentColor) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) + boxesColor = try typeContainer.decodeIfPresent(Color.self, forKey: .boxesColor) boxes = try typeContainer.decode([RadioBoxModel].self, forKey: .boxes) fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey) if let groupName = try typeContainer.decodeIfPresent(String.self, forKey: .groupName) { From af28134d90f9990266c429757cfb6cd8dee1cbe6 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Thu, 16 Apr 2020 13:49:52 -0400 Subject: [PATCH 4/4] final clean --- MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift index ef648f06..2a6ba953 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioBoxes.swift @@ -16,7 +16,9 @@ open class RadioBoxes: View { private let boxHeight: CGFloat = 64.0 private let itemSpacing: CGFloat = 8.0 private var numberOfColumns: CGFloat = 2.0 - private var radioBoxesModel: RadioBoxesModel! + private var radioBoxesModel: RadioBoxesModel? { + return model as? RadioBoxesModel + } private var delegateObject: MVMCoreUIDelegateObject? @@ -49,7 +51,6 @@ open class RadioBoxes: View { self.delegateObject = delegateObject guard let radioBoxesModel = model as? RadioBoxesModel else { return } - self.radioBoxesModel = radioBoxesModel boxes = radioBoxesModel.boxes FormValidator.setupValidation(for: radioBoxesModel, delegate: delegateObject?.formHolderDelegate)