Render descriptions with shared Markdown preview
Use one Markdown presentation for free-form content. - issue and pull-request descriptions and comments - milestone and commit descriptions
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import Highlighter
|
||||
import MarkdownUI
|
||||
import QuickLook
|
||||
import SwiftUI
|
||||
import UIKit
|
||||
@@ -402,7 +401,7 @@ private final class FileListView: UITableView, UITableViewDataSource, UITableVie
|
||||
private final class CommitHeaderView: UIView {
|
||||
private let stack = UIStackView()
|
||||
private let titleLabel = UILabel()
|
||||
private let descriptionLabel = UILabel()
|
||||
private var descriptionView: UIView?
|
||||
private let metadataStack = UIStackView()
|
||||
|
||||
override init(frame: CGRect) {
|
||||
@@ -414,9 +413,6 @@ private final class CommitHeaderView: UIView {
|
||||
titleLabel.adjustsFontForContentSizeCategory = true
|
||||
titleLabel.numberOfLines = 0
|
||||
titleLabel.accessibilityTraits = .header
|
||||
descriptionLabel.font = .preferredFont(forTextStyle: .body)
|
||||
descriptionLabel.adjustsFontForContentSizeCategory = true
|
||||
descriptionLabel.numberOfLines = 0
|
||||
|
||||
metadataStack.axis = .vertical
|
||||
metadataStack.spacing = 10
|
||||
@@ -424,7 +420,6 @@ private final class CommitHeaderView: UIView {
|
||||
stack.spacing = 12
|
||||
stack.translatesAutoresizingMaskIntoConstraints = false
|
||||
stack.addArrangedSubview(titleLabel)
|
||||
stack.addArrangedSubview(descriptionLabel)
|
||||
stack.addArrangedSubview(metadataStack)
|
||||
addSubview(stack)
|
||||
NSLayoutConstraint.activate([
|
||||
@@ -440,8 +435,12 @@ private final class CommitHeaderView: UIView {
|
||||
|
||||
func configure(_ page: CommitDetailsPage) {
|
||||
titleLabel.text = page.title
|
||||
descriptionLabel.text = page.description
|
||||
descriptionLabel.isHidden = page.description.isEmpty
|
||||
descriptionView?.removeFromSuperview()
|
||||
if !page.description.isEmpty {
|
||||
let view = markdownView(page.description)
|
||||
stack.insertArrangedSubview(view, at: 1)
|
||||
descriptionView = view
|
||||
}
|
||||
metadataStack.arrangedSubviews.forEach { $0.removeFromSuperview() }
|
||||
for metadata in page.metadata {
|
||||
let isCommit = metadata.label == "Commit"
|
||||
@@ -1132,9 +1131,7 @@ struct RepositoryMarkdownPreview: View {
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
Markdown(source)
|
||||
.markdownTheme(.gitHub)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
MarkdownContent(source: source)
|
||||
.padding()
|
||||
}
|
||||
.background(Color(uiColor: .systemBackground))
|
||||
@@ -1235,6 +1232,7 @@ final class DiffViewController: UIViewController {
|
||||
}
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func detailViews(
|
||||
title: String,
|
||||
state: String? = nil,
|
||||
@@ -1285,6 +1283,7 @@ private func stateTitle(_ titleLabel: UILabel, state: String, subject: String) -
|
||||
return stack
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private func commentViews(
|
||||
_ comments: [CommentRow],
|
||||
editComment: ((CommentRow) -> Void)? = nil
|
||||
@@ -1323,19 +1322,6 @@ private func commentViews(
|
||||
return views
|
||||
}
|
||||
|
||||
private func markdownView(_ source: String) -> UITextView {
|
||||
let view = UITextView()
|
||||
view.attributedText = markdown(source)
|
||||
view.isEditable = false
|
||||
view.isSelectable = true
|
||||
view.isScrollEnabled = false
|
||||
view.backgroundColor = .clear
|
||||
view.textContainerInset = .zero
|
||||
view.textContainer.lineFragmentPadding = 0
|
||||
view.adjustsFontForContentSizeCategory = true
|
||||
return view
|
||||
}
|
||||
|
||||
private func sectionLabel(_ text: String) -> UILabel {
|
||||
let label = UILabel()
|
||||
label.text = text
|
||||
|
||||
Reference in New Issue
Block a user