Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
simplify action cell layout (#1574)
Browse files Browse the repository at this point in the history
  • Loading branch information
rnystrom authored Feb 23, 2018
1 parent 506eb90 commit d08ecbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 20 deletions.
19 changes: 6 additions & 13 deletions Classes/Issues/Managing/IssueManagingActionCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ final class IssueManagingActionCell: UICollectionViewCell, ListBindable {
private let label = UILabel()
private let imageView = UIImageView()

static let iconHeight = Styles.Sizes.buttonIcon.height + Styles.Sizes.rowSpacing * 3
static let height = ceil(iconHeight + Styles.Sizes.rowSpacing * 2.5 + Styles.Text.secondary.size)
static let iconHeight = Styles.Sizes.buttonIcon.height + Styles.Sizes.rowSpacing * 2
static let height = ceil(iconHeight + Styles.Sizes.rowSpacing * 2.5 + Styles.Text.secondary.preferredFont.lineHeight)

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -28,35 +28,28 @@ final class IssueManagingActionCell: UICollectionViewCell, ListBindable {
contentView.layer.cornerRadius = Styles.Sizes.cardCornerRadius

let iconSize = IssueManagingActionCell.iconHeight
imageView.contentMode = .center
imageView.contentMode = .bottom
imageView.clipsToBounds = true
contentView.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.size.equalTo(CGSize(width: iconSize, height: iconSize))
make.centerX.equalTo(contentView)
make.top.equalTo(contentView).offset(Styles.Sizes.rowSpacing/2)
make.centerX.equalToSuperview()
make.centerY.equalToSuperview().offset(-iconSize/2)
}

label.textColor = tint
label.font = Styles.Text.secondaryBold.preferredFont
contentView.addSubview(label)
label.snp.makeConstraints { make in
make.centerX.equalTo(imageView)
make.top.equalTo(imageView.snp.bottom).offset(-Styles.Sizes.rowSpacing)
make.top.equalTo(imageView.snp.bottom).offset(Styles.Sizes.rowSpacing/2 + 2)
}
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func layoutSubviews() {
super.layoutSubviews()
let height = bounds.height - Styles.Sizes.rowSpacing
contentView.frame = CGRect(x: 0, y: 0, width: height, height: height)
contentView.center = CGPoint(x: bounds.width/2, y: bounds.height/2)
}

override var isSelected: Bool {
didSet {
highlight(isSelected)
Expand Down
12 changes: 5 additions & 7 deletions Classes/Issues/Managing/IssueManagingSectionController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ PeopleViewControllerDelegate {
self.client = client
super.init()
inset = UIEdgeInsets(top: Styles.Sizes.gutter, left: 0, bottom: Styles.Sizes.gutter, right: 0)
minimumInteritemSpacing = Styles.Sizes.rowSpacing
minimumLineSpacing = Styles.Sizes.rowSpacing
selectionDelegate = self
dataSource = self
}
Expand Down Expand Up @@ -205,14 +207,10 @@ PeopleViewControllerDelegate {
else { fatalError("Collection context must be set") }

let height = IssueManagingActionCell.height
let width = HangingChadItemWidth(
index: index,
count: viewModels.count,
containerWidth: containerWidth,
desiredItemWidth: height
)

let rawRowCount = min(CGFloat(viewModels.count), floor(containerWidth / (height + minimumInteritemSpacing)))
return CGSize(
width: width,
width: floor((containerWidth - (rawRowCount - 1) * minimumInteritemSpacing) / rawRowCount),
height: height
)
}
Expand Down

0 comments on commit d08ecbb

Please sign in to comment.