Table component refactoring, TableRowModel creation & table item will be able to take a empty view.

This commit is contained in:
Sumanth Nadigadda 2024-05-27 15:02:49 +05:30
parent 7748a5eae4
commit b88d76da41
6 changed files with 79 additions and 25 deletions

View File

@ -25,8 +25,9 @@
445BA07829C07B3D0036A7C5 /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 445BA07729C07B3D0036A7C5 /* Notification.swift */; }; 445BA07829C07B3D0036A7C5 /* Notification.swift in Sources */ = {isa = PBXBuildFile; fileRef = 445BA07729C07B3D0036A7C5 /* Notification.swift */; };
44604AD429CE186A00E62B51 /* NotificationButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD329CE186A00E62B51 /* NotificationButtonModel.swift */; }; 44604AD429CE186A00E62B51 /* NotificationButtonModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD329CE186A00E62B51 /* NotificationButtonModel.swift */; };
44604AD729CE196600E62B51 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD629CE196600E62B51 /* Line.swift */; }; 44604AD729CE196600E62B51 /* Line.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD629CE196600E62B51 /* Line.swift */; };
44A952D92BE384C40009F874 /* TableCellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952D82BE384C40009F874 /* TableCellModel.swift */; }; 44A952D92BE384C40009F874 /* TableItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952D82BE384C40009F874 /* TableItemModel.swift */; };
44A952DD2BE3DA820009F874 /* TableFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */; }; 44A952DD2BE3DA820009F874 /* TableFlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */; };
44BD43B62C04866600644F87 /* TableRowModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44BD43B52C04866600644F87 /* TableRowModel.swift */; };
5F21D7BF28DCEB3D003E7CD6 /* Useable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */; }; 5F21D7BF28DCEB3D003E7CD6 /* Useable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */; };
5FC35BE328D51405004EBEAC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE228D51405004EBEAC /* Button.swift */; }; 5FC35BE328D51405004EBEAC /* Button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE228D51405004EBEAC /* Button.swift */; };
710607952B91A99500F2863F /* TitleletChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 710607942B91A99500F2863F /* TitleletChangeLog.txt */; }; 710607952B91A99500F2863F /* TitleletChangeLog.txt in Resources */ = {isa = PBXBuildFile; fileRef = 710607942B91A99500F2863F /* TitleletChangeLog.txt */; };
@ -218,8 +219,9 @@
445BA07729C07B3D0036A7C5 /* Notification.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Notification.swift; sourceTree = "<group>"; }; 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>"; }; 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>"; }; 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>"; }; 44A952D82BE384C40009F874 /* TableItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableItemModel.swift; sourceTree = "<group>"; };
44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableFlowLayout.swift; sourceTree = "<group>"; }; 44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableFlowLayout.swift; sourceTree = "<group>"; };
44BD43B52C04866600644F87 /* TableRowModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableRowModel.swift; sourceTree = "<group>"; };
5F21D7BE28DCEB3D003E7CD6 /* Useable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Useable.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>"; }; 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>"; }; 710607942B91A99500F2863F /* TitleletChangeLog.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TitleletChangeLog.txt; sourceTree = "<group>"; };
@ -441,7 +443,8 @@
440B84C92BD8E0E9004A732A /* Table.swift */, 440B84C92BD8E0E9004A732A /* Table.swift */,
443DBAF92BDA303F0021497E /* TableCellItem.swift */, 443DBAF92BDA303F0021497E /* TableCellItem.swift */,
44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */, 44A952DC2BE3DA820009F874 /* TableFlowLayout.swift */,
44A952D82BE384C40009F874 /* TableCellModel.swift */, 44BD43B52C04866600644F87 /* TableRowModel.swift */,
44A952D82BE384C40009F874 /* TableItemModel.swift */,
); );
path = Table; path = Table;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1148,7 +1151,7 @@
EAACB89A2B927108006A3869 /* Valuing.swift in Sources */, EAACB89A2B927108006A3869 /* Valuing.swift in Sources */,
EAE785312BA0A438009428EA /* UIImage+Helper.swift in Sources */, EAE785312BA0A438009428EA /* UIImage+Helper.swift in Sources */,
EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */, EAB5FEF5292D371F00998C17 /* ButtonBase.swift in Sources */,
44A952D92BE384C40009F874 /* TableCellModel.swift in Sources */, 44A952D92BE384C40009F874 /* TableItemModel.swift in Sources */,
EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */, EA978EC5291D6AFE00ACC883 /* AnyLabelAttribute.swift in Sources */,
71ACE89C2BA0451200FB6ADC /* PaginationContainer.swift in Sources */, 71ACE89C2BA0451200FB6ADC /* PaginationContainer.swift in Sources */,
EAC71A1F2A2E173D00E47A9F /* RadioButton.swift in Sources */, EAC71A1F2A2E173D00E47A9F /* RadioButton.swift in Sources */,
@ -1178,6 +1181,7 @@
EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */, EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */,
EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */, EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */,
443DBAFA2BDA303F0021497E /* TableCellItem.swift in Sources */, 443DBAFA2BDA303F0021497E /* TableCellItem.swift in Sources */,
44BD43B62C04866600644F87 /* TableRowModel.swift in Sources */,
71FC86DA2B96F44C00700965 /* PaginationButton.swift in Sources */, 71FC86DA2B96F44C00700965 /* PaginationButton.swift in Sources */,
EABFEB642A26473700C4C106 /* NSAttributedString.swift in Sources */, EABFEB642A26473700C4C106 /* NSAttributedString.swift in Sources */,
EAF7F13328A2A16500B287F5 /* AttachmentLabelAttributeModel.swift in Sources */, EAF7F13328A2A16500B287F5 /* AttachmentLabelAttributeModel.swift in Sources */,

