Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Classes/Issues/Assignees/IssueAssigneeSummaryCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ final class IssueAssigneeSummaryCell: UICollectionViewCell, UICollectionViewData
label.textColor = Styles.Colors.Gray.light.color
contentView.addSubview(label)
label.snp.makeConstraints { make in
make.centerY.equalTo(contentView)
make.left.equalTo(contentView)
make.centerY.equalToSuperview()
make.left.equalToSuperview()
}

collectionView.backgroundColor = .clear
Expand All @@ -44,7 +44,7 @@ final class IssueAssigneeSummaryCell: UICollectionViewCell, UICollectionViewData
contentView.addSubview(collectionView)
collectionView.snp.makeConstraints { make in
make.left.equalTo(label.snp.right).offset(Styles.Sizes.columnSpacing)
make.top.bottom.right.equalTo(contentView)
make.top.bottom.right.equalToSuperview()
}
}

Expand Down
6 changes: 3 additions & 3 deletions Classes/Issues/Assignees/IssueAssigneeUserCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ final class IssueAssigneeUserCell: UICollectionViewCell, ListBindable {

contentView.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.centerY.equalTo(contentView)
make.left.equalTo(contentView)
make.centerY.equalToSuperview()
make.left.equalToSuperview()
make.size.equalTo(Styles.Sizes.icon)
}

