This commit is contained in:
Ryan Nystrom
2017-06-20 11:12:54 -04:00
parent c522940ee9
commit 7af03ac74f
8 changed files with 101 additions and 4 deletions

View File

@@ -0,0 +1,44 @@
//
// IssueCommentHrCell.swift
// Freetime
//
// Created by Ryan Nystrom on 6/20/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import UIKit
import SnapKit
import IGListKit
final class IssueCommentHrCell: UICollectionViewCell, IGListBindable {
static let inset = UIEdgeInsets(
top: 0,
left: Styles.Sizes.gutter,
bottom: Styles.Sizes.rowSpacing,
right: Styles.Sizes.gutter
)
let hr = UIView();
override init(frame: CGRect) {
super.init(frame: frame)
contentView.backgroundColor = .white
hr.backgroundColor = Styles.Colors.Gray.lighter
contentView.addSubview(hr)
hr.snp.makeConstraints { make in
make.edges.equalTo(contentView).inset(IssueCommentHrCell.inset)
}
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: IGListBindable
func bindViewModel(_ viewModel: Any) {}
}

View File

@@ -0,0 +1,24 @@
//
// IssueCommentHrModel.swift
// Freetime
//
// Created by Ryan Nystrom on 6/20/17.
// Copyright © 2017 Ryan Nystrom. All rights reserved.
//
import Foundation
import IGListKit
final class IssueCommentHrModel: NSObject, IGListDiffable {
// MARK: IGListDiffable
func diffIdentifier() -> NSObjectProtocol {
return self
}
func isEqual(toDiffableObject object: IGListDiffable?) -> Bool {
return true
}
}

View File

@@ -8,6 +8,14 @@
import UIKit
private func bodyIsCollapsible(body: Any) -> Bool {
if body is IssueCommentHrModel {
return false
} else {
return true
}
}
func IssueCollapsedBodies(bodies: [AnyObject]) -> (AnyObject, CGFloat)? {
let cap: CGFloat = 300
// minimum height to collapse so expanding shows significant amount of content
@@ -17,7 +25,9 @@ func IssueCollapsedBodies(bodies: [AnyObject]) -> (AnyObject, CGFloat)? {
for body in bodies {
let height = bodyHeight(viewModel: body)
totalHeight += height
if totalHeight > cap, totalHeight - cap > minDelta {
if bodyIsCollapsible(body: body),
totalHeight > cap,
totalHeight - cap > minDelta {
let collapsedBodyHeight = max(cap - (totalHeight - height), CollapseCellMinHeight)
return (body, collapsedBodyHeight)
}

View File

@@ -119,6 +119,8 @@ NYTPhotosViewControllerDelegate {
cellClass = IssueCommentQuoteCell.self
} else if viewModel is IssueCommentUnsupportedModel {
cellClass = IssueCommentUnsupportedCell.self
} else if viewModel is IssueCommentHrModel {
cellClass = IssueCommentHrCell.self
} else {
cellClass = IssueCommentTextCell.self
}

View File

@@ -22,6 +22,8 @@ func bodyHeight(viewModel: Any) -> CGFloat {
return Styles.Sizes.gutter * 2 + Styles.Sizes.avatar.height
} else if let viewModel = viewModel as? IssueCommentQuoteModel {
return viewModel.quote.textViewSize.height
} else if viewModel is IssueCommentHrModel {
return 3.0 + IssueCommentHrCell.inset.top + IssueCommentHrCell.inset.bottom
} else {
return Styles.Sizes.tableCellHeight
}

View File

@@ -121,7 +121,7 @@ func createModel(markdown: String, element: MMElement) -> IGListDiffable? {
case .HTML:
return IssueCommentUnsupportedModel(name: "HTML")
case .horizontalRule:
return IssueCommentUnsupportedModel(name: "<hr>")
return IssueCommentHrModel()
default: return nil
}
}

View File

@@ -73,7 +73,6 @@ func createCommentModel(
else { return nil }
let details = IssueCommentDetailsViewModel(date: date, login: author.login, avatarURL: avatarURL)
// let bodies = createCommentModels(body: commentFields.body, width: width)
let bodies = commentModels(markdown: commentFields.body, width: width)
let reactions = createIssueReactions(reactions: reactionFields)
let collapse = IssueCollapsedBodies(bodies: bodies)

View File

@@ -59,6 +59,8 @@
294563EC1EE5012100DBCD35 /* Issue+IssueType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 294563EB1EE5012100DBCD35 /* Issue+IssueType.swift */; };
294563EE1EE5012900DBCD35 /* PullRequest+IssueType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 294563ED1EE5012900DBCD35 /* PullRequest+IssueType.swift */; };
294563F01EE5036A00DBCD35 /* IssueType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 294563EF1EE5036A00DBCD35 /* IssueType.swift */; };
2949674C1EF9716400B1CF1A /* IssueCommentHrModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2949674B1EF9716400B1CF1A /* IssueCommentHrModel.swift */; };
2949674E1EF9719300B1CF1A /* IssueCommentHrCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2949674D1EF9719300B1CF1A /* IssueCommentHrCell.swift */; };
295840651EE89F28007723C6 /* IssueClosedModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 295840641EE89F28007723C6 /* IssueClosedModel.swift */; };
295840671EE89FE4007723C6 /* IssueClosedCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 295840661EE89FE4007723C6 /* IssueClosedCell.swift */; };
295840691EE8A328007723C6 /* IssueClosedSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 295840681EE8A328007723C6 /* IssueClosedSectionController.swift */; };
@@ -338,6 +340,8 @@
294563EB1EE5012100DBCD35 /* Issue+IssueType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Issue+IssueType.swift"; sourceTree = "<group>"; };
294563ED1EE5012900DBCD35 /* PullRequest+IssueType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "PullRequest+IssueType.swift"; sourceTree = "<group>"; };
294563EF1EE5036A00DBCD35 /* IssueType.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueType.swift; sourceTree = "<group>"; };
2949674B1EF9716400B1CF1A /* IssueCommentHrModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueCommentHrModel.swift; sourceTree = "<group>"; };
2949674D1EF9719300B1CF1A /* IssueCommentHrCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueCommentHrCell.swift; sourceTree = "<group>"; };
295840641EE89F28007723C6 /* IssueClosedModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueClosedModel.swift; sourceTree = "<group>"; };
295840661EE89FE4007723C6 /* IssueClosedCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueClosedCell.swift; sourceTree = "<group>"; };
295840681EE8A328007723C6 /* IssueClosedSectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IssueClosedSectionController.swift; sourceTree = "<group>"; };
@@ -481,10 +485,10 @@
292FCAC81EDFCC510026635E /* Comments */ = {
isa = PBXGroup;
children = (
293B58511EF808D1001D067D /* Unsupported */,
292FCAC91EDFCC510026635E /* CodeBlock */,
292FCACC1EDFCC510026635E /* CollapsibleCell.swift */,
292FCACD1EDFCC510026635E /* Details */,
2949674A1EF9714900B1CF1A /* Hr */,
292FCAD01EDFCC510026635E /* Images */,
292FCAD31EDFCC510026635E /* IssueCollapsedBodies.swift */,
292FCAD41EDFCC510026635E /* IssueCommentModel.swift */,
@@ -495,6 +499,7 @@
292FCADE1EDFCC510026635E /* Reactions */,
292FCAE01EDFCC510026635E /* Summary */,
292FCAE31EDFCC510026635E /* Text */,
293B58511EF808D1001D067D /* Unsupported */,
);
path = Comments;
sourceTree = "<group>";
@@ -607,6 +612,15 @@
path = Status;
sourceTree = "<group>";
};
2949674A1EF9714900B1CF1A /* Hr */ = {
isa = PBXGroup;
children = (
2949674B1EF9716400B1CF1A /* IssueCommentHrModel.swift */,
2949674D1EF9719300B1CF1A /* IssueCommentHrCell.swift */,
);
path = Hr;
sourceTree = "<group>";
};
295840631EE89F19007723C6 /* Closed */ = {
isa = PBXGroup;
children = (
@@ -1134,6 +1148,7 @@
2958406D1EE8EBF3007723C6 /* IssueCommentPhoto.swift in Sources */,
293B58531EF808DA001D067D /* IssueCommentUnsupportedModel.swift in Sources */,
294563EA1EE4EEF000DBCD35 /* IssueStatusCell.swift in Sources */,
2949674C1EF9716400B1CF1A /* IssueCommentHrModel.swift in Sources */,
2963A9391EE258C20066509C /* GithubClient+Issues.swift in Sources */,
299F2A121EC3BCF0006CE9D7 /* GithubSessionManager.swift in Sources */,
29A195021EC66B8B00C3E289 /* UIColor+Hex.swift in Sources */,
@@ -1186,6 +1201,7 @@
292FCB141EDFCC510026635E /* IssueLabelsModel.swift in Sources */,
2963A93B1EE25F6F0066509C /* LabelableFields+IssueLabelModel.swift in Sources */,
298BA08D1EC90A9000B01946 /* NSAttributedStringSizing.swift in Sources */,
2949674E1EF9719300B1CF1A /* IssueCommentHrCell.swift in Sources */,
2963A9321EE1EBE20066509C /* UIMenuController+Reactions.swift in Sources */,
29A1950C1EC7901400C3E289 /* NotificationType.swift in Sources */,
29A195041EC74C4800C3E289 /* Date+Display.swift in Sources */,