updated default implementation
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c6ae09f730
commit
a9a3aeee18
@ -8,7 +8,31 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public class RadioSwatchGroup: RadioSwatchGroupBase<DefaultRadioSwatchGroupModel, RadioSwatch> {}
|
public class RadioSwatchGroup: RadioSwatchGroupBase<DefaultRadioSwatchGroupModel, RadioSwatch> {
|
||||||
|
|
||||||
|
//default implementation
|
||||||
|
open override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
|
guard let cell = collectionView.cellForItem(at: indexPath) as? CollectionViewCell<RadioSwatch> 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<GroupModelType: RadioSwatchGroupModel, ModelHandlerType: ModelHandlerable & UIView>: Control<GroupModelType>, Changable, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate where GroupModelType.SelectorModelType == ModelHandlerType.ModelType {
|
public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHandlerType: ModelHandlerable & UIView>: Control<GroupModelType>, Changable, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate where GroupModelType.SelectorModelType == ModelHandlerType.ModelType {
|
||||||
|
|
||||||
@ -27,7 +51,7 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var label = Label()
|
public var label = Label()
|
||||||
|
|
||||||
private let cellSize: CGFloat = 48.0
|
private let cellSize: CGFloat = 48.0
|
||||||
private let lineSpacing: CGFloat = 12.0
|
private let lineSpacing: CGFloat = 12.0
|
||||||
@ -132,25 +156,7 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||||
guard let cell = collectionView.cellForItem(at: indexPath) as? CollectionViewCell<ModelHandlerType> else { return }
|
//implement click event
|
||||||
|
|
||||||
//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
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
|
open func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user