Expand All @@ -38,7 +38,7 @@ final class IssueAssigneeUserCell: UICollectionViewCell, ListBindable {
label.backgroundColor = .clear
contentView.addSubview(label)
label.snp.makeConstraints { make in
make.centerY.equalTo(contentView)
make.centerY.equalToSuperview()
make.left.equalTo(imageView.snp.right).offset(Styles.Sizes.columnSpacing)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ final class IssueTargetBranchSectionController: ListSectionController {
override func didUpdate(to object: Any) {
guard let object = object as? IssueTargetBranchModel else { return }
self.object = object
inset = UIEdgeInsets.zero
}

override func sizeForItem(at index: Int) -> CGSize {
Expand Down
4 changes: 1 addition & 3 deletions Classes/Issues/Branches/IssueTargetBranchModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ final class IssueTargetBranchModel: ListDiffable {

self.targetBranchText = StyledTextRenderer(
string: builder.build(),
contentSizeCategory: .small,
inset: .zero,
backgroundColor: Styles.Colors.background
contentSizeCategory: .small
).warm(width: width)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ final class IssueCommentCodeBlockCell: IssueCommentBaseCell, ListBindable {
)
static let textViewInset = UIEdgeInsets(
top: Styles.Sizes.rowSpacing,
left: Styles.Sizes.commentGutter,
left: Styles.Sizes.columnSpacing,
bottom: Styles.Sizes.rowSpacing,
right: Styles.Sizes.commentGutter
right: Styles.Sizes.columnSpacing
)

let textView = StyledTextView()
Expand Down
50 changes: 9 additions & 41 deletions Classes/Issues/Comments/Details/IssueCommentDetailCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import SDWebImage
import DateAgo

protocol IssueCommentDetailCellDelegate: class {
func didTapMore(cell: IssueCommentDetailCell, sender: UIView)
func didTapProfile(cell: IssueCommentDetailCell)
}

Expand All @@ -25,7 +24,6 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
private let loginLabel = UILabel()
private let dateLabel = ShowMoreDetailsLabel()
private let editedLabel = ShowMoreDetailsLabel()
private let moreButton = UIButton()
private var login = ""

override init(frame: CGRect) {
Expand All @@ -42,7 +40,7 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
contentView.addSubview(imageView)
imageView.snp.makeConstraints { make in
make.size.equalTo(Styles.Sizes.avatar)
make.left.equalTo(Styles.Sizes.commentGutter)
make.left.equalToSuperview()
make.top.equalTo(Styles.Sizes.rowSpacing)
}

Expand All @@ -55,57 +53,33 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
)
contentView.addSubview(loginLabel)
loginLabel.snp.makeConstraints { make in
make.bottom.equalTo(imageView.snp.centerY)
make.centerY.equalTo(imageView)
make.left.equalTo(imageView.snp.right).offset(Styles.Sizes.columnSpacing)
}

dateLabel.font = Styles.Text.secondary.preferredFont
dateLabel.textColor = Styles.Colors.Gray.light.color
contentView.addSubview(dateLabel)
dateLabel.snp.makeConstraints { make in
make.left.equalTo(loginLabel)
make.top.equalTo(loginLabel.snp.bottom)
}

moreButton.setImage(UIImage(named: "bullets")?.withRenderingMode(.alwaysTemplate), for: .normal)
moreButton.contentVerticalAlignment = .center
moreButton.contentHorizontalAlignment = .right
moreButton.imageView?.contentMode = .center
moreButton.tintColor = Styles.Colors.Gray.light.color
moreButton.addTarget(self, action: #selector(IssueCommentDetailCell.onMore(sender:)), for: .touchUpInside)
moreButton.accessibilityLabel = Constants.Strings.moreOptions
contentView.addSubview(moreButton)
moreButton.snp.makeConstraints { make in
make.size.equalTo(Styles.Sizes.buttonMin)
make.centerY.equalTo(imageView)
make.right.equalTo(-Styles.Sizes.commentGutter)
make.centerY.equalTo(loginLabel)
make.right.equalToSuperview()
}

editedLabel.font = Styles.Text.secondary.preferredFont
editedLabel.textColor = Styles.Colors.Gray.light.color
contentView.addSubview(editedLabel)
editedLabel.snp.makeConstraints { make in
make.left.equalTo(dateLabel.snp.right).offset(Styles.Sizes.inlineSpacing)
make.centerY.equalTo(dateLabel)
make.left.equalTo(loginLabel.snp.right).offset(Styles.Sizes.columnSpacing/2)
make.centerY.equalTo(loginLabel)
}
}

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

// MARK: Public API

func setBorderVisible(_ visible: Bool) {
border = visible ? .head : .neck
}

// MARK: Private API

@objc func onMore(sender: UIButton) {
delegate?.didTapMore(cell: self, sender: sender)
}

@objc func onTapAvatar() {
delegate?.didTapProfile(cell: self)
}
Expand All @@ -119,21 +93,15 @@ final class IssueCommentDetailCell: IssueCommentBaseCell, ListBindable {
func bindViewModel(_ viewModel: Any) {
guard let viewModel = viewModel as? IssueCommentDetailsViewModel else { return }

backgroundColor = viewModel.didAuthor
? Styles.Colors.Blue.light.color
: .white

imageView.sd_setImage(with: viewModel.avatarURL)
dateLabel.setText(date: viewModel.date)
dateLabel.setText(date: viewModel.date, format: .short)
loginLabel.text = viewModel.login

if let editedLogin = viewModel.editedBy, let editedDate = viewModel.editedAt {
editedLabel.isHidden = false

let editedByNonOwner = NSLocalizedString("Edited by %@", comment: "")
let editedByOwner = NSLocalizedString("Edited", comment: "")
let format = viewModel.login != editedLogin ? editedByNonOwner : editedByOwner
editedLabel.text = "\(Constants.Strings.bullet) \(String(format: format, editedLogin))"
let edited = NSLocalizedString("edited", comment: "")
editedLabel.text = "\(Constants.Strings.bullet) \(edited)"

let detailFormat = NSLocalizedString("%@ edited this issue %@", comment: "")
editedLabel.detailText = String(format: detailFormat, arguments: [editedLogin, editedDate.agoString(.long)])
Expand Down
6 changes: 3 additions & 3 deletions Classes/Issues/Comments/Hr/IssueCommentHrCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ final class IssueCommentHrCell: IssueCommentBaseCell, ListBindable {

static let inset = UIEdgeInsets(
top: 0,
left: Styles.Sizes.commentGutter,
left: Styles.Sizes.columnSpacing,
bottom: Styles.Sizes.rowSpacing,
right: Styles.Sizes.commentGutter
right: Styles.Sizes.columnSpacing
)

let hr = UIView()
Expand All @@ -27,7 +27,7 @@ final class IssueCommentHrCell: IssueCommentBaseCell, ListBindable {
hr.backgroundColor = Styles.Colors.Gray.lighter.color
contentView.addSubview(hr)
hr.snp.makeConstraints { make in
make.edges.equalTo(contentView).inset(IssueCommentHrCell.inset)
make.edges.equalToSuperview().inset(IssueCommentHrCell.inset)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Classes/Issues/Comments/Html/IssueCommentHtmlCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
// lint compiled style with http://csslint.net/
font-family: -apple-system; font-size: \(Styles.Text.body.preferredFont.pointSize)px;
color: #\(Styles.Colors.Gray.dark);
padding: \(Styles.Sizes.columnSpacing)px \(Styles.Sizes.commentGutter)px 0;
padding: \(Styles.Sizes.columnSpacing)px 0 0;
margin: 0;
}
* { font-family: -apple-system; font-size: \(Styles.Text.body.preferredFont.pointSize)px; }
Expand All @@ -60,7 +60,7 @@ final class IssueCommentHtmlCell: IssueCommentBaseCell, ListBindable, UIWebViewD
dl dd{padding: 0 \(Styles.Sizes.HTML.spacing)px;}
blockquote{font-style: italic; color: #\(Styles.Colors.Gray.medium);}
pre, code{background-color: #\(Styles.Colors.Gray.lighter); font-family: Courier;}
pre{padding: \(Styles.Sizes.columnSpacing)px \(Styles.Sizes.commentGutter)px;}
pre{padding: \(Styles.Sizes.columnSpacing)px 0;}
sub{font-size: \(Styles.Text.secondary.preferredFont.pointSize)px;}
sub a{font-size: \(Styles.Text.secondary.preferredFont.pointSize)px;}
table{border-spacing: 0; border-collapse: collapse;}
Expand Down
99 changes: 9 additions & 90 deletions Classes/Issues/Comments/IssueCommentBaseCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,11 @@ protocol IssueCommentDoubleTapDelegate: class {

class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {

static let collapseCellMinHeight: CGFloat = 30

enum BorderType {
case head
case neck
case tail
}
static let collapseCellMinHeight: CGFloat = 45

weak var doubleTapDelegate: IssueCommentDoubleTapDelegate?
var border: BorderType = .neck {
didSet { setNeedsLayout() }
}
let doubleTapGesture = UITapGestureRecognizer()

private let borderLayer = CAShapeLayer()
private let backgroundLayer = CAShapeLayer()
private let collapseLayer = CAGradientLayer()
private let collapseButton = UIButton()

Expand All @@ -43,35 +32,26 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {
doubleTapGesture.delegate = self
addGestureRecognizer(doubleTapGesture)

// insert above contentView layer
borderLayer.strokeColor = UIColor.red.cgColor
borderLayer.strokeColor = Styles.Colors.Gray.border.color.cgColor
borderLayer.lineWidth = 1 / UIScreen.main.scale
borderLayer.fillColor = nil
layer.addSublayer(borderLayer)

// insert as base layer
backgroundLayer.strokeColor = nil
backgroundLayer.fillColor = UIColor.white.cgColor
layer.insertSublayer(backgroundLayer, at: 0)

collapseLayer.isHidden = true
collapseLayer.colors = [
UIColor(white: 1, alpha: 0).cgColor,
UIColor(white: 1, alpha: 1).cgColor,
UIColor(white: 1, alpha: 1).cgColor
]
collapseLayer.locations = [0, 0.5, 1]

collapseButton.setImage(UIImage(named: "bullets")?.withRenderingMode(.alwaysTemplate), for: .normal)
collapseButton.backgroundColor = Styles.Colors.Blue.medium.color
collapseButton.accessibilityTraits = UIAccessibilityTraitNone
collapseButton.tintColor = .white
collapseButton.titleLabel?.font = Styles.Text.smallTitle.preferredFont
collapseButton.clipsToBounds = true
collapseButton.isHidden = true
collapseButton.contentEdgeInsets = UIEdgeInsets(top: -2, left: 8, bottom: -2, right: 8)
collapseButton.imageEdgeInsets = .zero
collapseButton.sizeToFit()
collapseButton.layer.cornerRadius = collapseButton.bounds.height / 2
collapseButton.layer.borderColor = UIColor(white: 1, alpha: 0.2).cgColor
collapseButton.layer.borderWidth = 1
collapseButton.isUserInteractionEnabled = false // allow tap to pass through to cell
contentView.addSubview(collapseButton)
}
Expand All @@ -84,69 +64,16 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {
super.layoutSubviews()
layoutContentViewForSafeAreaInsets()

let bounds = contentView.frame
let inset = borderLayer.lineWidth / 2
let pixelSnapBounds = bounds.insetBy(dx: inset, dy: inset)
let cornerRadius = Styles.Sizes.cardCornerRadius

let borderPath = UIBezierPath()
let fillPath: UIBezierPath

switch border {
case .head:
borderPath.move(to: CGPoint(x: pixelSnapBounds.minX, y: bounds.maxY))
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.minX, y: pixelSnapBounds.minY + cornerRadius))
borderPath.addQuadCurve(
to: CGPoint(x: pixelSnapBounds.minX + cornerRadius, y: pixelSnapBounds.minY),
controlPoint: CGPoint(x: pixelSnapBounds.minX, y: pixelSnapBounds.minY)
)
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.maxX - cornerRadius, y: pixelSnapBounds.minY))
borderPath.addQuadCurve(
to: CGPoint(x: pixelSnapBounds.maxX, y: pixelSnapBounds.minY + cornerRadius),
controlPoint: CGPoint(x: pixelSnapBounds.maxX, y: pixelSnapBounds.minY)
)
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.maxX, y: bounds.maxY))

fillPath = borderPath.copy() as! UIBezierPath
fillPath.close()
case .neck:
borderPath.move(to: CGPoint(x: pixelSnapBounds.minX, y: bounds.minY))
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.minX, y: bounds.maxY))
borderPath.move(to: CGPoint(x: pixelSnapBounds.maxX, y: bounds.minY))
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.maxX, y: bounds.maxY))

fillPath = UIBezierPath(rect: bounds)
case .tail:
borderPath.move(to: CGPoint(x: pixelSnapBounds.minX, y: bounds.minY))
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.minX, y: pixelSnapBounds.maxY - cornerRadius))
borderPath.addQuadCurve(
to: CGPoint(x: pixelSnapBounds.minX + cornerRadius, y: pixelSnapBounds.maxY),
controlPoint: CGPoint(x: pixelSnapBounds.minX, y: pixelSnapBounds.maxY)
)
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.maxX - cornerRadius, y: pixelSnapBounds.maxY))
borderPath.addQuadCurve(
to: CGPoint(x: pixelSnapBounds.maxX, y: pixelSnapBounds.maxY - cornerRadius),
controlPoint: CGPoint(x: pixelSnapBounds.maxX, y: pixelSnapBounds.maxY)
)
borderPath.addLine(to: CGPoint(x: pixelSnapBounds.maxX, y: bounds.minY))

fillPath = borderPath.copy() as! UIBezierPath
fillPath.close()
}
borderLayer.path = borderPath.cgPath
backgroundLayer.path = fillPath.cgPath

borderLayer.frame = self.bounds
backgroundLayer.frame = self.bounds
let contentBounds = contentView.bounds

if collapseLayer.isHidden == false {
contentView.layer.addSublayer(collapseLayer)
contentView.bringSubview(toFront: collapseButton)

let collapseFrame = CGRect(
x: bounds.minX,
y: bounds.height - IssueCommentBaseCell.collapseCellMinHeight,
width: bounds.width,
x: contentBounds.minX,
y: contentBounds.height - IssueCommentBaseCell.collapseCellMinHeight,
width: contentBounds.width,
height: IssueCommentBaseCell.collapseCellMinHeight
)

Expand All @@ -163,14 +90,6 @@ class IssueCommentBaseCell: UICollectionViewCell, UIGestureRecognizerDelegate {
}
}

override var backgroundColor: UIColor? {
get {
guard let color = backgroundLayer.fillColor else { return nil }
return UIColor(cgColor: color)
}
set { backgroundLayer.fillColor = newValue?.cgColor}
}

override func prepareForReuse() {
super.prepareForReuse()
collapseLayer.isHidden = true
Expand Down
8 changes: 3 additions & 5 deletions Classes/Issues/Comments/IssueCommentModel+Inset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ import UIKit
extension IssueCommentModel {

var commentSectionControllerInset: UIEdgeInsets {
let rowSpacing = Styles.Sizes.rowSpacing

switch threadState {
case .single:
// title and other header objects will have bottom insetting
if isRoot {
return UIEdgeInsets(top: 12, left: 0, bottom: rowSpacing, right: 0)
return UIEdgeInsets(top: Styles.Sizes.rowSpacing/2, left: 0, bottom: 0, right: 0)
} else {
return UIEdgeInsets(top: rowSpacing, left: 0, bottom: rowSpacing, right: 0)
return .zero
}
case .neck:
return .zero
case .tail:
return UIEdgeInsets(top: 0, left: 0, bottom: rowSpacing, right: 0)
return .zero
}
}

Expand Down
Loading