Code cleanup
This commit is contained in:
parent
fdd22f10e3
commit
135bf4c073
@ -13,7 +13,7 @@ open class RadioSwatchItem: Control {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var bottomText = Label.createLabelRegularMicro(true)
|
public let bottomText = Label.createLabelRegularMicro(true)
|
||||||
public var isOutOfStock = false
|
public var isOutOfStock = false
|
||||||
public var fillColor: Color = Color(uiColor: .mvmBlue)
|
public var fillColor: Color = Color(uiColor: .mvmBlue)
|
||||||
|
|
||||||
@ -35,19 +35,16 @@ open class RadioSwatchItem: Control {
|
|||||||
layer.setNeedsDisplay()
|
layer.setNeedsDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|
||||||
addSubview(bottomText)
|
addSubview(bottomText)
|
||||||
bottomText.textAlignment = .center
|
bottomText.textAlignment = .center
|
||||||
bottomText.topAnchor.constraint(equalTo: topAnchor, constant: 38).isActive = true
|
NSLayoutConstraint.constraintPinSubview(bottomText, pinTop: true, topConstant: 38, pinBottom: false, bottomConstant: 0, pinLeft: true, leftConstant: 0, pinRight: true, rightConstant: 0)
|
||||||
bottomText.leadingAnchor.constraint(equalTo: leadingAnchor).isActive = true
|
|
||||||
bottomText.trailingAnchor.constraint(equalTo: trailingAnchor).isActive = true
|
|
||||||
bottomAnchor.constraint(equalTo: bottomText.bottomAnchor).isActive = true
|
|
||||||
addTarget(self, action: #selector(selectSwatch), for: .touchUpInside)
|
addTarget(self, action: #selector(selectSwatch), for: .touchUpInside)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
guard let model = model as? RadioSwatchItemModel else { return }
|
guard let model = model as? RadioSwatchItemModel else { return }
|
||||||
fillColor = model.color
|
fillColor = model.color
|
||||||
@ -60,7 +57,6 @@ open class RadioSwatchItem: Control {
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - State Handling
|
// MARK: - State Handling
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
|
||||||
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
open override func draw(_ layer: CALayer, in ctx: CGContext) {
|
||||||
//Draw the swatch
|
//Draw the swatch
|
||||||
circleLayer?.removeFromSuperlayer()
|
circleLayer?.removeFromSuperlayer()
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
open class RadioSwatchItemCollectionViewCell: CollectionViewCell {
|
open class RadioSwatchItemCollectionViewCell: CollectionViewCell {
|
||||||
let radioSwatch = RadioSwatchItem()
|
public let radioSwatch = RadioSwatchItem()
|
||||||
|
|
||||||
open override func setupView() {
|
open override func setupView() {
|
||||||
super.setupView()
|
super.setupView()
|
||||||
|
|||||||
@ -13,9 +13,9 @@ open class RadioSwatches: View {
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var collectionView: CollectionView!
|
public var collectionView: CollectionView!
|
||||||
var swatches: [RadioSwatchItemModel]?
|
public var swatches: [RadioSwatchItemModel]?
|
||||||
private var size: CGFloat?
|
private var size: CGFloat?
|
||||||
private var delegateObject: MVMCoreUIDelegateObject?
|
private var delegateObject: MVMCoreUIDelegateObject?
|
||||||
|
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Constraints
|
// MARK: - Constraints
|
||||||
@ -50,7 +50,7 @@ open class RadioSwatches: View {
|
|||||||
collectionView.updateView(size)
|
collectionView.updateView(size)
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
super.set(with: model, delegateObject, additionalData)
|
||||||
self.delegateObject = delegateObject
|
self.delegateObject = delegateObject
|
||||||
|
|
||||||
@ -65,6 +65,7 @@ open class RadioSwatches: View {
|
|||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
// MARK: - Methods
|
// MARK: - Methods
|
||||||
//------------------------------------------------------
|
//------------------------------------------------------
|
||||||
|
/// Registers the cells with the collection view
|
||||||
open func registerCells() {
|
open func registerCells() {
|
||||||
collectionView.register(RadioSwatchItemCollectionViewCell.self, forCellWithReuseIdentifier: "RadioSwatchItemCollectionViewCell")
|
collectionView.register(RadioSwatchItemCollectionViewCell.self, forCellWithReuseIdentifier: "RadioSwatchItemCollectionViewCell")
|
||||||
}
|
}
|
||||||
@ -130,17 +131,17 @@ extension RadioSwatches: UICollectionViewDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
extension RadioSwatches: UICollectionViewDelegate {
|
extension RadioSwatches: UICollectionViewDelegate {
|
||||||
public func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
|
||||||
guard let molecule = swatches?[indexPath.row] else {return true }
|
guard let molecule = swatches?[indexPath.row] else {return true }
|
||||||
return molecule.enabled ?? true
|
return molecule.enabled ?? true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioSwatchItemCollectionViewCell else { return }
|
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioSwatchItemCollectionViewCell else { return }
|
||||||
cell.radioSwatch.selectSwatch()
|
cell.radioSwatch.selectSwatch()
|
||||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
_ = 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? RadioSwatchItemCollectionViewCell else { return }
|
guard let cell = collectionView.cellForItem(at: indexPath) as? RadioSwatchItemCollectionViewCell else { return }
|
||||||
cell.radioSwatch.deselectSwatch()
|
cell.radioSwatch.deselectSwatch()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,7 +61,6 @@ import Foundation
|
|||||||
public var selected: Bool? = false
|
public var selected: Bool? = false
|
||||||
public var enabled: Bool? = true
|
public var enabled: Bool? = true
|
||||||
public var strikethrough: Bool? = false
|
public var strikethrough: Bool? = false
|
||||||
public var fieldKey: String?
|
|
||||||
public var fieldValue: String?
|
public var fieldValue: String?
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user