Add share to trending link actions

This commit is contained in:
Shadowfacts 2023-02-11 10:21:09 -05:00
parent ea85b11945
commit 00a23b525f
3 changed files with 10 additions and 4 deletions

View File

@ -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)))
}
}

View File

@ -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):

View File

@ -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()