Fixing CXTDT-586497 issue, table contents alignment is based on the row type, is header

This commit is contained in:
Sumanth Nadigadda 2024-07-16 12:31:06 +05:30
parent 71c5e444f4
commit bf46f85622
3 changed files with 11 additions and 7 deletions

View File

@ -147,7 +147,8 @@ extension Table: UICollectionViewDelegate, UICollectionViewDataSource, TableColl
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].columns[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) let isHeader = tableData[indexPath.section].isHeader
cell.updateCell(content: currentItem, surface: surface, striped: shouldStrip, padding: padding, isHeader: isHeader)
return cell return cell
} }

View File

@ -58,7 +58,7 @@ final class TableCellItem: UICollectionViewCell {
//-------------------------------------------------- //--------------------------------------------------
/// Updates the cell content with ``TableItemModel`` and styling/padding attributes from other parameters /// 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() }) containerView.subviews.forEach({ $0.removeFromSuperview() })
self.padding = padding self.padding = padding
@ -83,10 +83,10 @@ final class TableCellItem: UICollectionViewCell {
NSLayoutConstraint.activate([ NSLayoutConstraint.activate([
component.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: VDSLayout.space1X), component.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: VDSLayout.space1X),
component.topAnchor.constraint(greaterThanOrEqualTo: containerView.topAnchor, constant: padding.verticalValue()), containerView.trailingAnchor.constraint(greaterThanOrEqualTo: component.trailingAnchor, constant: padding.horizontalValue())
containerView.bottomAnchor.constraint(greaterThanOrEqualTo: component.bottomAnchor, constant: padding.verticalValue()),
containerView.trailingAnchor.constraint(greaterThanOrEqualTo: component.trailingAnchor, constant: padding.horizontalValue()),
containerView.centerYAnchor.constraint(equalTo: component.centerYAnchor)
]) ])
component.topAnchor.constraint(equalTo: containerView.topAnchor, constant: padding.verticalValue()).isActive = !isHeader
containerView.bottomAnchor.constraint(equalTo: component.bottomAnchor, constant: padding.verticalValue()).isActive = isHeader
} }
} }

View File

@ -11,11 +11,14 @@ public struct TableRowModel {
public var columns: [TableItemModel] public var columns: [TableItemModel]
public var isHeader: Bool = false
public var columnsCount: Int { public var columnsCount: Int {
return columns.count return columns.count
} }
public init(columns: [TableItemModel]) { public init(columns: [TableItemModel], isHeader: Bool = false) {
self.columns = columns self.columns = columns
self.isHeader = isHeader
} }
} }