Skip to content

Commit

Permalink
flatten menus (#2586)
Browse files Browse the repository at this point in the history
* flatten menus

before, delete as last item was separated,
which stands a bit in the way of adding it to already separated last "more..." item
(we could separate both, but that is ugly)

looking at lots of other apps, however,
"delete" is not separated in most of them ("gallery" is a prominent exception)

* add 'delete' to top-level menu

having 'delete' at 'more' was kind of an experiment,
however, with new 'saved messages', things have changed:

one wants to quickly 'unsave' messaes,
however, from inside 'saved messages', delete is more logical,
as it is a copy and as there are also other messages inside 'saved messages'
(eg. notes)

* reformat image to what we do at simmilar places

* add 'more' menu

* add separator above 'more options'

* move 'reply privately' to more

* move 'copy image' to more

* use standard forward icon

* add 'resend', 'share', 'info' to more

* remove single-msg-actions from 'select' menu; they were there at the time we did not had a 'more' menu
  • Loading branch information
r10s authored Feb 7, 2025
1 parent ba67227 commit 1b66ca0
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 137 deletions.

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
91 changes: 37 additions & 54 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1259,22 +1259,6 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
}
}

private func onShareActionPressed() {
if let rows = tableView.indexPathsForSelectedRows {
let selectedMsgIds = rows.compactMap { messageIds[$0.row] }
if let msgId = selectedMsgIds.first {
Utils.share(message: dcContext.getMessage(id: msgId), parentViewController: self, sourceView: self.view)
setEditing(isEditing: false)
}
}
}

private func onInfoActionPressed() {
if let rows = tableView.indexPathsForSelectedRows, let firstRow = rows.first {
info(at: firstRow)
}
}

private func askToDeleteChat() {
let chat = dcContext.getChat(chatId: chatId)
let title = String.localizedStringWithFormat(String.localized("ask_delete_named_chat"), chat.name)
Expand Down Expand Up @@ -1708,6 +1692,20 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
}
}

private func shareSingle(at indexPath: IndexPath) {
let msgId = messageIds[indexPath.row]
Utils.share(message: dcContext.getMessage(id: msgId), parentViewController: self, sourceView: view)
}

private func resendSingle(at indexPath: IndexPath) {
let msgId = messageIds[indexPath.row]
dcContext.resendMessages(msgIds: [msgId])
}

private func deleteSingle(at indexPath: IndexPath) {
askToDeleteMessages(ids: [self.messageIds[indexPath.row]])
}

private func copyTextToClipboard(at indexPath: IndexPath) {
copyTextToClipboard(ids: [self.messageIds[indexPath.row]])
}
Expand Down Expand Up @@ -1902,6 +1900,7 @@ extension ChatViewController {
guard let self else { return nil }
let message = dcContext.getMessage(id: messageId)
var children: [UIMenuElement] = []
var moreOptions: [UIMenuElement] = []
var preferredElementSizeSmall = false

if canReply(to: message) {
Expand All @@ -1914,24 +1913,18 @@ extension ChatViewController {
children.append(UIMenu(title: String.localized("react"), image: UIImage(systemName: "face.smiling"), children: items))
}
children.append(
UIAction.menuAction(localizationKey: "notify_reply_button", systemImageName: "arrowshape.turn.up.left.fill", indexPath: indexPath, action: { self.reply(at: $0 ) })
UIAction.menuAction(localizationKey: "notify_reply_button", systemImageName: "arrowshape.turn.up.left", indexPath: indexPath, action: { self.reply(at: $0 ) })
)
}

if canReplyPrivately(to: message) {
children.append(
moreOptions.append(
UIAction.menuAction(localizationKey: "reply_privately", systemImageName: "arrowshape.turn.up.left", indexPath: indexPath, action: { self.replyPrivatelyToMessage(at: $0 ) })
)
}

let image: UIImage?
if #available(iOS 16.0, *) {
image = UIImage(systemName: "arrowshape.forward.fill")
} else {
image = UIImage(named: "ic_forward_white_36pt")
}
children.append(
UIAction.menuAction(localizationKey: "forward", image: image, indexPath: indexPath, action: forward)
UIAction.menuAction(localizationKey: "forward", systemImageName: "arrowshape.turn.up.forward", indexPath: indexPath, action: forward)
)

if !isMarkerOrInfo(message) { // info-messages out of context results in confusion, see https://github.com/deltachat/deltachat-ios/issues/2567
Expand Down Expand Up @@ -1959,14 +1952,30 @@ extension ChatViewController {
)
}
if message.image != nil {
children.append(
moreOptions.append(
UIAction.menuAction(localizationKey: "menu_copy_image_to_clipboard", systemImageName: "photo.on.rectangle", indexPath: indexPath, action: copyImageToClipboard)
)
}

if message.file != nil {
moreOptions.append(UIAction.menuAction(localizationKey: "menu_share", systemImageName: "square.and.arrow.up", indexPath: indexPath, action: shareSingle))
}

children.append(
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: deleteSingle)
)

if dcChat.canSend && message.isFromCurrentSender {
moreOptions.append(UIAction.menuAction(localizationKey: "resend", systemImageName: "paperplane", indexPath: indexPath, action: resendSingle))
}

moreOptions.append(UIAction.menuAction(localizationKey: "info", systemImageName: "info.circle", indexPath: indexPath, action: info))

moreOptions.append(UIAction.menuAction(localizationKey: "select", systemImageName: "checkmark.circle", indexPath: indexPath, action: selectMore))

children.append(contentsOf: [
UIMenu(options: [.displayInline], children: [
UIAction.menuAction(localizationKey: "menu_more_options", systemImageName: "checkmark.circle", indexPath: indexPath, action: selectMore),
UIMenu(title: String.localized("menu_more_options"), image: UIImage(systemName: "ellipsis.circle"), children: moreOptions)
])
])

Expand Down Expand Up @@ -2126,24 +2135,8 @@ extension ChatViewController {
}
}

