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

View File

@ -9,6 +9,18 @@ import Foundation
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 typealias SelectorModelType = DefaultRadioSwatchModel
public var inputId: String?