diff --git a/WordPress/Classes/Utility/WPTableViewHandler.h b/WordPress/Classes/Utility/WPTableViewHandler.h index f86fe1f800eb..79a265ed8a2f 100644 --- a/WordPress/Classes/Utility/WPTableViewHandler.h +++ b/WordPress/Classes/Utility/WPTableViewHandler.h @@ -53,6 +53,7 @@ - (nullable UISwipeActionsConfiguration *)tableView:(nonnull UITableView *)tableView leadingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath; - (nullable UISwipeActionsConfiguration *)tableView:(nonnull UITableView *)tableView trailingSwipeActionsConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath; +- (nullable UIContextMenuConfiguration *)tableView:(nonnull UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(nonnull NSIndexPath *)indexPath point:(CGPoint)point; #pragma mark - Tracking the removal of views diff --git a/WordPress/Classes/Utility/WPTableViewHandler.m b/WordPress/Classes/Utility/WPTableViewHandler.m index 9c0554be482a..bdbad1a594c7 100644 --- a/WordPress/Classes/Utility/WPTableViewHandler.m +++ b/WordPress/Classes/Utility/WPTableViewHandler.m @@ -314,6 +314,13 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath [self.delegate tableView:tableView didSelectRowAtIndexPath:indexPath]; } +- (UIContextMenuConfiguration *)tableView:(UITableView *)tableView contextMenuConfigurationForRowAtIndexPath:(NSIndexPath *)indexPath point:(CGPoint)point { + if ([self.delegate respondsToSelector:@selector(tableView:contextMenuConfigurationForRowAtIndexPath:point:)]) { + return [self.delegate tableView:tableView contextMenuConfigurationForRowAtIndexPath:indexPath point:point]; + } + return nil; +} + #pragma mark - Optional Delegate Methods diff --git a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderDiscoverViewController.swift b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderDiscoverViewController.swift index 57387fb37f7a..80dcb360c17c 100644 --- a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderDiscoverViewController.swift +++ b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderDiscoverViewController.swift @@ -363,6 +363,13 @@ private class ReaderDiscoverStreamViewController: ReaderStreamViewController { super.syncIfAppropriate(forceSync: true) tableView.reloadRows(at: [indexPath], with: UITableView.RowAnimation.fade) } + + override func getPost(at indexPath: IndexPath) -> ReaderPost? { + guard let card: ReaderCard = content.object(at: indexPath) else { + return nil + } + return card.post + } } // MARK: - ReaderRecommendedSitesCellDelegate diff --git a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift index 58889bfe52ba..b46c7ef8a0ce 100644 --- a/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift +++ b/WordPress/Classes/ViewRelated/Reader/Controllers/ReaderStreamViewController.swift @@ -1139,6 +1139,10 @@ import AutomatticTracks completion?(false) }) } + + func getPost(at indexPath: IndexPath) -> ReaderPost? { + content.object(at: indexPath) + } } // MARK: - ReaderStreamHeaderDelegate @@ -1447,6 +1451,20 @@ extension ReaderStreamViewController: WPTableViewHandlerDelegate { // Do nothing } + func tableView(_ tableView: UITableView, contextMenuConfigurationForRowAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { + guard let post = getPost(at: indexPath) else { + return nil + } + return UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in + guard let self else { return nil } + return UIMenu(children: ReaderPostMenu( + post: post, + topic: readerTopic, + anchor: self.tableView.cellForRow(at: indexPath) ?? self.view, + viewController: self + ).makeMenu()) + } + } } // MARK: - SearchableActivity Conformance