private func canShare() -> Bool {
if tableView.indexPathsForSelectedRows?.count == 1,
let rows = tableView.indexPathsForSelectedRows {
let msgIds = rows.compactMap { messageIds[$0.row] }
if let msgId = msgIds.first {
let msg = dcContext.getMessage(id: msgId)
return msg.file != nil
}
}
return false
}

private func canInfo() -> Bool {
return tableView.indexPathsForSelectedRows?.count == 1
}

private func evaluateMoreButton() {
editingBar.moreButton.isEnabled = canShare() || canResend() || canInfo()
editingBar.moreButton.isEnabled = canResend()
}

func setEditing(isEditing: Bool, selectedAtIndexPath: IndexPath? = nil) {
Expand Down Expand Up @@ -2466,16 +2459,6 @@ extension ChatViewController: ChatEditingDelegate {
self?.onResendActionPressed()
})
}
if canShare() {
actions.append(UIAction(title: String.localized("menu_share"), image: UIImage(systemName: "square.and.arrow.up")) { [weak self] _ in
self?.onShareActionPressed()
})
}
if canInfo() {
actions.append(UIAction(title: String.localized("info"), image: UIImage(systemName: "info.circle")) { [weak self] _ in
self?.onInfoActionPressed()
})
}
return UIMenu(children: actions)
}

Expand Down
7 changes: 1 addition & 6 deletions deltachat-ios/Chat/Views/ChatEditingBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,7 @@ public class ChatEditingBar: UIView {
public lazy var forwardButton: UIButton = {
let view = UIButton()
view.tintColor = .systemBlue
if #available(iOS 16.0, *) {
view.setImage(UIImage(systemName: "arrowshape.forward.fill"), for: .normal)
} else {
view.setImage(UIImage(named: "ic_forward_white_36pt"), for: .normal)
view.imageEdgeInsets = UIEdgeInsets(top: 5, left: 0, bottom: 5, right: 0)
}
view.setImage(UIImage(systemName: "arrowshape.turn.up.forward"), for: .normal)
view.translatesAutoresizingMaskIntoConstraints = false
view.isUserInteractionEnabled = true
view.accessibilityLabel = String.localized("forward")
Expand Down
7 changes: 1 addition & 6 deletions deltachat-ios/Controller/AccountSwitchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,7 @@ class AccountSwitchViewController: UITableViewController {
UIAction.menuAction(localizationKey: muteTitle, systemImageName: muteImage, indexPath: indexPath, action: { self.toggleMute(at: $0) }),
UIAction.menuAction(localizationKey: "profile_tag", systemImageName: "tag", indexPath: indexPath, action: { self.setProfileTag(at: $0) }),
UIAction.menuAction(localizationKey: "move_to_top", systemImageName: "arrow.up", indexPath: indexPath, action: { self.moveToTop(at: $0) }),
UIMenu(
options: [.displayInline],
children: [
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: { self.deleteAccount(at: $0) })
]
)
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: { self.deleteAccount(at: $0) })
]
return UIMenu(children: children)
}
Expand Down
7 changes: 1 addition & 6 deletions deltachat-ios/Controller/FilesViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,7 @@ extension FilesViewController: UITableViewDelegate, UITableViewDataSource {

children.append(contentsOf: [
UIAction.menuAction(localizationKey: "menu_share", systemImageName: "square.and.arrow.up", indexPath: indexPath, action: { self.shareAttachment(of: $0) }),
UIMenu(
options: [.displayInline],
children: [
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: { self.askToDeleteItem(at: $0) })
]
)
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: { self.askToDeleteItem(at: $0) })
])
let menu = UIMenu(children: children)

