diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index a5eabdd5..9487171e 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -8,7 +8,31 @@ import Foundation import UIKit -public class RadioSwatchGroup: RadioSwatchGroupBase {} +public class RadioSwatchGroup: RadioSwatchGroupBase { + + //default implementation + open override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + guard let cell = collectionView.cellForItem(at: indexPath) as? CollectionViewCell else { return } + + //reset the old model + if let selectedModel { + let oldSelectedModel = selectedModel.copyWith { + $0.selected = false + } + replace(viewModel: oldSelectedModel) + } + + //set the new model + let newSelectedModel = cell.model.copyWith { + $0.selected = true + } + + label.text = newSelectedModel.text + replace(viewModel: newSelectedModel) + selectedModel = newSelectedModel + } + +} public class RadioSwatchGroupBase: Control, Changable, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate where GroupModelType.SelectorModelType == ModelHandlerType.ModelType { @@ -27,7 +51,7 @@ public class RadioSwatchGroupBase else { return } - - //reset the old model - if let selectedModel { - let oldSelectedModel = selectedModel.copyWith { - $0.selected = false - } - replace(viewModel: oldSelectedModel) - } - - //set the new model - let newSelectedModel = cell.model.copyWith { - $0.selected = true - } - - label.text = newSelectedModel.text - replace(viewModel: newSelectedModel) - selectedModel = newSelectedModel - + //implement click event } open func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {