diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItem.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItem.swift index 9117aee8..a6e6b802 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItem.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItem.swift @@ -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() diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItemCollectionViewCell.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItemCollectionViewCell.swift index 3d3100a8..a820a680 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItemCollectionViewCell.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchItemCollectionViewCell.swift @@ -8,7 +8,7 @@ import Foundation open class RadioSwatchItemCollectionViewCell: CollectionViewCell { - let radioSwatch = RadioSwatchItem() + public let radioSwatch = RadioSwatchItem() open override func setupView() { super.setupView() diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift index 2811da69..f13dd331 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatches.swift @@ -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() } diff --git a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchesModel.swift b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchesModel.swift index 965b72f6..d422d0db 100644 --- a/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchesModel.swift +++ b/MVMCoreUI/Atomic/Atoms/Selectors/RadioSwatchesModel.swift @@ -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 {