Expand Down
25 changes: 6 additions & 19 deletions deltachat-ios/Controller/GalleryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -263,25 +263,12 @@ extension GalleryViewController: UICollectionViewDataSource, UICollectionViewDel

let menu = UIMenu(
children: [
UIMenu(
options: [.displayInline],
children: [UIAction.menuAction(localizationKey: "show_in_chat",
systemImageName: "doc.text.magnifyingglass",
indexPath: indexPath,
action: {
self.redirectToMessage(of: $0 )
})]
),
UIMenu(
options: [.displayInline],
children: [UIAction.menuAction(localizationKey: "delete",
attributes: [.destructive],
systemImageName: "trash",
indexPath: indexPath,
action: {
self.askToDeleteItem(at: $0 )
})]
),
UIAction.menuAction(localizationKey: "show_in_chat", systemImageName: "doc.text.magnifyingglass", indexPath: indexPath, action: {
self.redirectToMessage(of: $0 )
}),
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: {
self.askToDeleteItem(at: $0 )
}),
]
)
return menu
Expand Down
10 changes: 3 additions & 7 deletions deltachat-ios/Controller/QrPageController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,9 @@ class QrPageController: UIPageViewController {
})
}
if qrSegmentControl.selectedSegmentIndex == 0 {
actions.append(UIMenu(options: [.displayInline],
children: [
UIAction(title: String.localized("withdraw_qr_code"), image: UIImage(systemName: "trash"), attributes: [.destructive]) { [weak self] _ in
self?.withdrawQrCode()
},
]
))
actions.append(UIAction(title: String.localized("withdraw_qr_code"), image: UIImage(systemName: "trash"), attributes: [.destructive]) { [weak self] _ in
self?.withdrawQrCode()
})
}
return UIMenu(children: actions)
}
Expand Down
10 changes: 3 additions & 7 deletions deltachat-ios/Controller/QrViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,9 @@ class QrViewController: UIViewController {
UIAction(title: String.localized("menu_copy_to_clipboard"), image: UIImage(systemName: "document.on.document")) { [weak self] _ in
self?.copyToClipboard()
},
UIMenu(options: [.displayInline],
children: [
UIAction(title: String.localized("withdraw_qr_code"), image: UIImage(systemName: "trash"), attributes: [.destructive]) { [weak self] _ in
self?.withdrawQrCode()
},
]
),
UIAction(title: String.localized("withdraw_qr_code"), image: UIImage(systemName: "trash"), attributes: [.destructive]) { [weak self] _ in
self?.withdrawQrCode()
},
]
return UIMenu(children: actions)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,7 @@ extension ProxySettingsViewController {
guard let self else { return nil }
let children: [UIMenuElement] = [
UIAction.menuAction(localizationKey: "menu_share", systemImageName: "square.and.arrow.up", indexPath: indexPath, action: { self.shareProxy(at: $0) }),
UIMenu(
options: [.displayInline],
children: [
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: { self.deleteProxy(at: $0) })
]
)
UIAction.menuAction(localizationKey: "delete", attributes: [.destructive], systemImageName: "trash", indexPath: indexPath, action: { self.deleteProxy(at: $0) })
]
return UIMenu(children: children)
}
Expand Down

0 comments on commit 1b66ca0

Please sign in to comment.