Files
GitHawk/Classes/Issues/Assignees/IssueAssigneeSummaryCell.swift
Ryan Nystrom e56c29a9a6 Redesigned Issues interface (#1983)
* clean up title model

* update title style

* organize issue SC method

* remove background colors from styled text in issues

* collection view bg white

* remove card inset and clean up snap superview code

* clean up label design

* thread is root and change base font size

* remove borders on comment cells

* adjust collapse design

* adjust comment line spacing and make non-root body smaller

* refactor detail view

* viewer header background color

* more buttons in reaction cell

* vertical spacers working

* design basically finished;

* scroll to bottom accounts for inset

* PR review background color white

* fixup PR review comments

* spacing on merge and review

* readme background white

* rename to just "spacer"

* horizontal spacing

* fix tests
2018-07-27 11:03:09 -04:00

89 lines
3.0 KiB
Swift

//
// IssueAssigneeSummaryCell.swift
// Freetime
//
// Created by Ryan Nystrom on 7/13/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
import IGListKit
import SnapKit
final class IssueAssigneeSummaryCell: UICollectionViewCell, UICollectionViewDataSource, ListBindable {
static let reuse = "cell"
private let label = UILabel()
private let collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.itemSize = Styles.Sizes.icon
layout.minimumLineSpacing = Styles.Sizes.columnSpacing / 2.0
let view = UICollectionView(frame: .zero, collectionViewLayout: layout)
view.register(IssueAssigneeAvatarCell.self, forCellWithReuseIdentifier: IssueAssigneeSummaryCell.reuse)
return view
}()
private var urls = [URL]()
override init(frame: CGRect) {
super.init(frame: frame)
label.font = Styles.Text.secondary.preferredFont
label.textColor = Styles.Colors.Gray.light.color
contentView.addSubview(label)
label.snp.makeConstraints { make in
make.centerY.equalToSuperview()
make.left.equalToSuperview()
}
collectionView.backgroundColor = .clear
collectionView.dataSource = self
collectionView.isUserInteractionEnabled = false
contentView.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.equalTo(label.snp.right).offset(Styles.Sizes.columnSpacing)
make.top.bottom.right.equalToSuperview()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
layoutContentViewForSafeAreaInsets()
let height = contentView.bounds.height
let size = (collectionView.collectionViewLayout as? UICollectionViewFlowLayout)?.itemSize ?? .zero
let inset = (height - size.height)/2
collectionView.contentInset = UIEdgeInsets(top: inset, left: 0, bottom: inset, right: 0)
}
// MARK: ListBindable
func bindViewModel(_ viewModel: Any) {
guard let viewModel = viewModel as? IssueAssigneeSummaryModel else { return }
label.text = viewModel.title
urls = viewModel.expanded ? [] : viewModel.urls
collectionView.reloadData()
setNeedsLayout()
}
// MARK: UICollectionViewDataSource
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return urls.count
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: IssueAssigneeSummaryCell.reuse, for: indexPath) as? IssueAssigneeAvatarCell
else { fatalError("Wrong cell type") }
cell.configure(urls[indexPath.item])
return cell
}
}