didSelect
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
5d5c17606e
commit
f13c9488a4
@ -10,10 +10,7 @@ import UIKit
|
||||
|
||||
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 }
|
||||
|
||||
public override func didSelect(selector: DefaultRadioSwatchModel) {
|
||||
//reset the old model
|
||||
if let selectedModel {
|
||||
let oldSelectedModel = selectedModel.copyWith {
|
||||
@ -23,7 +20,7 @@ public class RadioSwatchGroup: RadioSwatchGroupBase<DefaultRadioSwatchGroupModel
|
||||
}
|
||||
|
||||
//set the new model
|
||||
let newSelectedModel = cell.model.copyWith {
|
||||
let newSelectedModel = selector.copyWith {
|
||||
$0.selected = true
|
||||
}
|
||||
|
||||
@ -52,7 +49,6 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
||||
// MARK: - Private Properties
|
||||
//--------------------------------------------------
|
||||
public var label = Label()
|
||||
|
||||
private let cellSize: CGFloat = 48.0
|
||||
private let lineSpacing: CGFloat = 12.0
|
||||
private let itemSpacing: CGFloat = 16.0
|
||||
@ -70,7 +66,7 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
||||
$0.register(CollectionViewCell<ModelHandlerType>.self, forCellWithReuseIdentifier: "collectionViewCell")
|
||||
}
|
||||
}()
|
||||
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
//--------------------------------------------------
|
||||
@ -88,11 +84,11 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
||||
|
||||
open override func setup() {
|
||||
super.setup()
|
||||
isTappable = false
|
||||
isAccessibilityElement = true
|
||||
accessibilityTraits = .button
|
||||
addSubview(label)
|
||||
addSubview(collectionView)
|
||||
|
||||
NSLayoutConstraint.activate([
|
||||
label.topAnchor.constraint(equalTo: topAnchor),
|
||||
label.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||
@ -156,7 +152,8 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
||||
//implement click event
|
||||
guard let cell = collectionView.cellForItem(at: indexPath) as? CollectionViewCell<ModelHandlerType> else { return }
|
||||
didSelect(selector: cell.model)
|
||||
}
|
||||
|
||||
open func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
|
||||
@ -182,4 +179,8 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
||||
cell?.set(with: model)
|
||||
return cell ?? UICollectionViewCell()
|
||||
}
|
||||
|
||||
open func didSelect(selector: ModelHandlerType.ModelType) {
|
||||
//override to do functionality
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user