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