From bf8a294676285bbbc23986c8193209d69bdab25b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 1 May 2022 23:04:56 -0400 Subject: [PATCH] Split MenuActionProvider from MenuPreviewProvider --- .../AccountListTableViewController.swift | 6 ++++ .../BookmarksTableViewController.swift | 9 ++++++ .../ConversationTableViewController.swift | 3 ++ .../ProfileDirectoryViewController.swift | 6 ++-- .../TrendingHashtagsViewController.swift | 6 ++-- .../Explore/TrendingLinksViewController.swift | 6 ++-- .../TrendingStatusesViewController.swift | 6 ++++ .../EditListAccountsViewController.swift | 6 ++++ .../NotificationsTableViewController.swift | 3 ++ .../Search/SearchResultsViewController.swift | 9 ++++++ ...ActionAccountListTableViewController.swift | 9 ++++++ .../TimelineTableViewController.swift | 3 ++ Tusker/Screens/Utilities/Previewing.swift | 26 +++++++++-------- .../Account Cell/AccountTableViewCell.swift | 6 ++-- Tusker/Views/ContentTextView.swift | 7 +++-- ...ActionNotificationGroupTableViewCell.swift | 4 +-- ...FollowNotificationGroupTableViewCell.swift | 6 ++-- ...llowRequestNotificationTableViewCell.swift | 4 +-- .../PollFinishedTableViewCell.swift | 6 ++-- .../Profile Header/ProfileHeaderView.swift | 8 ++---- .../Status/BaseStatusTableViewCell.swift | 16 ++++------- .../ConversationMainStatusTableViewCell.swift | 2 +- Tusker/Views/Status/StatusCardView.swift | 6 ++-- .../Status/TimelineStatusTableViewCell.swift | 28 ++++++++++--------- 24 files changed, 118 insertions(+), 73 deletions(-) diff --git a/Tusker/Screens/Account List/AccountListTableViewController.swift b/Tusker/Screens/Account List/AccountListTableViewController.swift index 58cecb43..4d9c2ae3 100644 --- a/Tusker/Screens/Account List/AccountListTableViewController.swift +++ b/Tusker/Screens/Account List/AccountListTableViewController.swift @@ -67,3 +67,9 @@ class AccountListTableViewController: EnhancedTableViewController { extension AccountListTableViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } + +extension AccountListTableViewController: ToastableViewController { +} + +extension AccountListTableViewController: MenuActionProvider { +} diff --git a/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift b/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift index c57e2da5..f867eb60 100644 --- a/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift +++ b/Tusker/Screens/Bookmarks/BookmarksTableViewController.swift @@ -153,6 +153,15 @@ class BookmarksTableViewController: EnhancedTableViewController { } +extension BookmarksTableViewController: TuskerNavigationDelegate { +} + +extension BookmarksTableViewController: ToastableViewController { +} + +extension BookmarksTableViewController: MenuActionProvider { +} + extension BookmarksTableViewController: StatusTableViewCellDelegate { var apiController: MastodonController { mastodonController } diff --git a/Tusker/Screens/Conversation/ConversationTableViewController.swift b/Tusker/Screens/Conversation/ConversationTableViewController.swift index 137b1d47..7755837b 100644 --- a/Tusker/Screens/Conversation/ConversationTableViewController.swift +++ b/Tusker/Screens/Conversation/ConversationTableViewController.swift @@ -444,6 +444,9 @@ extension ConversationTableViewController: TuskerNavigationDelegate { } } +extension ConversationTableViewController: MenuActionProvider { +} + extension ConversationTableViewController: StatusTableViewCellDelegate { var apiController: MastodonController { mastodonController } func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell) { diff --git a/Tusker/Screens/Explore/ProfileDirectoryViewController.swift b/Tusker/Screens/Explore/ProfileDirectoryViewController.swift index 2554a78e..50e22ca9 100644 --- a/Tusker/Screens/Explore/ProfileDirectoryViewController.swift +++ b/Tusker/Screens/Explore/ProfileDirectoryViewController.swift @@ -134,8 +134,10 @@ extension ProfileDirectoryViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } -extension ProfileDirectoryViewController: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { self } +extension ProfileDirectoryViewController: ToastableViewController { +} + +extension ProfileDirectoryViewController: MenuActionProvider { } extension ProfileDirectoryViewController: UICollectionViewDelegate { diff --git a/Tusker/Screens/Explore/TrendingHashtagsViewController.swift b/Tusker/Screens/Explore/TrendingHashtagsViewController.swift index 7f5bdfa2..4b14d364 100644 --- a/Tusker/Screens/Explore/TrendingHashtagsViewController.swift +++ b/Tusker/Screens/Explore/TrendingHashtagsViewController.swift @@ -110,6 +110,8 @@ extension TrendingHashtagsViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } -extension TrendingHashtagsViewController: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { self } +extension TrendingHashtagsViewController: ToastableViewController { +} + +extension TrendingHashtagsViewController: MenuActionProvider { } diff --git a/Tusker/Screens/Explore/TrendingLinksViewController.swift b/Tusker/Screens/Explore/TrendingLinksViewController.swift index 3a0fac59..a1e4eb24 100644 --- a/Tusker/Screens/Explore/TrendingLinksViewController.swift +++ b/Tusker/Screens/Explore/TrendingLinksViewController.swift @@ -104,6 +104,8 @@ extension TrendingLinksViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } -extension TrendingLinksViewController: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { self } +extension TrendingLinksViewController: ToastableViewController { +} + +extension TrendingLinksViewController: MenuActionProvider { } diff --git a/Tusker/Screens/Explore/TrendingStatusesViewController.swift b/Tusker/Screens/Explore/TrendingStatusesViewController.swift index a16c4619..a290381e 100644 --- a/Tusker/Screens/Explore/TrendingStatusesViewController.swift +++ b/Tusker/Screens/Explore/TrendingStatusesViewController.swift @@ -85,6 +85,12 @@ extension TrendingStatusesViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } +extension TrendingStatusesViewController: ToastableViewController { +} + +extension TrendingStatusesViewController: MenuActionProvider { +} + extension TrendingStatusesViewController: StatusTableViewCellDelegate { func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell) { tableView.beginUpdates() diff --git a/Tusker/Screens/Lists/EditListAccountsViewController.swift b/Tusker/Screens/Lists/EditListAccountsViewController.swift index d5a03be4..df670458 100644 --- a/Tusker/Screens/Lists/EditListAccountsViewController.swift +++ b/Tusker/Screens/Lists/EditListAccountsViewController.swift @@ -176,3 +176,9 @@ extension EditListAccountsViewController: SearchResultsViewControllerDelegate { extension EditListAccountsViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } + +extension EditListAccountsViewController: ToastableViewController { +} + +extension EditListAccountsViewController: MenuActionProvider { +} diff --git a/Tusker/Screens/Notifications/NotificationsTableViewController.swift b/Tusker/Screens/Notifications/NotificationsTableViewController.swift index ff695344..6e32353e 100644 --- a/Tusker/Screens/Notifications/NotificationsTableViewController.swift +++ b/Tusker/Screens/Notifications/NotificationsTableViewController.swift @@ -250,6 +250,9 @@ extension NotificationsTableViewController: TuskerNavigationDelegate { var apiController: MastodonController { mastodonController } } +extension NotificationsTableViewController: MenuActionProvider { +} + extension NotificationsTableViewController: StatusTableViewCellDelegate { func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell) { cellHeightChanged() diff --git a/Tusker/Screens/Search/SearchResultsViewController.swift b/Tusker/Screens/Search/SearchResultsViewController.swift index 01d551bb..195d50cd 100644 --- a/Tusker/Screens/Search/SearchResultsViewController.swift +++ b/Tusker/Screens/Search/SearchResultsViewController.swift @@ -288,6 +288,15 @@ extension SearchResultsViewController: UISearchBarDelegate { } } +extension SearchResultsViewController: TuskerNavigationDelegate { +} + +extension SearchResultsViewController: ToastableViewController { +} + +extension SearchResultsViewController: MenuActionProvider { +} + extension SearchResultsViewController: StatusTableViewCellDelegate { var apiController: MastodonController { mastodonController } func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell) { diff --git a/Tusker/Screens/Status Action Account List/StatusActionAccountListTableViewController.swift b/Tusker/Screens/Status Action Account List/StatusActionAccountListTableViewController.swift index 45d3b15d..c491517f 100644 --- a/Tusker/Screens/Status Action Account List/StatusActionAccountListTableViewController.swift +++ b/Tusker/Screens/Status Action Account List/StatusActionAccountListTableViewController.swift @@ -144,6 +144,15 @@ class StatusActionAccountListTableViewController: EnhancedTableViewController { } +extension StatusActionAccountListTableViewController: TuskerNavigationDelegate { +} + +extension StatusActionAccountListTableViewController: ToastableViewController { +} + +extension StatusActionAccountListTableViewController: MenuActionProvider { +} + extension StatusActionAccountListTableViewController: StatusTableViewCellDelegate { var apiController: MastodonController { mastodonController } func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell) { diff --git a/Tusker/Screens/Timeline/TimelineTableViewController.swift b/Tusker/Screens/Timeline/TimelineTableViewController.swift index ba991da6..f8dc9632 100644 --- a/Tusker/Screens/Timeline/TimelineTableViewController.swift +++ b/Tusker/Screens/Timeline/TimelineTableViewController.swift @@ -294,6 +294,9 @@ extension TimelineTableViewController: StatusTableViewCellDelegate { } } +extension TimelineTableViewController: MenuActionProvider { +} + extension TimelineTableViewController: UITableViewDataSourcePrefetching, StatusTablePrefetching { func tableView(_ tableView: UITableView, prefetchRowsAt indexPaths: [IndexPath]) { let ids: [String] = indexPaths.compactMap { diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index 76b034da..936a8599 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -10,29 +10,33 @@ import UIKit import SafariServices import Pachyderm +protocol MenuActionProvider: AnyObject { + var navigationDelegate: TuskerNavigationDelegate? { get } + var toastableViewController: ToastableViewController? { get } +} + protocol MenuPreviewProvider: AnyObject { - typealias PreviewProviders = (content: UIContextMenuContentPreviewProvider, actions: () -> [UIMenuElement]) - var navigationDelegate: TuskerNavigationDelegate? { get } - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? - } protocol CustomPreviewPresenting { func presentFromPreview(presenter: UIViewController) } -extension MenuPreviewProvider { +extension MenuActionProvider where Self: TuskerNavigationDelegate { + var navigationDelegate: TuskerNavigationDelegate? { self } +} + +extension MenuActionProvider where Self: ToastableViewController { + var toastableViewController: ToastableViewController? { self } +} + +extension MenuActionProvider { private var mastodonController: MastodonController? { navigationDelegate?.apiController } - // Default no-op implementation - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { - return nil - } - func actionsForProfile(accountID: String, sourceView: UIView?) -> [UIMenuElement] { guard let mastodonController = mastodonController, let account = mastodonController.persistentContainer.account(for: accountID) else { return [] } @@ -84,7 +88,7 @@ extension MenuPreviewProvider { func actionsForURL(_ url: URL, sourceView: UIView?) -> [UIAction] { return [ - openInSafariAction(url: url), + openInSafariAction(url: url), createAction(identifier: "share", title: "Share", systemImageName: "square.and.arrow.up", handler: { [weak self, weak sourceView] (_) in guard let self = self else { return } self.navigationDelegate?.showMoreOptions(forURL: url, sourceView: sourceView) diff --git a/Tusker/Views/Account Cell/AccountTableViewCell.swift b/Tusker/Views/Account Cell/AccountTableViewCell.swift index 03f1cbd0..0271d710 100644 --- a/Tusker/Views/Account Cell/AccountTableViewCell.swift +++ b/Tusker/Views/Account Cell/AccountTableViewCell.swift @@ -11,7 +11,7 @@ import SwiftSoup class AccountTableViewCell: UITableViewCell { - weak var delegate: TuskerNavigationDelegate? + weak var delegate: (TuskerNavigationDelegate & MenuActionProvider)? var mastodonController: MastodonController! { delegate?.apiController } @IBOutlet weak var avatarImageView: UIImageView! @@ -98,13 +98,11 @@ extension AccountTableViewCell: SelectableTableViewCell { } extension AccountTableViewCell: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { return delegate } - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { guard let mastodonController = mastodonController else { return nil } return ( content: { ProfileViewController(accountID: self.accountID, mastodonController: mastodonController) }, - actions: { self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) } + actions: { self.delegate?.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) ?? [] } ) } } diff --git a/Tusker/Views/ContentTextView.swift b/Tusker/Views/ContentTextView.swift index 2019f08e..77e2fd7d 100644 --- a/Tusker/Views/ContentTextView.swift +++ b/Tusker/Views/ContentTextView.swift @@ -243,9 +243,10 @@ extension ContentTextView: UITextViewDelegate { } } -extension ContentTextView: MenuPreviewProvider { - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { - fatalError("unimplemented") +extension ContentTextView: MenuActionProvider { + var toastableViewController: ToastableViewController? { + // todo: pass this down through the text view + nil } } diff --git a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift index e139823e..a7695d9e 100644 --- a/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/ActionNotificationGroupTableViewCell.swift @@ -12,7 +12,7 @@ import SwiftSoup class ActionNotificationGroupTableViewCell: UITableViewCell { - weak var delegate: TuskerNavigationDelegate? + weak var delegate: (TuskerNavigationDelegate & MenuActionProvider)? var mastodonController: MastodonController! { delegate?.apiController } @IBOutlet weak var actionImageView: UIImageView! @@ -244,8 +244,6 @@ extension ActionNotificationGroupTableViewCell: SelectableTableViewCell { } extension ActionNotificationGroupTableViewCell: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { return delegate } - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { return (content: { let notifications = self.group.notifications diff --git a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift index 75fe33a7..446e3995 100644 --- a/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift +++ b/Tusker/Views/Notifications/FollowNotificationGroupTableViewCell.swift @@ -11,7 +11,7 @@ import Pachyderm class FollowNotificationGroupTableViewCell: UITableViewCell { - weak var delegate: TuskerNavigationDelegate? + weak var delegate: (TuskerNavigationDelegate & MenuActionProvider)? var mastodonController: MastodonController! { delegate?.apiController } @IBOutlet weak var avatarStackView: UIStackView! @@ -196,8 +196,6 @@ extension FollowNotificationGroupTableViewCell: SelectableTableViewCell { } extension FollowNotificationGroupTableViewCell: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { return delegate } - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { guard let mastodonController = mastodonController else { return nil } let accountIDs = self.group.notifications.map { $0.account.id } @@ -209,7 +207,7 @@ extension FollowNotificationGroupTableViewCell: MenuPreviewProvider { } }, actions: { if accountIDs.count == 1 { - return self.actionsForProfile(accountID: accountIDs.first!, sourceView: self) + return self.delegate?.actionsForProfile(accountID: accountIDs.first!, sourceView: self) ?? [] } else { return [] } diff --git a/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift b/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift index d81f07b7..eaf24cdd 100644 --- a/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift +++ b/Tusker/Views/Notifications/FollowRequestNotificationTableViewCell.swift @@ -11,7 +11,7 @@ import Pachyderm class FollowRequestNotificationTableViewCell: UITableViewCell { - weak var delegate: TuskerNavigationDelegate? + weak var delegate: (TuskerNavigationDelegate & MenuActionProvider)? var mastodonController: MastodonController! { delegate?.apiController } @IBOutlet weak var stackView: UIStackView! @@ -169,8 +169,6 @@ extension FollowRequestNotificationTableViewCell: SelectableTableViewCell { } extension FollowRequestNotificationTableViewCell: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { return delegate } - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { guard let mastodonController = mastodonController else { return nil } return (content: { diff --git a/Tusker/Views/Notifications/PollFinishedTableViewCell.swift b/Tusker/Views/Notifications/PollFinishedTableViewCell.swift index e3c78ab5..b1b5bf6b 100644 --- a/Tusker/Views/Notifications/PollFinishedTableViewCell.swift +++ b/Tusker/Views/Notifications/PollFinishedTableViewCell.swift @@ -12,7 +12,7 @@ import SwiftSoup class PollFinishedTableViewCell: UITableViewCell { - weak var delegate: TuskerNavigationDelegate? + weak var delegate: (TuskerNavigationDelegate & MenuActionProvider)? var mastodonController: MastodonController? { delegate?.apiController } @IBOutlet weak var displayNameLabel: EmojiLabel! @@ -91,8 +91,6 @@ extension PollFinishedTableViewCell: SelectableTableViewCell { } extension PollFinishedTableViewCell: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { delegate } - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { guard let delegate = delegate, let statusID = notification?.status?.id, @@ -102,7 +100,7 @@ extension PollFinishedTableViewCell: MenuPreviewProvider { return (content: { delegate.conversation(mainStatusID: statusID, state: .unknown) }, actions: { - self.actionsForStatus(status, sourceView: self) + delegate.actionsForStatus(status, sourceView: self) }) } } diff --git a/Tusker/Views/Profile Header/ProfileHeaderView.swift b/Tusker/Views/Profile Header/ProfileHeaderView.swift index dbda8d9d..3742e6f3 100644 --- a/Tusker/Views/Profile Header/ProfileHeaderView.swift +++ b/Tusker/Views/Profile Header/ProfileHeaderView.swift @@ -10,7 +10,7 @@ import UIKit import Pachyderm import Combine -protocol ProfileHeaderViewDelegate: TuskerNavigationDelegate { +protocol ProfileHeaderViewDelegate: TuskerNavigationDelegate, MenuActionProvider { func profileHeader(_ headerView: ProfileHeaderView, selectedPostsIndexChangedTo newIndex: Int) } @@ -106,7 +106,7 @@ class ProfileHeaderView: UIView { updateImages(account: account) - moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: actionsForProfile(accountID: accountID, sourceView: moreButton)) + moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForProfile(accountID: accountID, sourceView: moreButton) ?? []) noteTextView.navigationDelegate = delegate noteTextView.setTextFromHtml(account.note) @@ -272,7 +272,3 @@ extension ProfileHeaderView: UIPointerInteractionDelegate { return UIPointerStyle(effect: .lift(preview), shape: .none) } } - -extension ProfileHeaderView: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { delegate } -} diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index ffde2777..5a8d8ce4 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -11,11 +11,11 @@ import Pachyderm import Combine import AVKit -protocol StatusTableViewCellDelegate: TuskerNavigationDelegate { +protocol StatusTableViewCellDelegate: TuskerNavigationDelegate, MenuActionProvider { func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell) } -class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { +class BaseStatusTableViewCell: UITableViewCell { weak var delegate: StatusTableViewCellDelegate? { didSet { @@ -153,7 +153,8 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { cardView.card = status.card cardView.isHidden = status.card == nil - cardView.navigationDelegate = navigationDelegate + cardView.navigationDelegate = delegate + cardView.actionProvider = delegate attachmentsView.updateUI(status: status) @@ -206,7 +207,7 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { // keep menu in sync with changed states e.g. bookmarked, muted // do not include reply action here, because the cell already contains a button for it - moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: actionsForStatus(status, sourceView: moreButton, includeReply: false)) + moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForStatus(status, sourceView: moreButton, includeReply: false) ?? []) pollView.isHidden = status.poll == nil pollView.mastodonController = mastodonController @@ -326,13 +327,6 @@ class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { showStatusAutomatically = false } - // MARK: - MenuPreviewProvider - var navigationDelegate: TuskerNavigationDelegate? { return delegate } - - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { - return nil - } - // MARK: - Interaction @IBAction func collapseButtonPressed() { diff --git a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift index fabc01ba..e861e721 100644 --- a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift +++ b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift @@ -112,7 +112,7 @@ extension ConversationMainStatusTableViewCell: UIContextMenuInteractionDelegate return UIContextMenuConfiguration(identifier: nil) { ProfileViewController(accountID: self.accountID, mastodonController: self.mastodonController) } actionProvider: { (_) in - return UIMenu(title: "", image: nil, identifier: nil, options: [], children: self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView)) + return UIMenu(title: "", image: nil, identifier: nil, options: [], children: self.delegate?.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) ?? []) } } } diff --git a/Tusker/Views/Status/StatusCardView.swift b/Tusker/Views/Status/StatusCardView.swift index d97f722c..84cc1775 100644 --- a/Tusker/Views/Status/StatusCardView.swift +++ b/Tusker/Views/Status/StatusCardView.swift @@ -14,6 +14,7 @@ import WebURLFoundationExtras class StatusCardView: UIView { weak var navigationDelegate: TuskerNavigationDelegate? + weak var actionProvider: MenuActionProvider? var card: Card? { didSet { @@ -212,9 +213,6 @@ class StatusCardView: UIView { } -extension StatusCardView: MenuPreviewProvider { -} - extension StatusCardView: UIContextMenuInteractionDelegate { func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { guard let card = card else { return nil } @@ -222,7 +220,7 @@ extension StatusCardView: UIContextMenuInteractionDelegate { return UIContextMenuConfiguration(identifier: nil) { return SFSafariViewController(url: URL(card.url)!) } actionProvider: { (_) in - let actions = self.actionsForURL(URL(card.url)!, sourceView: self) + let actions = self.actionProvider?.actionsForURL(URL(card.url)!, sourceView: self) ?? [] return UIMenu(title: "", image: nil, identifier: nil, options: [], children: actions) } } diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 9718cc2b..ae8a1af6 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -214,17 +214,6 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { reply() } - override func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> BaseStatusTableViewCell.PreviewProviders? { - guard let mastodonController = mastodonController, - let status = mastodonController.persistentContainer.status(for: statusID) else { - return nil - } - return ( - content: { ConversationTableViewController(for: self.statusID, state: self.statusState.copy(), mastodonController: mastodonController) }, - actions: { self.actionsForStatus(status, sourceView: self) } - ) - } - // MARK: - Accessibility override var accessibilityLabel: String? { @@ -377,13 +366,13 @@ extension TimelineStatusTableViewCell: UIContextMenuInteractionDelegate { return UIContextMenuConfiguration(identifier: nil) { ProfileViewController(accountID: self.accountID, mastodonController: self.mastodonController) } actionProvider: { (_) in - return UIMenu(title: "", image: nil, identifier: nil, options: [], children: self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView)) + return UIMenu(title: "", image: nil, identifier: nil, options: [], children: self.delegate?.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) ?? []) } } func contextMenuInteraction(_ interaction: UIContextMenuInteraction, willPerformPreviewActionForMenuWith configuration: UIContextMenuConfiguration, animator: UIContextMenuInteractionCommitAnimating) { if let viewController = animator.previewViewController, - let delegate = navigationDelegate { + let delegate = delegate { animator.preferredCommitStyle = .pop animator.addCompletion { if let customPresenting = viewController as? CustomPreviewPresenting { @@ -396,3 +385,16 @@ extension TimelineStatusTableViewCell: UIContextMenuInteractionDelegate { } } + +extension TimelineStatusTableViewCell: MenuPreviewProvider { + func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { + guard let mastodonController = mastodonController, + let status = mastodonController.persistentContainer.status(for: statusID) else { + return nil + } + return ( + content: { ConversationTableViewController(for: self.statusID, state: self.statusState.copy(), mastodonController: mastodonController) }, + actions: { self.delegate?.actionsForStatus(status, sourceView: self) ?? [] } + ) + } +}