From 36230d930eb933c1b5e8914d3ba1dc5f6eb399e7 Mon Sep 17 00:00:00 2001 From: Mihael Cholakov Date: Mon, 6 Jan 2020 14:52:18 +0200 Subject: [PATCH] Context menu now previews selected article --- .../MasterTimelineViewController.swift | 71 ++++++++++--------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/iOS/MasterTimeline/MasterTimelineViewController.swift b/iOS/MasterTimeline/MasterTimelineViewController.swift index f6584928c..b5b7baba2 100644 --- a/iOS/MasterTimeline/MasterTimelineViewController.swift +++ b/iOS/MasterTimeline/MasterTimelineViewController.swift @@ -18,6 +18,7 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner private lazy var feedTapGestureRecognizer = UITapGestureRecognizer(target: self, action:#selector(showFeedInspector(_:))) private var refreshProgressView: RefreshProgressView? + private var currentlyPreviewedArticle: Article? @IBOutlet weak var filterButton: UIBarButtonItem! @IBOutlet weak var markAllAsReadButton: UIBarButtonItem! @@ -305,41 +306,36 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner guard let article = dataSource.itemIdentifier(for: indexPath) else { return nil } - return UIContextMenuConfiguration(identifier: indexPath.row as NSCopying, previewProvider: nil, actionProvider: { [weak self] suggestedActions in - - guard let self = self else { return nil } - - var actions = [UIAction]() - actions.append(self.toggleArticleReadStatusAction(article)) - actions.append(self.toggleArticleStarStatusAction(article)) - - if let action = self.markAboveAsReadAction(article) { - actions.append(action) + currentlyPreviewedArticle = article + + return UIContextMenuConfiguration( + identifier: indexPath.row as NSCopying, + previewProvider: { [weak self] in + + guard let self = self else { return nil } + + let articleViewController = UIStoryboard.main.instantiateController(ofType: ArticleViewController.self) + articleViewController.coordinator = self.coordinator + articleViewController.article = article + return articleViewController + + }, actionProvider: { [weak self] suggestedActions in + + guard let self = self else { return nil } + + return UIMenu(title: "", children: [ + self.toggleArticleReadStatusAction(article), + self.toggleArticleStarStatusAction(article), + self.markAboveAsReadAction(article), + self.markBelowAsReadAction(article), + self.discloseFeedAction(article), + self.markAllInFeedAsReadAction(article), + self.openInBrowserAction(article), + self.shareAction(article, indexPath: indexPath) + ].compactMap { $0 }) + } - - if let action = self.markBelowAsReadAction(article) { - actions.append(action) - } - - if let action = self.discloseFeedAction(article) { - actions.append(action) - } - - if let action = self.markAllInFeedAsReadAction(article) { - actions.append(action) - } - - if let action = self.openInBrowserAction(article) { - actions.append(action) - } - - if let action = self.shareAction(article, indexPath: indexPath) { - actions.append(action) - } - - return UIMenu(title: "", children: actions) - - }) + ) } @@ -351,6 +347,13 @@ class MasterTimelineViewController: UITableViewController, UndoableCommandRunner return UITargetedPreview(view: cell, parameters: CroppingPreviewParameters(view: cell)) } + + override func tableView(_ tableView: UITableView, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { + if let article = currentlyPreviewedArticle { + coordinator.selectArticle(article) + currentlyPreviewedArticle = nil + } + } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { becomeFirstResponder()