Adding models for the tab cell items

This commit is contained in:
Sumanth Nadigadda 2024-05-02 18:47:30 +05:30
parent 39ef411559
commit d94c845eb3
5 changed files with 96 additions and 23 deletions

View File

@ -25,6 +25,8 @@
445BA07829C07B3D0036A7C5 /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 445BA07729C07B3D0036A7C5 /* Notification.swift */; };
44604AD429CE186A00E62B51 /* NotificationButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD329CE186A00E62B51 /* NotificationButtonModel.swift */; };
44604AD729CE196600E62B51 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD629CE196600E62B51 /* Line.swift */; };
44A952D92BE384C40009F874 /* TableCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952D82BE384C40009F874 /* TableCellModel.swift */; };
44A952DB2BE3852E0009F874 /* TableCellLabelModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952DA2BE3852E0009F874 /* TableCellLabelModel.swift */; };
5F21D7BF28DCEB3D003E7CD6 /* Useable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */; };
5FC35BE328D51405004EBEAC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE228D51405004EBEAC /* Button.swift */; };
710607952B91A99500F2863F /* TitleletChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 710607942B91A99500F2863F /* TitleletChangeLog.txt */; };
@ -216,6 +218,8 @@
445BA07729C07B3D0036A7C5 /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; };
44604AD329CE186A00E62B51 /* NotificationButtonModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationButtonModel.swift; sourceTree = "<group>"; };
44604AD629CE196600E62B51 /* Line.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Line.swift; sourceTree = "<group>"; };
44A952D82BE384C40009F874 /* TableCellModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableCellModel.swift; sourceTree = "<group>"; };
44A952DA2BE3852E0009F874 /* TableCellLabelModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableCellLabelModel.swift; sourceTree = "<group>"; };
5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Useable.swift; sourceTree = "<group>"; };
5FC35BE228D51405004EBEAC /* Button.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Button.swift; sourceTree = "<group>"; };
710607942B91A99500F2863F /* TitleletChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TitleletChangeLog.txt; sourceTree = "<group>"; };
@ -436,6 +440,8 @@
children = (
440B84C92BD8E0E9004A732A /* Table.swift */,
443DBAF92BDA303F0021497E /* TableCellItem.swift */,
44A952D82BE384C40009F874 /* TableCellModel.swift */,
44A952DA2BE3852E0009F874 /* TableCellLabelModel.swift */,
);
path = Table;
sourceTree = "<group>";
@ -1142,6 +1148,7 @@
EAACB89A2B927108006A3869 /* Valuing.swift in Sources */,
EAE785312BA0A438009428EA /* UIImage+Helper.swift in Sources */,
EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */,
44A952D92BE384C40009F874 /* TableCellModel.swift in Sources */,
EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */,
71ACE89C2BA0451200FB6ADC /* PaginationContainer.swift in Sources */,
EAC71A1F2A2E173D00E47A9F /* RadioButton.swift in Sources */,
@ -1211,6 +1218,7 @@
EA0B18052A9E2D2D00F2D0CD /* SelectorBase.swift in Sources */,
EAC71A1D2A2E155A00E47A9F /* Checkbox.swift in Sources */,
EAF7F0AB289B13FD00B287F5 /* TextStyleLabelAttribute.swift in Sources */,
44A952DB2BE3852E0009F874 /* TableCellLabelModel.swift in Sources */,
EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */,
EA81410B2A0E8E3C004F60D2 /* ButtonIcon.swift in Sources */,
EA985BE629688F6A00F2FF2E /* TileletBadgeModel.swift in Sources */,

View File

