From 4dd8c1d69200f2c8e385fff7c281a99308ca9387 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 27 Apr 2022 23:21:08 -0400 Subject: [PATCH] Add subtitles to visibility context menu items Closes #155 --- Tusker/Extensions/Visibility+Helpers.swift | 13 +++++++++++++ .../Compose/ComposeHostingController.swift | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Tusker/Extensions/Visibility+Helpers.swift b/Tusker/Extensions/Visibility+Helpers.swift index ab7fe15f..445c418a 100644 --- a/Tusker/Extensions/Visibility+Helpers.swift +++ b/Tusker/Extensions/Visibility+Helpers.swift @@ -24,6 +24,19 @@ extension Status.Visibility { } } + var subtitle: String { + switch self { + case .public: + return "Everyone" + case .unlisted: + return "Hidden from public timelines" + case .private: + return "Followers only" + case .direct: + return "Mentioned users only" + } + } + var imageName: String { switch self { case .public: diff --git a/Tusker/Screens/Compose/ComposeHostingController.swift b/Tusker/Screens/Compose/ComposeHostingController.swift index a3d3b416..81e2a148 100644 --- a/Tusker/Screens/Compose/ComposeHostingController.swift +++ b/Tusker/Screens/Compose/ComposeHostingController.swift @@ -250,7 +250,7 @@ class ComposeHostingController: UIHostingController { item.accessibilityLabel = String(format: NSLocalizedString("Visibility: %@", comment: "compose visiblity accessibility label"), draft.visibility.displayName) let elements = Status.Visibility.allCases.map { (visibility) -> UIMenuElement in let state = visibility == newVisibility ? UIMenuElement.State.on : .off - return UIAction(title: visibility.displayName, image: UIImage(systemName: visibility.unfilledImageName), identifier: nil, discoverabilityTitle: nil, attributes: [], state: state) { [unowned self] (_) in + return UIAction(title: visibility.displayName, subtitle: visibility.subtitle, image: UIImage(systemName: visibility.unfilledImageName), state: state) { [unowned self] (_) in self.draft.visibility = visibility } } @@ -270,9 +270,9 @@ class ComposeHostingController: UIHostingController { item.image = UIImage(systemName: "link") item.accessibilityLabel = "Federated" } + let instanceSubtitle = "Only \(mastodonController.accountInfo!.instanceURL.host!)" item.menu = UIMenu(children: [ - // todo: iOS 15, action subtitles - UIAction(title: "Local-only", image: UIImage(named: "link.broken"), state: localOnly ? .on : .off) { [unowned self] (_) in + UIAction(title: "Local-only", subtitle: instanceSubtitle, image: UIImage(named: "link.broken"), state: localOnly ? .on : .off) { [unowned self] (_) in self.draft.localOnly = true }, UIAction(title: "Federated", image: UIImage(systemName: "link"), state: localOnly ? .off : .on) { [unowned self] (_) in @@ -474,3 +474,13 @@ extension ComposeHostingController: ComposeDrawingViewControllerDelegate { dismiss(animated: true) } } + +fileprivate extension UIAction { + convenience init(title: String, subtitle: String?, image: UIImage?, state: UIAction.State, handler: @escaping UIActionHandler) { + if #available(iOS 15.0, *) { + self.init(title: title, subtitle: subtitle, image: image, identifier: nil, discoverabilityTitle: nil, attributes: [], state: state, handler: handler) + } else { + self.init(title: title, image: image, identifier: nil, discoverabilityTitle: nil, attributes: [], state: state, handler: handler) + } + } +}