// // BreadcrumbCellItem.swift // VDS // // Created by Kanamarlapudi, Vasavi on 11/03/24. // import UIKit import VDSTokens ///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.space1X $0.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal) $0.setContentHuggingPriority(.defaultHigh, for: .horizontal) } }() 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) { //update surface separator.surface = surface breadCrumbItem.surface = surface breadCrumbItem.setContentCompressionResistancePriority(.defaultLow, for: .horizontal) breadCrumbItem.setContentHuggingPriority(.defaultLow, for: .horizontal) //remove previous views stackView.arrangedSubviews.forEach { $0.removeFromSuperview() } //add to stack stackView.addArrangedSubview(separator) stackView.addArrangedSubview(breadCrumbItem) stackView.setCustomSpacing(VDSLayout.space1X, after: separator) //update separator separator.textColor = textColorConfiguration.getColor(surface) separator.isHidden = hideSlash self.breadCrumbItem = breadCrumbItem layoutIfNeeded() } }