worked on more changes for swatch

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-08-30 17:00:49 -05:00
parent 574d6f84ac
commit 4054695a6b
2 changed files with 44 additions and 22 deletions

View File

@ -22,11 +22,11 @@ public class RadioSwatchGroup: Control<DefaultRadioSwatchGroupModel>, Changable
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Private Properties // MARK: - Private Properties
//-------------------------------------------------- //--------------------------------------------------
private var mainStackView: UIStackView = { private var contentView: UIView = {
return UIStackView().with { return UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .vertical $0.backgroundColor = .clear
$0.spacing = 24
} }
}() }()
@ -43,10 +43,11 @@ public class RadioSwatchGroup: Control<DefaultRadioSwatchGroupModel>, Changable
let layout = UICollectionViewFlowLayout().with { let layout = UICollectionViewFlowLayout().with {
$0.minimumLineSpacing = lineSpacing $0.minimumLineSpacing = lineSpacing
$0.minimumInteritemSpacing = itemSpacing $0.minimumInteritemSpacing = itemSpacing
$0.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
} }
return UICollectionView(frame: .zero, collectionViewLayout: layout).with { return UICollectionView(frame: .zero, collectionViewLayout: layout).with {
$0.backgroundColor = .clear $0.backgroundColor = .clear
$0.showsHorizontalScrollIndicator = false
$0.showsVerticalScrollIndicator = false
$0.translatesAutoresizingMaskIntoConstraints = false $0.translatesAutoresizingMaskIntoConstraints = false
$0.register(CollectionViewCell<ModelHandlerType>.self, forCellWithReuseIdentifier: "collectionViewCell") $0.register(CollectionViewCell<ModelHandlerType>.self, forCellWithReuseIdentifier: "collectionViewCell")
} }
@ -71,21 +72,29 @@ public class RadioSwatchGroup: Control<DefaultRadioSwatchGroupModel>, Changable
super.setup() super.setup()
isAccessibilityElement = true isAccessibilityElement = true
accessibilityTraits = .button accessibilityTraits = .button
addSubview(mainStackView) addSubview(contentView)
mainStackView.addArrangedSubview(label) contentView.addSubview(label)
mainStackView.addArrangedSubview(collectionView) contentView.addSubview(collectionView)
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
mainStackView.topAnchor.constraint(equalTo: topAnchor), contentView.topAnchor.constraint(equalTo: topAnchor),
mainStackView.leadingAnchor.constraint(equalTo: leadingAnchor), contentView.leadingAnchor.constraint(equalTo: leadingAnchor),
mainStackView.trailingAnchor.constraint(equalTo: trailingAnchor), contentView.trailingAnchor.constraint(equalTo: trailingAnchor),
mainStackView.bottomAnchor.constraint(equalTo: bottomAnchor) contentView.bottomAnchor.constraint(equalTo: bottomAnchor),
label.topAnchor.constraint(equalTo: contentView.topAnchor),
label.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
label.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
collectionView.topAnchor.constraint(equalTo: label.bottomAnchor, constant: 24),
collectionView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor)
]) ])
collectionViewHeight = collectionView.heightAnchor.constraint(greaterThanOrEqualToConstant: cellSize) collectionViewHeight = collectionView.heightAnchor.constraint(greaterThanOrEqualToConstant: cellSize)
collectionViewHeight?.isActive = true collectionViewHeight?.isActive = true
collectionViewWidth = collectionView.widthAnchor.constraint(greaterThanOrEqualToConstant: cellSize * 5)
collectionViewWidth = collectionView.widthAnchor.constraint(greaterThanOrEqualToConstant: cellSize * 10)
collectionViewWidth?.isActive = true collectionViewWidth?.isActive = true
} }
open override func shouldUpdateView(viewModel: ModelType) -> Bool { open override func shouldUpdateView(viewModel: ModelType) -> Bool {
@ -99,6 +108,7 @@ public class RadioSwatchGroup: Control<DefaultRadioSwatchGroupModel>, Changable
} }
open override func updateView(viewModel: ModelType) { open override func updateView(viewModel: ModelType) {
label.set(with: viewModel.labelModel)
collectionView.reloadData() collectionView.reloadData()
setNeedsLayout() setNeedsLayout()
} }
@ -106,14 +116,14 @@ public class RadioSwatchGroup: Control<DefaultRadioSwatchGroupModel>, Changable
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Lifecycle // MARK: - Lifecycle
//-------------------------------------------------- //--------------------------------------------------
open override func layoutSubviews() { // open override func layoutSubviews() {
super.layoutSubviews() // super.layoutSubviews()
// Accounts for any collection size changes // // Accounts for any collection size changes
setHeight() // //setHeight()
DispatchQueue.main.async { [weak self] in //// DispatchQueue.main.async { [weak self] in
self?.collectionView.collectionViewLayout.invalidateLayout() //// self?.collectionView.collectionViewLayout.invalidateLayout()
} //// }
} // }
open func setHeight() { open func setHeight() {
let bounds = collectionView.bounds let bounds = collectionView.bounds

View File

@ -9,6 +9,18 @@ import Foundation
public protocol RadioSwatchGroupModel: SelectorGroupSelectedModelable, Equatable where SelectorModelType: RadioSwatchModel { } public protocol RadioSwatchGroupModel: SelectorGroupSelectedModelable, Equatable where SelectorModelType: RadioSwatchModel { }
extension RadioSwatchGroupModel {
public var labelModel: DefaultLabelModel {
var model = DefaultLabelModel()
model.textPosition = .left
model.typograpicalStyle = .BodySmall
model.text = selectedModel?.text ?? " "
model.surface = surface
model.disabled = disabled
return model
}
}
public struct DefaultRadioSwatchGroupModel: RadioSwatchGroupModel { public struct DefaultRadioSwatchGroupModel: RadioSwatchGroupModel {
public typealias SelectorModelType = DefaultRadioSwatchModel public typealias SelectorModelType = DefaultRadioSwatchModel
public var inputId: String? public var inputId: String?