code is rendered, not label

This commit is contained in:
Ryan Nystrom
2017-06-26 21:43:57 -07:00
parent df3763434e
commit f6a37cafc7
4 changed files with 10 additions and 9 deletions

View File

@@ -24,7 +24,7 @@ final class IssueCommentCodeBlockCell: UICollectionViewCell, ListBindable, Colla
right: Styles.Sizes.gutter
)
let label = UILabel()
let textView = AttributedStringView()
let scrollView = UIScrollView()
let overlay = CreateCollapsibleOverlay()
@@ -42,8 +42,7 @@ final class IssueCommentCodeBlockCell: UICollectionViewCell, ListBindable, Colla
scrollView.backgroundColor = Styles.Colors.Gray.lighter.color
contentView.addSubview(scrollView)
label.numberOfLines = 0
scrollView.addSubview(label)
scrollView.addSubview(textView)
}
required init?(coder aDecoder: NSCoder) {
@@ -72,9 +71,7 @@ final class IssueCommentCodeBlockCell: UICollectionViewCell, ListBindable, Colla
let contentSize = viewModel.contentSize
scrollView.contentSize = contentSize
label.attributedText = viewModel.code.attributedText
let textFrame = CGRect(x: 0, y: 0, width: contentSize.width, height: contentSize.height)
label.frame = UIEdgeInsetsInsetRect(textFrame, IssueCommentCodeBlockCell.textViewInset)
textView.configureAndSizeToFit(text: viewModel.code, width: 0)
}
// MARK: CollapsibleCell

View File

@@ -31,7 +31,8 @@ extension MMElement {
let stringSizing = NSAttributedStringSizing(
containerWidth: 0,
attributedText: NSAttributedString(string: text, attributes: attributes),
inset: inset
inset: inset,
backgroundColor: Styles.Colors.Gray.lighter.color
)
return IssueCommentCodeBlockModel(
code: stringSizing,

View File

@@ -36,11 +36,13 @@ final class NSAttributedStringSizing: NSObject, ListDiffable {
let inset: UIEdgeInsets
let attributedText: NSAttributedString
let screenScale: CGFloat
let backgroundColor: UIColor
init(
containerWidth: CGFloat,
attributedText: NSAttributedString,
inset: UIEdgeInsets = .zero,
backgroundColor: UIColor = .white,
exclusionPaths: [UIBezierPath] = [],
maximumNumberOfLines: Int = 0,
lineFragmentPadding: CGFloat = 0.0,
@@ -54,6 +56,7 @@ final class NSAttributedStringSizing: NSObject, ListDiffable {
self.attributedText = attributedText
self.inset = inset
self.screenScale = screenScale
self.backgroundColor = backgroundColor
textContainer = NSTextContainer()
textContainer.exclusionPaths = exclusionPaths
@@ -129,7 +132,7 @@ final class NSAttributedStringSizing: NSObject, ListDiffable {
let size = textSize(width)
UIGraphicsBeginImageContextWithOptions(size, true, screenScale)
UIColor.white.setFill()
backgroundColor.setFill()
UIBezierPath(rect: CGRect(origin: .zero, size: size)).fill()
let glyphRange = layoutManager.glyphRange(for: textContainer)
layoutManager.drawBackground(forGlyphRange: glyphRange, at: .zero)

View File

@@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0.0</string>
<key>CFBundleVersion</key>
<string>89</string>
<string>92</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>org-appextension-feature-password-management</string>