From 7d7b45757569786632b31910fd139f9a1256c950 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 27 Jul 2019 18:53:07 -0400 Subject: [PATCH] Fix context menu actions in beta 4 --- .../EnhancedTableViewController.swift | 3 +- Tusker/Screens/Utilities/Previewing.swift | 36 ++++++++++--------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/Tusker/Screens/Utilities/EnhancedTableViewController.swift b/Tusker/Screens/Utilities/EnhancedTableViewController.swift index 55fcc195a3..91f43c9b92 100644 --- a/Tusker/Screens/Utilities/EnhancedTableViewController.swift +++ b/Tusker/Screens/Utilities/EnhancedTableViewController.swift @@ -47,7 +47,8 @@ extension EnhancedTableViewController { return nil } let actionProvider: UIContextMenuActionProvider = { (elements) in - return UIMenu(title: "test", children: elements + actionsProvider()) + return UIMenu(title: "", image: nil, identifier: nil, options: [], children: elements + actionsProvider()) +// return UIMenu(title: "test", children: elements + actionsProvider()) } return UIContextMenuConfiguration(identifier: nil, previewProvider: previewProvider, actionProvider: actionProvider) } else { diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index b68c367122..1bd95e2e95 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -27,26 +27,26 @@ extension MenuPreviewProvider { func actionsForProfile(accountID: String) -> [UIAction] { guard let account = MastodonCache.account(for: accountID) else { return [] } return [ - UIAction(__title: "Open in Safari", image: UIImage(systemName: "safari")) { (_) in + createAction(identifier: "openinsafari", title: "Open in Safari", systemImageName: "safari", handler: { (_) in self.present(SFSafariViewController(url: account.url)) - }, - UIAction(__title: "Send Message", image: UIImage(systemName: "envelope")) { (_) in + }), + createAction(identifier: "sendmessage", title: "Send Message", systemImageName: "envelope", handler: { (_) in self.present(UINavigationController(rootViewController: ComposeViewController(mentioningAcct: account.acct))) - }, - UIAction(__title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { (_) in + }), + createAction(identifier: "share", title: "Share...", systemImageName: "square.and.arrow.up", handler: { (_) in self.present(UIActivityViewController(activityItems: [account.url], applicationActivities: nil)) - } + }) ] } func actionsForURL(_ url: URL) -> [UIAction] { return [ - UIAction(__title: "Open in Safari", image: UIImage(systemName: "safari")) { (_) in + createAction(identifier: "openinsafari", title: "Open in Safari", systemImageName: "safari", handler: { (_) in self.present(SFSafariViewController(url: url)) - }, - UIAction(__title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { (_) in + }), + createAction(identifier: "share", title: "Share...", systemImageName: "square.and.arrow.up", handler: { (_) in self.present(UIActivityViewController(activityItems: [url], applicationActivities: nil)) - } + }) ] } @@ -57,16 +57,20 @@ extension MenuPreviewProvider { func actionsForStatus(statusID: String) -> [UIAction] { guard let status = MastodonCache.status(for: statusID) else { return [] } return [ - UIAction(__title: "Reply", image: UIImage(systemName: "arrowshape.turn.up.left")) { (_) in + createAction(identifier: "reply", title: "Reply", systemImageName: "arrowshape.turn.up.left", handler: { (_) in self.present(UINavigationController(rootViewController: ComposeViewController(inReplyTo: statusID))) - }, - UIAction(__title: "Open in Safari", image: UIImage(systemName: "safari")) { (_) in + }), + createAction(identifier: "openinsafari", title: "Open in Safari", systemImageName: "safari", handler: { (_) in self.present(SFSafariViewController(url: status.url!)) - }, - UIAction(__title: "Share...", image: UIImage(systemName: "square.and.arrow.up")) { (_) in + }), + createAction(identifier: "share", title: "Share...", systemImageName: "square.and.arrow.up", handler: { (_) in self.present(UIActivityViewController(activityItems: [status.url!], applicationActivities: nil)) - } + }) ] } + private func createAction(identifier: String, title: String, systemImageName: String, handler: @escaping UIActionHandler) -> UIAction { + return UIAction(title: title, image: UIImage(systemName: systemImageName), identifier: UIAction.Identifier(identifier), discoverabilityTitle: nil, attributes: [], state: .off, handler: handler) + } + }