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> {
|
public class RadioSwatchGroup: RadioSwatchGroupBase<DefaultRadioSwatchGroupModel, RadioSwatch> {
|
||||||
|
|
||||||
//default implementation
|
public override func didSelect(selector: DefaultRadioSwatchModel) {
|
||||||
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
|
//reset the old model
|
||||||
if let selectedModel {
|
if let selectedModel {
|
||||||
let oldSelectedModel = selectedModel.copyWith {
|
let oldSelectedModel = selectedModel.copyWith {
|
||||||
@ -23,7 +20,7 @@ public class RadioSwatchGroup: RadioSwatchGroupBase<DefaultRadioSwatchGroupModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
//set the new model
|
//set the new model
|
||||||
let newSelectedModel = cell.model.copyWith {
|
let newSelectedModel = selector.copyWith {
|
||||||
$0.selected = true
|
$0.selected = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,7 +49,6 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
|||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public 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
|
||||||
private let itemSpacing: CGFloat = 16.0
|
private let itemSpacing: CGFloat = 16.0
|
||||||
@ -70,7 +66,7 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
|||||||
$0.register(CollectionViewCell<ModelHandlerType>.self, forCellWithReuseIdentifier: "collectionViewCell")
|
$0.register(CollectionViewCell<ModelHandlerType>.self, forCellWithReuseIdentifier: "collectionViewCell")
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -88,11 +84,11 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
|||||||
|
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
isTappable = false
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
addSubview(label)
|
addSubview(label)
|
||||||
addSubview(collectionView)
|
addSubview(collectionView)
|
||||||
|
|
||||||
NSLayoutConstraint.activate([
|
NSLayoutConstraint.activate([
|
||||||
label.topAnchor.constraint(equalTo: topAnchor),
|
label.topAnchor.constraint(equalTo: topAnchor),
|
||||||
label.leadingAnchor.constraint(equalTo: leadingAnchor),
|
label.leadingAnchor.constraint(equalTo: leadingAnchor),
|
||||||
@ -156,7 +152,8 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
|||||||
}
|
}
|
||||||
|
|
||||||
open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
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) {
|
open func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
|
||||||
@ -182,4 +179,8 @@ public class RadioSwatchGroupBase<GroupModelType: RadioSwatchGroupModel, ModelHa
|
|||||||
cell?.set(with: model)
|
cell?.set(with: model)
|
||||||
return cell ?? UICollectionViewCell()
|
return cell ?? UICollectionViewCell()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open func didSelect(selector: ModelHandlerType.ModelType) {
|
||||||
|
//override to do functionality
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user