From 00a23b525fbc4ea7b9ec364d2da8ab4d35c989f5 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 11 Feb 2023 10:21:09 -0500 Subject: [PATCH] Add share to trending link actions --- Tusker/Screens/Explore/TrendingLinksViewController.swift | 5 +++-- Tusker/Screens/Explore/TrendsViewController.swift | 3 ++- Tusker/Screens/Utilities/Previewing.swift | 6 +++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/Tusker/Screens/Explore/TrendingLinksViewController.swift b/Tusker/Screens/Explore/TrendingLinksViewController.swift index 89e09f4809..85df679845 100644 --- a/Tusker/Screens/Explore/TrendingLinksViewController.swift +++ b/Tusker/Screens/Explore/TrendingLinksViewController.swift @@ -246,7 +246,8 @@ extension TrendingLinksViewController: UICollectionViewDelegate { func collectionView(_ collectionView: UICollectionView, contextMenuConfigurationForItemAt indexPath: IndexPath, point: CGPoint) -> UIContextMenuConfiguration? { guard case .link(let card) = dataSource.itemIdentifier(for: indexPath), - let url = URL(card.url) else { + let url = URL(card.url), + let cell = collectionView.cellForItem(at: indexPath) else { return nil } return UIContextMenuConfiguration { @@ -254,7 +255,7 @@ extension TrendingLinksViewController: UICollectionViewDelegate { vc.preferredControlTintColor = Preferences.shared.accentColor.color return vc } actionProvider: { _ in - UIMenu(children: self.actionsForTrendingLink(card: card)) + UIMenu(children: self.actionsForTrendingLink(card: card, source: .view(cell))) } } diff --git a/Tusker/Screens/Explore/TrendsViewController.swift b/Tusker/Screens/Explore/TrendsViewController.swift index 4380fbff8e..711d82c98b 100644 --- a/Tusker/Screens/Explore/TrendsViewController.swift +++ b/Tusker/Screens/Explore/TrendsViewController.swift @@ -369,12 +369,13 @@ extension TrendsViewController: UICollectionViewDelegate { guard let url = URL(card.url) else { return nil } + let cell = collectionView.cellForItem(at: indexPath)! return UIContextMenuConfiguration { let vc = SFSafariViewController(url: url) vc.preferredControlTintColor = Preferences.shared.accentColor.color return vc } actionProvider: { _ in - UIMenu(children: self.actionsForTrendingLink(card: card)) + UIMenu(children: self.actionsForTrendingLink(card: card, source: .view(cell))) } case let .status(id, state): diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index e385ad6df2..cd35dd38c8 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -346,12 +346,16 @@ extension MenuActionProvider { } } - func actionsForTrendingLink(card: Card) -> [UIMenuElement] { + func actionsForTrendingLink(card: Card, source: PopoverSource) -> [UIMenuElement] { guard let url = URL(card.url) else { return [] } return [ openInSafariAction(url: url), + createAction(identifier: "share", title: "Share", systemImageName: "square.and.arrow.up", handler: { [weak self] (_) in + guard let self else { return } + self.navigationDelegate?.showMoreOptions(forURL: url, source: source) + }), createAction(identifier: "postlink", title: "Post this Link", systemImageName: "square.and.pencil", handler: { [weak self] _ in guard let self = self else { return } let draft = self.mastodonController!.createDraft()