mirror of
https://github.com/zhigang1992/GitHawk.git
synced 2026-05-30 04:07:44 +08:00
text and header alignment
This commit is contained in:
@@ -11,7 +11,18 @@ import IGListKit
|
||||
|
||||
final class IssueCommentCodeBlockCell: UICollectionViewCell, IGListBindable, CollapsibleCell {
|
||||
|
||||
static let inset = Styles.Sizes.textCellInset
|
||||
static let scrollViewInset = UIEdgeInsets(
|
||||
top: Styles.Sizes.rowSpacing,
|
||||
left: 0,
|
||||
bottom: Styles.Sizes.rowSpacing,
|
||||
right: 0
|
||||
)
|
||||
static let textViewInset = UIEdgeInsets(
|
||||
top: Styles.Sizes.rowSpacing,
|
||||
left: Styles.Sizes.gutter,
|
||||
bottom: Styles.Sizes.rowSpacing,
|
||||
right: Styles.Sizes.gutter
|
||||
)
|
||||
|
||||
let label = UILabel()
|
||||
let scrollView = UIScrollView()
|
||||
@@ -38,7 +49,13 @@ final class IssueCommentCodeBlockCell: UICollectionViewCell, IGListBindable, Col
|
||||
super.layoutSubviews()
|
||||
// size the scrollview to the width of the cell but match its height to its content size
|
||||
// that way when the cell is collapsed, the scroll view isn't vertically scrollable
|
||||
scrollView.frame = CGRect(x: 0, y: 0, width: contentView.bounds.width, height: scrollView.contentSize.height)
|
||||
let inset = IssueCommentCodeBlockCell.scrollViewInset
|
||||
scrollView.frame = CGRect(
|
||||
x: inset.left,
|
||||
y: inset.top,
|
||||
width: contentView.bounds.width - inset.left - inset.right,
|
||||
height: scrollView.contentSize.height
|
||||
)
|
||||
LayoutCollapsible(layer: overlay, view: contentView)
|
||||
}
|
||||
|
||||
@@ -52,7 +69,7 @@ final class IssueCommentCodeBlockCell: UICollectionViewCell, IGListBindable, Col
|
||||
|
||||
label.attributedText = viewModel.code.attributedText
|
||||
let textFrame = CGRect(x: 0, y: 0, width: contentSize.width, height: contentSize.height)
|
||||
label.frame = UIEdgeInsetsInsetRect(textFrame, IssueCommentTextCell.inset)
|
||||
label.frame = UIEdgeInsetsInsetRect(textFrame, IssueCommentCodeBlockCell.textViewInset)
|
||||
}
|
||||
|
||||
// MARK: CollapsibleCell
|
||||
|
||||
@@ -12,7 +12,8 @@ func bodyHeight(viewModel: Any) -> CGFloat {
|
||||
if let viewModel = viewModel as? NSAttributedStringSizing {
|
||||
return viewModel.textViewSize.height
|
||||
} else if let viewModel = viewModel as? IssueCommentCodeBlockModel {
|
||||
return viewModel.code.textViewSize.height
|
||||
let inset = IssueCommentCodeBlockCell.scrollViewInset
|
||||
return viewModel.code.textViewSize.height + inset.top + inset.bottom
|
||||
} else if viewModel is IssueCommentImageModel {
|
||||
return 200.0
|
||||
} else if viewModel is IssueCommentReactionViewModel {
|
||||
|
||||
@@ -21,10 +21,13 @@ private func codeBlockString(
|
||||
string: body.trimmingCharacters(in: .whitespacesAndNewlines),
|
||||
attributes: attributes
|
||||
)
|
||||
var inset = IssueCommentCodeBlockCell.textViewInset
|
||||
inset.left += IssueCommentCodeBlockCell.scrollViewInset.left
|
||||
inset.right += IssueCommentCodeBlockCell.scrollViewInset.right
|
||||
return NSAttributedStringSizing(
|
||||
containerWidth: 0,
|
||||
attributedText: attributedText,
|
||||
inset: IssueCommentCodeBlockCell.inset
|
||||
inset: inset
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@ private func bodyString(
|
||||
]
|
||||
textAttributes.linkAttributes = [
|
||||
NSForegroundColorAttributeName: Styles.Colors.Blue.medium,
|
||||
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue,
|
||||
]
|
||||
textAttributes.inlineCodeAttributes = [
|
||||
NSForegroundColorAttributeName: Styles.Colors.Gray.dark,
|
||||
@@ -63,6 +62,40 @@ private func bodyString(
|
||||
NSParagraphStyleAttributeName: NSParagraphStyle(),
|
||||
]
|
||||
|
||||
let headerParaStyle = NSMutableParagraphStyle()
|
||||
headerParaStyle.paragraphSpacingBefore = 8
|
||||
|
||||
textAttributes.h1Attributes = [
|
||||
NSParagraphStyleAttributeName: headerParaStyle,
|
||||
NSForegroundColorAttributeName: Styles.Colors.Gray.dark,
|
||||
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 24),
|
||||
]
|
||||
textAttributes.h2Attributes = [
|
||||
NSParagraphStyleAttributeName: headerParaStyle,
|
||||
NSForegroundColorAttributeName: Styles.Colors.Gray.dark,
|
||||
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 22),
|
||||
]
|
||||
textAttributes.h3Attributes = [
|
||||
NSParagraphStyleAttributeName: headerParaStyle,
|
||||
NSForegroundColorAttributeName: Styles.Colors.Gray.dark,
|
||||
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 20),
|
||||
]
|
||||
textAttributes.h4Attributes = [
|
||||
NSParagraphStyleAttributeName: headerParaStyle,
|
||||
NSForegroundColorAttributeName: Styles.Colors.Gray.dark,
|
||||
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 18),
|
||||
]
|
||||
textAttributes.h5Attributes = [
|
||||
NSParagraphStyleAttributeName: headerParaStyle,
|
||||
NSForegroundColorAttributeName: Styles.Colors.Gray.dark,
|
||||
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 16),
|
||||
]
|
||||
textAttributes.h6Attributes = [
|
||||
NSParagraphStyleAttributeName: headerParaStyle,
|
||||
NSForegroundColorAttributeName: Styles.Colors.Gray.medium,
|
||||
NSFontAttributeName: UIFont.boldSystemFont(ofSize: 16),
|
||||
]
|
||||
|
||||
return markdownString(
|
||||
body: between,
|
||||
width: width,
|
||||
|
||||
Reference in New Issue
Block a user