View raw markdown on comments (#1819)

This commit is contained in:
Ryan Nystrom
2018-05-19 19:07:52 -04:00
committed by GitHub
parent 1beccb9508
commit 8642d03a51
3 changed files with 87 additions and 6 deletions

View File

@@ -95,7 +95,7 @@ final class IssueCommentSectionController:
.share([url], activities: [TUSafariActivity()]) { $0.popoverPresentationController?.sourceView = sender }
}
func deleteAction() -> UIAlertAction? {
var deleteAction: UIAlertAction? {
guard object?.viewerCanDelete == true else { return nil }
return AlertAction.delete { [weak self] _ in
@@ -114,7 +114,7 @@ final class IssueCommentSectionController:
}
}
func editAction() -> UIAlertAction? {
var editAction: UIAlertAction? {
guard object?.viewerCanUpdate == true else { return nil }
return UIAlertAction(title: NSLocalizedString("Edit", comment: ""), style: .default, handler: { [weak self] _ in
guard let strongSelf = self,
@@ -138,7 +138,7 @@ final class IssueCommentSectionController:
})
}
func replyAction() -> UIAlertAction? {
var replyAction: UIAlertAction? {
return UIAlertAction(
title: NSLocalizedString("Reply", comment: ""),
style: .default,
@@ -155,6 +155,23 @@ final class IssueCommentSectionController:
)
}
var viewMarkdownAction: UIAlertAction? {
return UIAlertAction(
title: NSLocalizedString("View Markdown", comment: ""),
style: .default,
handler: { [weak self] _ in
guard let markdown = self?.object?.rawMarkdown else { return }
let nav = UINavigationController(
rootViewController: ViewMarkdownViewController(markdown: markdown)
)
self?.viewController?.present(
nav,
animated: trueUnlessReduceMotionEnabled
)
}
)
}
private func clearCollapseCells() {
// clear any collapse state before updating so we don't have a dangling overlay
for cell in collectionContext?.visibleCells(for: self) ?? [] {
@@ -451,9 +468,10 @@ final class IssueCommentSectionController:
alert.popoverPresentationController?.sourceView = sender
alert.addActions([
shareAction(sender: sender),
editAction(),
replyAction(),
deleteAction(),
viewMarkdownAction,
editAction,
replyAction,
deleteAction,
AlertAction.cancel()
])
viewController?.present(alert, animated: trueUnlessReduceMotionEnabled)

View File

@@ -0,0 +1,59 @@
//
// ViewMarkdownViewController.swift
// Freetime
//
// Created by Ryan Nystrom on 5/19/18.
// Copyright © 2018 Ryan Nystrom. All rights reserved.
//
import UIKit
final class ViewMarkdownViewController: UIViewController {
private let markdown: String
private let textView = UITextView()
init(markdown: String) {
self.markdown = markdown
super.init(nibName: nil, bundle: nil)
title = NSLocalizedString("Markdown", comment: "")
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(
barButtonSystemItem: .done,
target: self,
action: #selector(onDismiss)
)
textView.isEditable = false
textView.text = markdown
textView.font = Styles.Text.code.preferredFont
textView.textColor = Styles.Colors.Gray.dark.color
textView.textContainerInset = UIEdgeInsets(
top: Styles.Sizes.rowSpacing,
left: Styles.Sizes.rowSpacing,
bottom: Styles.Sizes.rowSpacing,
right: Styles.Sizes.rowSpacing
)
view.addSubview(textView)
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
textView.frame = view.bounds
}
// MARK: Private API
@objc func onDismiss() {
dismiss(animated: trueUnlessReduceMotionEnabled)
}
}

View File

@@ -217,6 +217,7 @@
2974069D1F0EDEAD003A6BFB /* IssueCommentTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2974069C1F0EDEAD003A6BFB /* IssueCommentTableCell.swift */; };
2974069F1F0EDED3003A6BFB /* IssueCommentTableCollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2974069E1F0EDED3003A6BFB /* IssueCommentTableCollectionCell.swift */; };
29764C141FDC4DB60095FF95 /* SettingsLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29764C131FDC4DB60095FF95 /* SettingsLabel.swift */; };
2977788820B0DAD500F2AFC2 /* ViewMarkdownViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2977788720B0DAD500F2AFC2 /* ViewMarkdownViewController.swift */; };
29792B191FFB10A3007A0C57 /* UIViewController+MessageAutocompleteControllerLayoutDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29792B181FFB10A3007A0C57 /* UIViewController+MessageAutocompleteControllerLayoutDelegate.swift */; };
29792B1B1FFB21AD007A0C57 /* AutocompleteController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29792B1A1FFB21AD007A0C57 /* AutocompleteController.swift */; };
29792B1D1FFB2FC6007A0C57 /* IssueManagingNavSectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 29792B1C1FFB2FC6007A0C57 /* IssueManagingNavSectionController.swift */; };
@@ -713,6 +714,7 @@
2974069C1F0EDEAD003A6BFB /* IssueCommentTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueCommentTableCell.swift; sourceTree = "<group>"; };
2974069E1F0EDED3003A6BFB /* IssueCommentTableCollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueCommentTableCollectionCell.swift; sourceTree = "<group>"; };
29764C131FDC4DB60095FF95 /* SettingsLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsLabel.swift; sourceTree = "<group>"; };
2977788720B0DAD500F2AFC2 /* ViewMarkdownViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewMarkdownViewController.swift; sourceTree = "<group>"; };
29792B181FFB10A3007A0C57 /* UIViewController+MessageAutocompleteControllerLayoutDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+MessageAutocompleteControllerLayoutDelegate.swift"; sourceTree = "<group>"; };
29792B1A1FFB21AD007A0C57 /* AutocompleteController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutocompleteController.swift; sourceTree = "<group>"; };
29792B1C1FFB2FC6007A0C57 /* IssueManagingNavSectionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IssueManagingNavSectionController.swift; sourceTree = "<group>"; };
@@ -1410,6 +1412,7 @@
2965F36F2071508C003CC92F /* StyledTextBuilder+Checkbox.swift */,
2965F37120715161003CC92F /* StyledTextBuilder+NewBase.swift */,
29921BCB1EF624D400C1E848 /* UIFont+MutableTraits.swift */,
2977788720B0DAD500F2AFC2 /* ViewMarkdownViewController.swift */,
);
path = Markdown;
sourceTree = "<group>";
@@ -3036,6 +3039,7 @@
298BA08F1EC90FEE00B01946 /* UIView+BottomBorder.swift in Sources */,
297AE87F1EC0D5C200B44A1F /* UIViewController+Alerts.swift in Sources */,
D8D876FA1FB6084F00A57E2B /* UIBarButtonItem+TightSpacing.swift in Sources */,
2977788820B0DAD500F2AFC2 /* ViewMarkdownViewController.swift in Sources */,
29CEA5CF1F84DCB3009827DB /* UIViewController+EmptyBackBar.swift in Sources */,
292CD3D81F0DC52900D3D57B /* UIViewController+IssueCommentHtmlCellNavigationDelegate.swift in Sources */,
297AE8801EC0D5C200B44A1F /* UIViewController+LoadingIndicator.swift in Sources */,