vds_ios/VDS/Components/Breadcrumbs/BreadcrumbCellItem.swift
Matt Bruce e139a0a0b8 refactor cell some more
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-03-21 14:15:41 -05:00

95 lines
3.0 KiB
Swift

//
// BreadcrumbCellItem.swift
// VDS
//
// Created by Kanamarlapudi, Vasavi on 11/03/24.
//
import UIKit
import VDSColorTokens
///This is customised view for Breadcrumb cell item
final class BreadcrumbCellItem: UICollectionViewCell {
///Identifier for the BreadcrumbCellItem
static let identifier: String = String(describing: BreadcrumbCellItem.self)
//--------------------------------------------------
// MARK: - Private Properties
//--------------------------------------------------
internal var stackView: UIStackView = {
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.axis = .horizontal
$0.distribution = .fill
$0.alignment = .fill
$0.spacing = VDSLayout.Spacing.space1X.value
}
}()
internal var breadCrumbItem: BreadcrumbItem?
///separator label
private var separator: Label = Label().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.textAlignment = .left
$0.numberOfLines = 1
$0.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
$0.setContentHuggingPriority(.defaultHigh, for: .horizontal)
$0.text = "/"
}
private let textColorConfiguration = SurfaceColorConfiguration(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark)
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
override init(frame: CGRect) {
super.init(frame: frame)
setUp()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setUp()
}
///Configuring the cell with default setup
private func setUp() {
separator.textColorConfiguration = textColorConfiguration.eraseToAnyColorable()
contentView.addSubview(stackView)
stackView.pinToSuperView()
separator.backgroundColor = .clear
}
///Updating the breadCrumbItem and UI based on the selected flag along with the surface
func update(surface: Surface, hideSlash: Bool, breadCrumbItem: BreadcrumbItem) {
//remove views from stack
separator.removeFromSuperview()
self.breadCrumbItem?.removeFromSuperview()
//update surface
separator.surface = surface
breadCrumbItem.surface = surface
//add to stack
stackView.addArrangedSubview(separator)
stackView.addArrangedSubview(breadCrumbItem)
stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: separator)
//update separator
separator.textColor = textColorConfiguration.getColor(surface)
separator.isHidden = hideSlash
self.breadCrumbItem = breadCrumbItem
layoutIfNeeded()
}
/// Remove views from StackView.
override func prepareForReuse() {
super.prepareForReuse()
separator.removeFromSuperview()
breadCrumbItem?.removeFromSuperview()
}
}