90 lines
3.2 KiB
Swift
90 lines
3.2 KiB
Swift
//
|
|
// TableCellItem.swift
|
|
// VDS
|
|
//
|
|
// Created by Nadigadda, Sumanth on 25/04/24.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDSCoreTokens
|
|
|
|
final class TableCellItem: UICollectionViewCell {
|
|
|
|
/// Identifier for TableCellItem
|
|
static let Identifier: String = String(describing: TableCellItem.self)
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Private Properties
|
|
//--------------------------------------------------
|
|
|
|
/// Main view which holds the content of the cell
|
|
private let containerView = View()
|
|
|
|
/// Line seperator for cell
|
|
private let separator: Line = Line()
|
|
|
|
/// Color configuration for default background color
|
|
private let backgroundColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, VDSColor.backgroundPrimaryDark)
|
|
|
|
/// Color configuration for striped background color
|
|
private let stripedColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundSecondaryLight, VDSColor.backgroundSecondaryDark)
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Initializers
|
|
//--------------------------------------------------
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
setupCell()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
setupCell()
|
|
}
|
|
|
|
private func setupCell() {
|
|
contentView.backgroundColor = .clear
|
|
|
|
addSubview(containerView)
|
|
containerView.pinToSuperView()
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Public Methods
|
|
//--------------------------------------------------
|
|
|
|
/// Updates the cell content with ``TableItemModel`` and styling/padding attributes from other parameters
|
|
public func updateCell(content: TableItemModel, surface: Surface, striped: Bool = false, padding: UIEdgeInsets, isHeader: Bool = false) {
|
|
|
|
containerView.subviews.forEach({ $0.removeFromSuperview() })
|
|
|
|
containerView.surface = surface
|
|
containerView.backgroundColor = striped ? stripedColorConfiguration.getColor(surface) : backgroundColorConfiguration.getColor(surface)
|
|
|
|
|
|
containerView.addSubview(separator)
|
|
separator.pinLeading().pinTrailing().pinBottom()
|
|
|
|
separator.style = content.bottomLine ?? .primary
|
|
separator.isHidden = content.bottomLine == nil
|
|
separator.surface = surface
|
|
|
|
guard let component = content.component else { return }
|
|
|
|
containerView.addSubview(component)
|
|
|
|
if var surfacedView = component as? Surfaceable {
|
|
surfacedView.surface = surface
|
|
}
|
|
|
|
NSLayoutConstraint.activate([
|
|
component.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: padding.left),
|
|
containerView.trailingAnchor.constraint(greaterThanOrEqualTo: component.trailingAnchor, constant: padding.right)
|
|
])
|
|
|
|
component.topAnchor.constraint(equalTo: containerView.topAnchor, constant: padding.top).isActive = !isHeader
|
|
containerView.bottomAnchor.constraint(equalTo: component.bottomAnchor, constant: padding.bottom).isActive = isHeader
|
|
}
|
|
}
|