Skip to content

Commit

Permalink
Show menu for long press to copy contact to clipboard (#2274)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeitschlag committed Aug 28, 2024
1 parent ef0ab15 commit fbc51e8
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions deltachat-ios/Controller/ContactDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class ContactDetailViewController: UITableViewController {
headerCell.onMuteButtonTapped = toggleMuteChat
headerCell.onSearchButtonTapped = showSearch
headerCell.setRecentlySeen(viewModel.contact.wasSeenRecently)

if viewModel.isSavedMessages == false && viewModel.isDeviceTalk == false {
let copyContactGestureRecognizer = UILongPressGestureRecognizer(target: self, action: #selector(ContactDetailViewController.showCopyToClipboard))
headerCell.labelsContainer.addGestureRecognizer(copyContactGestureRecognizer)
}

return headerCell
}()

Expand Down Expand Up @@ -323,6 +329,24 @@ class ContactDetailViewController: UITableViewController {
}

// MARK: - actions

@objc private func showCopyToClipboard() {
UIMenuController.shared.menuItems = [
UIMenuItem(title: String.localized("menu_copy_to_clipboard"), action: #selector(ContactDetailViewController.copyToClipboard))
]

if #available(iOS 13.0, *) {
UIMenuController.shared.showMenu(from: headerCell.titleLabelContainer, rect: headerCell.titleLabelContainer.frame)
} else {
UIMenuController.shared.setTargetRect(headerCell.titleLabelContainer.frame, in: headerCell)
UIMenuController.shared.setMenuVisible(true, animated: true)
}
}

@objc private func copyToClipboard() {
UIPasteboard.general.string = viewModel.contact.email
}

private func handleChatAction(indexPath: IndexPath) {
let action = viewModel.chatActionFor(row: indexPath.row)
switch action {
Expand Down

0 comments on commit fbc51e8

Please sign in to comment.