@ -77,7 +77,7 @@ open class Table: View {
open var rowBottomLineType: Line.Style = .secondary { didSet { setNeedsUpdate() } }
open var tableData: [[Any]]? { didSet { setNeedsUpdate() } }
open var tableData: [[TableCellModel]]? { didSet { setNeedsUpdate() } }
//--------------------------------------------------
// MARK: - Overrides

View File

@ -25,6 +25,10 @@ final class TableCellItem: UICollectionViewCell {
$0.lineBreakMode = .byWordWrapping
}
private var icon = Icon().with {
$0.size = UIDevice.isIPad ? .medium : .small
}
private let separator: Line = Line()
private let backgroundColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, VDSColor.backgroundPrimaryDark)
@ -49,38 +53,50 @@ final class TableCellItem: UICollectionViewCell {
addSubview(containerView)
containerView.pinToSuperView()
containerView.addSubview(cellLabel)
cellLabel.pinLeading()
labelTopConstraint = cellLabel.pinTop(anchor: containerView.topAnchor, constant: 0)
labelBottomConstraint = containerView.pinBottom(anchor: cellLabel.bottomAnchor, constant: 0)
labelTrailingConstraint = containerView.pinTrailing(anchor: cellLabel.trailingAnchor, constant: 0)
labelTopConstraint?.activate()
labelBottomConstraint?.activate()
labelTrailingConstraint?.activate()
containerView.addSubview(separator)
separator.pinLeading().pinTrailing().pinBottom()
}
func updateCell(content: Any, surface: Surface, separatorStyle: Line.Style, isHeader: Bool = false, hideSeparator: Bool = false, striped: Bool = false, padding: Table.Padding = .standard) {
guard let info = content as? String else { return }
cellLabel.textStyle = textStyle(for: isHeader)
cellLabel.text = info
cellLabel.surface = surface
func updateCell(content: TableCellModel, surface: Surface, separatorStyle: Line.Style, isHeader: Bool = false, hideSeparator: Bool = false, striped: Bool = false, padding: Table.Padding = .standard) {
containerView.subviews.forEach({ $0.removeFromSuperview() })
containerView.surface = surface
containerView.backgroundColor = striped ? stripedColorConfiguration.getColor(surface) : backgroundColorConfiguration.getColor(surface)
if let model = content as? Table.TableCellLabelModel {
addLabel(model: model, surface: surface, isHeader: isHeader, padding: padding)
} else if let model = content as? Table.TableCellImageModel {
addImage(model: model, surface: surface)
}
containerView.addSubview(separator)
separator.pinLeading().pinTrailing().pinBottom()
separator.isHidden = hideSeparator
separator.style = separatorStyle
separator.surface = surface
}
private func addLabel(model: Table.TableCellLabelModel, surface: Surface, isHeader: Bool, padding: Table.Padding) {
containerView.addSubview(cellLabel)
cellLabel.pinLeading(VDSLayout.space1X)
NSLayoutConstraint.activate([
cellLabel.topAnchor.constraint(equalTo: containerView.topAnchor, constant: padding.verticalValue()),
containerView.bottomAnchor.constraint(equalTo: cellLabel.bottomAnchor, constant: padding.verticalValue()),
containerView.trailingAnchor.constraint(equalTo: cellLabel.trailingAnchor, constant: padding.horizontalValue())
])
labelTopConstraint?.constant = padding.verticalValue()
labelBottomConstraint?.constant = padding.verticalValue()
labelTrailingConstraint?.constant = padding.horizontalValue()
cellLabel.textStyle = textStyle(for: isHeader)
cellLabel.text = model.text
cellLabel.surface = surface
}
private func addImage(model: Table.TableCellImageModel, surface: Surface) {
containerView.addSubview(icon)
icon.pinLeading().pinCenterY()
icon.name = model.name
icon.surface = surface
}
private func textStyle(for header:Bool) -> TextStyle {

View File

@ -0,0 +1,39 @@
//
// TableCellLabelModel.swift
// VDS
//
// Created by Nadigadda, Sumanth on 02/05/24.
//
import Foundation
extension Table {
public struct TableCellLabelModel: TableCellModel, Surfaceable {
public var text: String
public var accessibilityString: String?
public var surface: Surface
public init(text: String, accessibilityString: String? = "", surface: Surface = .light) {
self.text = text
self.accessibilityString = accessibilityString
self.surface = surface
}
}
public struct TableCellImageModel: TableCellModel, Surfaceable {
public var name: Icon.Name
public var size: Icon.Size
public var surface: Surface
public init(name: Icon.Name, size: Icon.Size, surface: Surface = .light) {
self.name = name
self.size = size
self.surface = surface
}
}
}

View File

@ -0,0 +1,10 @@
//
// TableCellModel.swift
// VDS
//
// Created by Nadigadda, Sumanth on 02/05/24.
//
import Foundation
public protocol TableCellModel { }