From 4dd510f3afc9be2680d6b4b062e88298004fd7ff Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 28 Apr 2021 19:11:41 -0400 Subject: [PATCH] Only attach profile context menu interaction to correct views in statuses --- .../Status/BaseStatusTableViewCell.swift | 30 +++++++------------ .../ConversationMainStatusTableViewCell.swift | 12 ++++++++ .../Status/TimelineStatusTableViewCell.swift | 14 ++++++++- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 4f26ebd4..ba84e786 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -15,7 +15,7 @@ protocol StatusTableViewCellDelegate: TuskerNavigationDelegate { func statusCellCollapsedStateChanged(_ cell: BaseStatusTableViewCell) } -class BaseStatusTableViewCell: UITableViewCell { +class BaseStatusTableViewCell: UITableViewCell, MenuPreviewProvider { weak var delegate: StatusTableViewCellDelegate? { didSet { @@ -338,6 +338,15 @@ class BaseStatusTableViewCell: UITableViewCell { attachmentsView.attachmentViews.allObjects.forEach { $0.removeFromSuperview() } showStatusAutomatically = false } + + // MARK: - MenuPreviewProvider + var navigationDelegate: TuskerNavigationDelegate? { return delegate } + + func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { + return nil + } + + // MARK: - Interaction @IBAction func collapseButtonPressed() { setCollapsed(!collapsed, animated: true) @@ -457,10 +466,6 @@ class BaseStatusTableViewCell: UITableViewCell { @objc func accountPressed() { delegate?.selected(account: accountID) } - - func getStatusCellPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { - return nil - } } extension BaseStatusTableViewCell: AttachmentViewDelegate { @@ -535,21 +540,6 @@ extension BaseStatusTableViewCell: AVPlayerViewControllerDelegate { } } -extension BaseStatusTableViewCell: MenuPreviewProvider { - var navigationDelegate: TuskerNavigationDelegate? { return delegate } - - func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> PreviewProviders? { - guard let mastodonController = mastodonController else { return nil } - if avatarImageView.frame.contains(location) { - return ( - content: { ProfileViewController(accountID: self.accountID, mastodonController: mastodonController) }, - actions: { self.actionsForProfile(accountID: self.accountID, sourceView: self.avatarImageView) } - ) - } - return self.getStatusCellPreviewProviders(for: location, sourceViewController: sourceViewController) - } -} - extension BaseStatusTableViewCell: UIDragInteractionDelegate { func dragInteraction(_ interaction: UIDragInteraction, itemsForBeginning session: UIDragSession) -> [UIDragItem] { guard let currentAccountID = mastodonController.accountInfo?.id, diff --git a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift index e33cd339..7aff9727 100644 --- a/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift +++ b/Tusker/Views/Status/ConversationMainStatusTableViewCell.swift @@ -36,6 +36,8 @@ class ConversationMainStatusTableViewCell: BaseStatusTableViewCell { accessibilityElements = [profileAccessibilityElement!, contentWarningLabel!, collapseButton!, contentTextView!, totalFavoritesButton!, totalReblogsButton!, timestampAndClientLabel!, replyButton!, favoriteButton!, reblogButton!, moreButton!] contentTextView.defaultFont = .systemFont(ofSize: 18) + + profileDetailContainerView.addInteraction(UIContextMenuInteraction(delegate: self)) } override func doUpdateUI(status: StatusMO, state: StatusState) { @@ -86,3 +88,13 @@ class ConversationMainStatusTableViewCell: BaseStatusTableViewCell { } } } + +extension ConversationMainStatusTableViewCell: UIContextMenuInteractionDelegate { + func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { + 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)) + } + } +} diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.swift b/Tusker/Views/Status/TimelineStatusTableViewCell.swift index 1a8d9b3d..0b56962b 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.swift +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.swift @@ -50,6 +50,8 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { replyButton.imageView!.leadingAnchor.constraint(equalTo: contentTextView.leadingAnchor).isActive = true contentTextView.defaultFont = .systemFont(ofSize: 16) + + avatarImageView.addInteraction(UIContextMenuInteraction(delegate: self)) } override func createObserversIfNecessary() { @@ -181,7 +183,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell { reply() } - override func getStatusCellPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> BaseStatusTableViewCell.PreviewProviders? { + override func getPreviewProviders(for location: CGPoint, sourceViewController: UIViewController) -> BaseStatusTableViewCell.PreviewProviders? { guard let mastodonController = mastodonController, let status = mastodonController.persistentContainer.status(for: statusID) else { return nil @@ -303,3 +305,13 @@ extension TimelineStatusTableViewCell: DraggableTableViewCell { return [UIDragItem(itemProvider: provider)] } } + +extension TimelineStatusTableViewCell: UIContextMenuInteractionDelegate { + func contextMenuInteraction(_ interaction: UIContextMenuInteraction, configurationForMenuAtLocation location: CGPoint) -> UIContextMenuConfiguration? { + 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)) + } + } +}