Adding padding related changes to table
This commit is contained in:
parent
a82550ed57
commit
39ef411559
@ -31,6 +31,8 @@ open class Table: View {
|
||||
|
||||
private let flowLayout = MatrixFlowLayout().with {
|
||||
$0.estimatedItemSize = UICollectionViewFlowLayout.automaticSize
|
||||
$0.minimumLineSpacing = 0
|
||||
$0.minimumInteritemSpacing = 0
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
@ -109,7 +111,7 @@ extension Table : UICollectionViewDelegate, UICollectionViewDataSource {
|
||||
let shouldStrip = striped ? (indexPath.section % 2 != 0) : false
|
||||
let style = indexPath.section == 0 ? headerBottomLineType : rowBottomLineType
|
||||
let hideSeparator = indexPath.section == 0 ? headerBottomLine : rowBottomLine
|
||||
cell.updateCell(content: currentItem, surface: surface, separatorStyle: style, isHeader: indexPath.section == 0, hideSeparator: hideSeparator, striped: shouldStrip)
|
||||
cell.updateCell(content: currentItem, surface: surface, separatorStyle: style, isHeader: indexPath.section == 0, hideSeparator: hideSeparator, striped: shouldStrip, padding: padding)
|
||||
return cell
|
||||
}
|
||||
}
|
||||
@ -119,19 +121,8 @@ extension Table: UICollectionViewDelegateFlowLayout {
|
||||
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
||||
guard let sectionCount = tableData?[indexPath.section].count else { return CGSize.zero }
|
||||
let width = Int(collectionView.frame.width) / sectionCount
|
||||
return CGSize(width: width, height: 50)
|
||||
return CGSize(width: width, height: 100)
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
|
||||
//return padding.verticalValue()
|
||||
return 0
|
||||
}
|
||||
|
||||
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
|
||||
//return padding.horizontalValue()
|
||||
return 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
final class MatrixFlowLayout : UICollectionViewFlowLayout {
|
||||
|
||||
@ -30,6 +30,9 @@ final class TableCellItem: UICollectionViewCell {
|
||||
private let backgroundColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundPrimaryLight, VDSColor.backgroundPrimaryDark)
|
||||
private let stripedColorConfiguration = SurfaceColorConfiguration(VDSColor.backgroundSecondaryLight, VDSColor.backgroundSecondaryDark)
|
||||
|
||||
private var labelTopConstraint: NSLayoutConstraint?
|
||||
private var labelBottomConstraint: NSLayoutConstraint?
|
||||
private var labelTrailingConstraint: NSLayoutConstraint?
|
||||
|
||||
override init(frame: CGRect) {
|
||||
super.init(frame: frame)
|
||||
@ -48,13 +51,21 @@ final class TableCellItem: UICollectionViewCell {
|
||||
containerView.pinToSuperView()
|
||||
|
||||
containerView.addSubview(cellLabel)
|
||||
cellLabel.pinToSuperView()
|
||||
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) {
|
||||
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
|
||||
@ -66,6 +77,10 @@ final class TableCellItem: UICollectionViewCell {
|
||||
separator.isHidden = hideSeparator
|
||||
separator.style = separatorStyle
|
||||
separator.surface = surface
|
||||
|
||||
labelTopConstraint?.constant = padding.verticalValue()
|
||||
labelBottomConstraint?.constant = padding.verticalValue()
|
||||
labelTrailingConstraint?.constant = padding.horizontalValue()
|
||||
}
|
||||
|
||||
private func textStyle(for header:Bool) -> TextStyle {
|
||||
@ -73,8 +88,7 @@ final class TableCellItem: UICollectionViewCell {
|
||||
}
|
||||
|
||||
override func preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes {
|
||||
let targetSize = CGSize(width: layoutAttributes.frame.width, height: 0)
|
||||
layoutAttributes.frame.size = contentView.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: .required, verticalFittingPriority: .fittingSizeLevel)
|
||||
layoutAttributes.frame.size = contentView.systemLayoutSizeFitting(layoutAttributes.frame.size, withHorizontalFittingPriority: .required, verticalFittingPriority: .required)
|
||||
return layoutAttributes
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user