Fix for CXTDT-586375, updating the way padding is set to view, based on striped status.

This commit is contained in:
Sumanth Nadigadda 2024-07-18 19:52:15 +05:30
parent bf46f85622
commit 7f13aebc7e
3 changed files with 18 additions and 18 deletions

View File

@ -51,10 +51,8 @@ open class Table: View {
func horizontalValue() -> CGFloat {
switch self {
case .standard:
return UIDevice.isIPad ? VDSLayout.space8X : VDSLayout.space6X
case .compact:
return UIDevice.isIPad ? VDSLayout.space8X : VDSLayout.space6X
case .standard, .compact:
return UIDevice.isIPad ? VDSLayout.space4X : VDSLayout.space3X
}
}
@ -148,7 +146,9 @@ extension Table: UICollectionViewDelegate, UICollectionViewDataSource, TableColl
let currentItem = tableData[indexPath.section].columns[indexPath.row]
let shouldStrip = striped ? (indexPath.section % 2 != 0) : false
let isHeader = tableData[indexPath.section].isHeader
cell.updateCell(content: currentItem, surface: surface, striped: shouldStrip, padding: padding, isHeader: isHeader)
var edgePadding = UIEdgeInsets(top: padding.verticalValue(), left: 0, bottom: padding.verticalValue(), right: padding.horizontalValue())
edgePadding.left = (indexPath.row == 0 && !striped) ? VDSLayout.space1X : padding.horizontalValue()
cell.updateCell(content: currentItem, surface: surface, striped: shouldStrip, padding: edgePadding, isHeader: isHeader)
return cell
}

View File

@ -29,10 +29,7 @@ final class TableCellItem: UICollectionViewCell {
/// Color configuration for striped background color
private let stripedColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundSecondaryLight, VDSColor.backgroundSecondaryDark)
/// Padding parameter to maintain the edge spacing of the containerView
private var padding: Table.Padding = .standard
//--------------------------------------------------
// MARK: - Initializers
//--------------------------------------------------
@ -58,10 +55,10 @@ 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, isHeader: Bool = false) {
public func updateCell(content: TableItemModel, surface: Surface, striped: Bool = false, padding: UIEdgeInsets, isHeader: Bool = false) {
containerView.subviews.forEach({ $0.removeFromSuperview() })
self.padding = padding
containerView.surface = surface
containerView.backgroundColor = striped ? stripedColorConfiguration.getColor(surface) : backgroundColorConfiguration.getColor(surface)
@ -82,11 +79,11 @@ final class TableCellItem: UICollectionViewCell {
}
NSLayoutConstraint.activate([
component.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: VDSLayout.space1X),
containerView.trailingAnchor.constraint(greaterThanOrEqualTo: component.trailingAnchor, constant: padding.horizontalValue())
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.verticalValue()).isActive = !isHeader
containerView.bottomAnchor.constraint(equalTo: component.bottomAnchor, constant: padding.verticalValue()).isActive = isHeader
component.topAnchor.constraint(equalTo: containerView.topAnchor, constant: padding.top).isActive = !isHeader
containerView.bottomAnchor.constraint(equalTo: component.bottomAnchor, constant: padding.bottom).isActive = isHeader
}
}

View File

@ -40,6 +40,9 @@ class MatrixFlowLayout : UICollectionViewFlowLayout {
///padding type to be set from Table component, which is used to calculate the size & position of the cell.
var layoutPadding: Table.Padding = .standard
///Striped status of Table, based on this status padding of leading attribute changes.
var striped: Bool = false
//--------------------------------------------------
// MARK: - Overrides
//--------------------------------------------------
@ -77,7 +80,7 @@ class MatrixFlowLayout : UICollectionViewFlowLayout {
let selectedItem = delegate.collectionView(collectionView, dataForItemAt: indexPath)
///Calculate the estimated height of the cell
let itemHeight = estimateHeightFor(item: selectedItem, with: itemWidth)
let itemHeight = estimateHeightFor(item: selectedItem, with: itemWidth, index: indexPath)
layoutWidth += itemWidth
@ -108,8 +111,8 @@ class MatrixFlowLayout : UICollectionViewFlowLayout {
}
/// Fetches estimated height by calling the cell's component estimated height and adding padding
private func estimateHeightFor(item: TableItemModel, with width: CGFloat) -> CGFloat {
private func estimateHeightFor(item: TableItemModel, with width: CGFloat, index: IndexPath) -> CGFloat {
let horizontalPadding = (index.row == 0 && !striped) ? (VDSLayout.space1X + layoutPadding.horizontalValue()) : (2 * layoutPadding.horizontalValue())
let itemWidth = width - layoutPadding.horizontalValue() - defaultLeadingPadding
let maxSize = CGSize(width: itemWidth, height: CGFloat.greatestFiniteMagnitude)
let estItemSize = item.component?.systemLayoutSizeFitting(maxSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel) ?? CGSize(width: itemWidth, height: item.defaultHeight)