From 9f7d16a70e872de88f18b6503b8b4bbf0625fd4e Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Wed, 23 Nov 2022 11:47:00 -0500 Subject: [PATCH] Don't show duplicate actions in status cell more actions menu --- Tusker/Screens/Utilities/Previewing.swift | 10 ++++++---- Tusker/Views/Status/BaseStatusTableViewCell.swift | 2 +- Tusker/Views/Status/StatusCollectionViewCell.swift | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Tusker/Screens/Utilities/Previewing.swift b/Tusker/Screens/Utilities/Previewing.swift index dcf5a9c8..984ec12f 100644 --- a/Tusker/Screens/Utilities/Previewing.swift +++ b/Tusker/Screens/Utilities/Previewing.swift @@ -138,7 +138,7 @@ extension MenuActionProvider { ] } - func actionsForStatus(_ status: StatusMO, sourceView: UIView?, includeReply: Bool = true) -> [UIMenuElement] { + func actionsForStatus(_ status: StatusMO, sourceView: UIView?, includeStatusButtonActions: Bool = true) -> [UIMenuElement] { guard let mastodonController = mastodonController else { return [] } guard let accountID = mastodonController.accountInfo?.id else { @@ -169,7 +169,8 @@ extension MenuActionProvider { }), ] - if #available(iOS 16.0, *) { + if #available(iOS 16.0, *), + includeStatusButtonActions { let favorited = status.favourited // TODO: move this color into an asset catalog or something var favImage = UIImage(systemName: favorited ? "star.fill" : "star")! @@ -200,7 +201,7 @@ extension MenuActionProvider { var actionsSection: [UIAction] = [] - if includeReply { + if includeStatusButtonActions { actionsSection.insert(createAction(identifier: "reply", title: "Reply", systemImageName: "arrowshape.turn.up.left", handler: { [weak self] (_) in guard let self = self else { return } self.navigationDelegate?.compose(inReplyToID: status.id) @@ -278,8 +279,9 @@ extension MenuActionProvider { addOpenInNewWindow(actions: &shareSection, activity: UserActivityManager.showConversationActivity(mainStatusID: status.id, accountID: accountID)) if #available(iOS 16.0, *) { + let toggleableAndActions = toggleableSection + actionsSection return [ - UIMenu(options: .displayInline, preferredElementSize: .medium, children: toggleableSection + actionsSection), + UIMenu(options: .displayInline, preferredElementSize: toggleableAndActions.count == 1 ? .large : .medium, children: toggleableAndActions), UIMenu(options: .displayInline, children: shareSection), ] } else { diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index 98a32dda..a314ce89 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -209,7 +209,7 @@ class BaseStatusTableViewCell: UITableViewCell { // keep menu in sync with changed states e.g. bookmarked, muted // do not include reply action here, because the cell already contains a button for it - moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForStatus(status, sourceView: moreButton, includeReply: false) ?? []) + moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForStatus(status, sourceView: moreButton, includeStatusButtonActions: false) ?? []) pollView.isHidden = status.poll == nil pollView.mastodonController = mastodonController diff --git a/Tusker/Views/Status/StatusCollectionViewCell.swift b/Tusker/Views/Status/StatusCollectionViewCell.swift index da7f39f9..2bd63a25 100644 --- a/Tusker/Views/Status/StatusCollectionViewCell.swift +++ b/Tusker/Views/Status/StatusCollectionViewCell.swift @@ -195,7 +195,7 @@ extension StatusCollectionViewCell { // keep menu in sync with changed states e.g. bookmarked, muted // do not include reply action here, because the cell already contains a button for it - moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForStatus(status, sourceView: moreButton, includeReply: false) ?? []) + moreButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: delegate?.actionsForStatus(status, sourceView: moreButton, includeStatusButtonActions: false) ?? []) contentContainer.pollView.isHidden = status.poll == nil contentContainer.pollView.mastodonController = mastodonController