From 4054695a6b4d56176e8e23e0b0324a2951c7cf71 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 30 Aug 2022 17:00:49 -0500 Subject: [PATCH] worked on more changes for swatch Signed-off-by: Matt Bruce --- .../RadioSwatch/RadioSwatchGroup.swift | 54 +++++++++++-------- .../RadioSwatch/RadioSwatchGroupModel.swift | 12 +++++ 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index b2d70384..2089d62b 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -22,11 +22,11 @@ public class RadioSwatchGroup: Control, 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, 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.self, forCellWithReuseIdentifier: "collectionViewCell") } @@ -71,21 +72,29 @@ public class RadioSwatchGroup: Control, 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, Changable } open override func updateView(viewModel: ModelType) { + label.set(with: viewModel.labelModel) collectionView.reloadData() setNeedsLayout() } @@ -106,14 +116,14 @@ public class RadioSwatchGroup: Control, 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 diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift b/VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift index 18660d5a..5f0fd4f7 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroupModel.swift @@ -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?