Add subtitles to visibility context menu items

Closes #155
This commit is contained in:
Shadowfacts 2022-04-27 23:21:08 -04:00
parent eb9a5aeb42
commit 4dd8c1d692
2 changed files with 26 additions and 3 deletions

View File

@ -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 { var imageName: String {
switch self { switch self {
case .public: case .public:

View File

@ -250,7 +250,7 @@ class ComposeHostingController: UIHostingController<ComposeContainerView> {
item.accessibilityLabel = String(format: NSLocalizedString("Visibility: %@", comment: "compose visiblity accessibility label"), draft.visibility.displayName) item.accessibilityLabel = String(format: NSLocalizedString("Visibility: %@", comment: "compose visiblity accessibility label"), draft.visibility.displayName)
let elements = Status.Visibility.allCases.map { (visibility) -> UIMenuElement in let elements = Status.Visibility.allCases.map { (visibility) -> UIMenuElement in
let state = visibility == newVisibility ? UIMenuElement.State.on : .off 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 self.draft.visibility = visibility
} }
} }
@ -270,9 +270,9 @@ class ComposeHostingController: UIHostingController<ComposeContainerView> {
item.image = UIImage(systemName: "link") item.image = UIImage(systemName: "link")
item.accessibilityLabel = "Federated" item.accessibilityLabel = "Federated"
} }
let instanceSubtitle = "Only \(mastodonController.accountInfo!.instanceURL.host!)"
item.menu = UIMenu(children: [ item.menu = UIMenu(children: [
// todo: iOS 15, action subtitles UIAction(title: "Local-only", subtitle: instanceSubtitle, image: UIImage(named: "link.broken"), state: localOnly ? .on : .off) { [unowned self] (_) in
UIAction(title: "Local-only", image: UIImage(named: "link.broken"), state: localOnly ? .on : .off) { [unowned self] (_) in
self.draft.localOnly = true self.draft.localOnly = true
}, },
UIAction(title: "Federated", image: UIImage(systemName: "link"), state: localOnly ? .off : .on) { [unowned self] (_) in UIAction(title: "Federated", image: UIImage(systemName: "link"), state: localOnly ? .off : .on) { [unowned self] (_) in
@ -474,3 +474,13 @@ extension ComposeHostingController: ComposeDrawingViewControllerDelegate {
dismiss(animated: true) 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)
}
}
}