From d08ecbbcd5c765922d9edbe83a173418b74eb7e3 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Thu, 22 Feb 2018 21:04:53 -0500 Subject: [PATCH] simplify action cell layout (#1574) --- .../Managing/IssueManagingActionCell.swift | 19 ++++++------------- .../IssueManagingSectionController.swift | 12 +++++------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/Classes/Issues/Managing/IssueManagingActionCell.swift b/Classes/Issues/Managing/IssueManagingActionCell.swift index 8bcf354b4..566d1a00d 100644 --- a/Classes/Issues/Managing/IssueManagingActionCell.swift +++ b/Classes/Issues/Managing/IssueManagingActionCell.swift @@ -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) @@ -28,13 +28,13 @@ 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 @@ -42,7 +42,7 @@ final class IssueManagingActionCell: UICollectionViewCell, ListBindable { 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) } } @@ -50,13 +50,6 @@ final class IssueManagingActionCell: UICollectionViewCell, ListBindable { 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) diff --git a/Classes/Issues/Managing/IssueManagingSectionController.swift b/Classes/Issues/Managing/IssueManagingSectionController.swift index 9921f2386..cf83b59bf 100644 --- a/Classes/Issues/Managing/IssueManagingSectionController.swift +++ b/Classes/Issues/Managing/IssueManagingSectionController.swift @@ -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 } @@ -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 ) }