View File

@ -37,7 +37,7 @@ open class Table: View {
} }
/// Array of ``TableItemModel`` by combining Header & Row items /// Array of ``TableItemModel`` by combining Header & Row items
private var tableData: [[TableItemModel]] { private var tableData: [TableRowModel] {
return tableHeader + tableRows return tableHeader + tableRows
} }
@ -79,10 +79,10 @@ open class Table: View {
open var padding: Padding = .standard { didSet { setNeedsUpdate() } } open var padding: Padding = .standard { didSet { setNeedsUpdate() } }
/// Parameter to show the table header row /// Parameter to show the table header row
open var tableHeader: [[TableItemModel]] = [] { didSet { setNeedsUpdate() } } open var tableHeader: [TableRowModel] = [] { didSet { setNeedsUpdate() } }
/// Parameter to show the all table rows /// Parameter to show the all table rows
open var tableRows: [[TableItemModel]] = [] { didSet { setNeedsUpdate() } } open var tableRows: [TableRowModel] = [] { didSet { setNeedsUpdate() } }
open var fillContainer: Bool = true { didSet { setNeedsUpdate() } } open var fillContainer: Bool = true { didSet { setNeedsUpdate() } }
@ -123,7 +123,7 @@ open class Table: View {
} }
func calculateColumnWidths() -> [CGFloat] { func calculateColumnWidths() -> [CGFloat] {
guard let noOfColumns = tableData.first?.count else { return [] } guard let noOfColumns = tableData.first?.columnsCount else { return [] }
let itemWidth = floor(matrixView.safeAreaLayoutGuide.layoutFrame.width / CGFloat(noOfColumns)) let itemWidth = floor(matrixView.safeAreaLayoutGuide.layoutFrame.width / CGFloat(noOfColumns))
return Array(repeating: itemWidth, count: noOfColumns) return Array(repeating: itemWidth, count: noOfColumns)
} }
@ -140,12 +140,12 @@ extension Table: UICollectionViewDelegate, UICollectionViewDataSource, TableColl
return tableData.count return tableData.count
} }
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return tableData[section].count return tableData[section].columnsCount
} }
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TableCellItem.Identifier, for: indexPath) as? TableCellItem else { return UICollectionViewCell() } guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TableCellItem.Identifier, for: indexPath) as? TableCellItem else { return UICollectionViewCell() }
let currentItem = tableData[indexPath.section][indexPath.row] let currentItem = tableData[indexPath.section].columns[indexPath.row]
let shouldStrip = striped ? (indexPath.section % 2 != 0) : false let shouldStrip = striped ? (indexPath.section % 2 != 0) : false
cell.updateCell(content: currentItem, surface: surface, striped: shouldStrip, padding: padding) cell.updateCell(content: currentItem, surface: surface, striped: shouldStrip, padding: padding)
return cell return cell
@ -156,7 +156,7 @@ extension Table: UICollectionViewDelegate, UICollectionViewDataSource, TableColl
//-------------------------------------------------- //--------------------------------------------------
func collectionView(_ collectionView: UICollectionView, dataForItemAt indexPath: IndexPath) -> TableItemModel { func collectionView(_ collectionView: UICollectionView, dataForItemAt indexPath: IndexPath) -> TableItemModel {
return tableData[indexPath.section][indexPath.row] return tableData[indexPath.section].columns[indexPath.row]
} }
func collectionView(_ collectionView: UICollectionView, widthForItemAt indexPath: IndexPath) -> CGFloat { func collectionView(_ collectionView: UICollectionView, widthForItemAt indexPath: IndexPath) -> CGFloat {

View File

@ -65,19 +65,6 @@ final class TableCellItem: UICollectionViewCell {
containerView.surface = surface containerView.surface = surface
containerView.backgroundColor = striped ? stripedColorConfiguration.getColor(surface) : backgroundColorConfiguration.getColor(surface) containerView.backgroundColor = striped ? stripedColorConfiguration.getColor(surface) : backgroundColorConfiguration.getColor(surface)
containerView.addSubview(content.component)
if var surfacedView = content.component as? Surfaceable {
surfacedView.surface = surface
}
NSLayoutConstraint.activate([
content.component.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: VDSLayout.space1X),
content.component.topAnchor.constraint(greaterThanOrEqualTo: containerView.topAnchor, constant: padding.verticalValue()),
containerView.bottomAnchor.constraint(greaterThanOrEqualTo: content.component.bottomAnchor, constant: padding.verticalValue()),
containerView.trailingAnchor.constraint(greaterThanOrEqualTo: content.component.trailingAnchor, constant: padding.horizontalValue()),
containerView.centerYAnchor.constraint(equalTo: content.component.centerYAnchor)
])
containerView.addSubview(separator) containerView.addSubview(separator)
separator.pinLeading().pinTrailing().pinBottom() separator.pinLeading().pinTrailing().pinBottom()
@ -85,5 +72,21 @@ final class TableCellItem: UICollectionViewCell {
separator.style = content.bottomLine ?? .primary separator.style = content.bottomLine ?? .primary
separator.isHidden = content.bottomLine == nil separator.isHidden = content.bottomLine == nil
separator.surface = surface 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: VDSLayout.space1X),
component.topAnchor.constraint(greaterThanOrEqualTo: containerView.topAnchor, constant: padding.verticalValue()),
containerView.bottomAnchor.constraint(greaterThanOrEqualTo: component.bottomAnchor, constant: padding.verticalValue()),
containerView.trailingAnchor.constraint(greaterThanOrEqualTo: component.trailingAnchor, constant: padding.horizontalValue()),
containerView.centerYAnchor.constraint(equalTo: component.centerYAnchor)
])
} }
} }

