From a9a3aeee18ea132000ecaa25f17456bcccc57dbb Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 31 Aug 2022 09:57:35 -0500 Subject: [PATCH] updated default implementation Signed-off-by: Matt Bruce --- .../RadioSwatch/RadioSwatchGroup.swift | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) 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) {