Files
GitHawk/Classes/Issues/Files/IssueViewFilesCell.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

80 lines
2.6 KiB
Swift

//
// IssueViewFilesCell.swift
// Freetime
//
// Created by Ryan Nystrom on 8/11/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
import SnapKit
final class IssueViewFilesCell: UICollectionViewCell {
private let label = UILabel()
override init(frame: CGRect) {
super.init(frame: frame)
isAccessibilityElement = true
accessibilityTraits |= UIAccessibilityTraitButton
contentView.addSubview(label)
label.snp.makeConstraints { make in
make.left.equalToSuperview()
make.centerY.equalToSuperview()
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
layoutContentViewForSafeAreaInsets()
}
// MARK: Public API
func configure(changes: FileChanges) {
let attributedText = NSMutableAttributedString()
let actionFormat = NSLocalizedString("View Files (%d) ", comment: "")
attributedText.append(NSAttributedString(
string: String(format: actionFormat, changes.changedFiles),
attributes: [
.font: Styles.Text.secondary.preferredFont,
.foregroundColor: Styles.Colors.Blue.medium.color
]
))
if changes.additions > 0 {
attributedText.append(NSAttributedString(
string: "+\(changes.additions) ", // note trailing space
attributes: [
.font: Styles.Text.secondaryBold.preferredFont,
.foregroundColor: Styles.Colors.Green.medium.color
]
))
}
if changes.deletions > 0 {
attributedText.append(NSAttributedString(
string: "-\(changes.deletions)",
attributes: [
.font: Styles.Text.secondaryBold.preferredFont,
.foregroundColor: Styles.Colors.Red.medium.color
]
))
}
label.attributedText = attributedText
accessibilityLabel = NSLocalizedString(
"View Files",
comment: "The accessibility label for the View Files button in a pull request.")
let hintFormat = NSLocalizedString(
"View %zi files with %zi additions and %zi deletions.",
comment: "The accessibility hint with details of the View Files button.")
accessibilityHint = String(format: hintFormat, arguments: [changes.changedFiles, changes.additions, changes.deletions])
}
}