View File

@ -112,7 +112,7 @@ class MatrixFlowLayout : UICollectionViewFlowLayout {
let itemWidth = width - layoutPadding.horizontalValue() - defaultLeadingPadding let itemWidth = width - layoutPadding.horizontalValue() - defaultLeadingPadding
let maxSize = CGSize(width: itemWidth, height: CGFloat.greatestFiniteMagnitude) let maxSize = CGSize(width: itemWidth, height: CGFloat.greatestFiniteMagnitude)
let estItemSize = item.component.systemLayoutSizeFitting(maxSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel) let estItemSize = item.component?.systemLayoutSizeFitting(maxSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel) ?? CGSize(width: itemWidth, height: item.defaultHeight)
return estItemSize.height + (2 * layoutPadding.verticalValue()) return estItemSize.height + (2 * layoutPadding.verticalValue())
} }

View File

@ -0,0 +1,26 @@
//
// TableItemModel.swift
// VDS
//
// Created by Nadigadda, Sumanth on 02/05/24.
//
import Foundation
import UIKit
import VDSTokens
/// Model that represent the content of each cell of Table component
public struct TableItemModel {
public let defaultHeight: CGFloat = 50.0
public var bottomLine: Line.Style?
/// Component to be show in the Table cell
public var component: UIView?
public init(bottomLine: Line.Style? = nil, component: UIView? = nil) {
self.bottomLine = bottomLine
self.component = component
}
}

View File

@ -0,0 +1,21 @@
//
// TableRowModel.swift
// VDS
//
// Created by Sumanth Nadigadda on 27/05/24.
//
import Foundation
public struct TableRowModel {
public var columns: [TableItemModel]
public var columnsCount: Int {
return columns.count
}
public init(columns: [TableItemModel]) {
self.columns = columns
}
}