vds_ios/VDS/Components/Breadcrumbs/BreadcrumbCellItem.swift

83 lines
2.6 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 = .top
}
}()
internal var breadcrumb = BreadcrumbItem().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.titleLabel?.numberOfLines = 0
}
///separator label
private var separator: Label = Label().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.textAlignment = .left
$0.numberOfLines = 0
$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() {
//add stackview
//this is the horizontal stack that contains breadcrumb and separator
stackView.addArrangedSubview(breadcrumb)
stackView.addArrangedSubview(separator)
stackView.setCustomSpacing(VDSLayout.Spacing.space1X.value, after: breadcrumb)
stackView
.pinTop()
.pinLeading()
.pinTrailing(0, .defaultHigh)
.pinBottom(0, .defaultHigh)
contentView.addSubview(stackView)
separator.backgroundColor = .clear
// stackView.backgroundColor = .red
// breadcrumb.backgroundColor = .green
// separator.backgroundColor = .yellow
}
///Updating UI based on selected index, current index along with surface
func update(_ selectedIndex: Int, currentIndex: Int, surface: Surface, showSlash: Bool) {
separator.textColor = textColorConfiguration.getColor(surface)
separator.isHidden = showSlash
}
}