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