From bf46f85622d714a5131acdcd65bf4c333264fa6c Mon Sep 17 00:00:00 2001 From: Sumanth Nadigadda Date: Tue, 16 Jul 2024 12:31:06 +0530 Subject: [PATCH] Fixing CXTDT-586497 issue, table contents alignment is based on the row type, is header --- VDS/Components/Table/Table.swift | 3 ++- VDS/Components/Table/TableCellItem.swift | 10 +++++----- VDS/Components/Table/TableRowModel.swift | 5 ++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/VDS/Components/Table/Table.swift b/VDS/Components/Table/Table.swift index 8ce5f462..9ce35ef6 100644 --- a/VDS/Components/Table/Table.swift +++ b/VDS/Components/Table/Table.swift @@ -147,7 +147,8 @@ extension Table: UICollectionViewDelegate, UICollectionViewDataSource, TableColl guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TableCellItem.Identifier, for: indexPath) as? TableCellItem else { return UICollectionViewCell() } let currentItem = tableData[indexPath.section].columns[indexPath.row] let shouldStrip = striped ? (indexPath.section % 2 != 0) : false - cell.updateCell(content: currentItem, surface: surface, striped: shouldStrip, padding: padding) + let isHeader = tableData[indexPath.section].isHeader + cell.updateCell(content: currentItem, surface: surface, striped: shouldStrip, padding: padding, isHeader: isHeader) return cell } diff --git a/VDS/Components/Table/TableCellItem.swift b/VDS/Components/Table/TableCellItem.swift index 23d2df74..ddd35277 100644 --- a/VDS/Components/Table/TableCellItem.swift +++ b/VDS/Components/Table/TableCellItem.swift @@ -58,7 +58,7 @@ final class TableCellItem: UICollectionViewCell { //-------------------------------------------------- /// Updates the cell content with ``TableItemModel`` and styling/padding attributes from other parameters - public func updateCell(content: TableItemModel, surface: Surface, striped: Bool = false, padding: Table.Padding = .standard) { + public func updateCell(content: TableItemModel, surface: Surface, striped: Bool = false, padding: Table.Padding = .standard, isHeader: Bool = false) { containerView.subviews.forEach({ $0.removeFromSuperview() }) self.padding = padding @@ -83,10 +83,10 @@ final class TableCellItem: UICollectionViewCell { 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) + containerView.trailingAnchor.constraint(greaterThanOrEqualTo: component.trailingAnchor, constant: padding.horizontalValue()) ]) + + component.topAnchor.constraint(equalTo: containerView.topAnchor, constant: padding.verticalValue()).isActive = !isHeader + containerView.bottomAnchor.constraint(equalTo: component.bottomAnchor, constant: padding.verticalValue()).isActive = isHeader } } diff --git a/VDS/Components/Table/TableRowModel.swift b/VDS/Components/Table/TableRowModel.swift index a838438f..22f428ce 100644 --- a/VDS/Components/Table/TableRowModel.swift +++ b/VDS/Components/Table/TableRowModel.swift @@ -11,11 +11,14 @@ public struct TableRowModel { public var columns: [TableItemModel] + public var isHeader: Bool = false + public var columnsCount: Int { return columns.count } - public init(columns: [TableItemModel]) { + public init(columns: [TableItemModel], isHeader: Bool = false) { self.columns = columns + self.isHeader = isHeader } }