Skip to content

Commit

Permalink
always show the selected reaction in menu
Browse files Browse the repository at this point in the history
if a reaction was selected,
show that instead of "...".

this is what whatsapp/signal are doing - as well as
deltachat android since
deltachat/deltachat-android#2979

deltachat desktop has more room and shows "..." and selection the same time.

little drawback is that changing a reaction requires two taps,
but that seems fine in practise and is outweighted by advantages as:
- always seeing what was selected
- make it clearer, there is only one reaction
- make it clearer how to retract ones reaction
- retracting is always only one tap
- consistency
  • Loading branch information
r10s committed Apr 8, 2024
1 parent 71a4a27 commit d6b3416
Showing 1 changed file with 32 additions and 14 deletions.
46 changes: 32 additions & 14 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1932,10 +1932,17 @@ extension ChatViewController {
private func appendReactionItems(to menuElements: inout [UIMenuElement], indexPath: IndexPath) {
let messageId = messageIds[indexPath.row]
let myReactions = getMyReactions(messageId: messageId)
var myReactionChecked = false

for reaction in DefaultReactions.allCases {
let sentThisReaction = myReactions.contains(where: { $0 == reaction.emoji })
let title = sentThisReaction ? (reaction.emoji + "") : reaction.emoji
let title: String
if sentThisReaction {
title = reaction.emoji + ""
myReactionChecked = true
} else {
title = reaction.emoji
}
menuElements.append(UIAction(title: title) { [weak self] _ in
guard let self else { return }

Expand All @@ -1948,23 +1955,34 @@ extension ChatViewController {
})
}

let showPicker = myReactions.isEmpty || myReactionChecked
let title: String
if showPicker {
title = "•••"
} else {
title = (myReactions.first ?? "?") + ""
}
menuElements.append(
UIAction(title: "•••") { [weak self] _ in
UIAction(title: title) { [weak self] _ in
guard let self else { return }
reactionMessageId = self.messageIds[indexPath.row]

let pickerViewController = MCEmojiPickerViewController()
pickerViewController.navigationItem.title = String.localized("react")
pickerViewController.delegate = self

let navigationController = UINavigationController(rootViewController: pickerViewController)
if #available(iOS 15.0, *) {
if let sheet = navigationController.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.preferredCornerRadius = 20
let messageId = self.messageIds[indexPath.row]
if showPicker {
reactionMessageId = messageId
let pickerViewController = MCEmojiPickerViewController()
pickerViewController.navigationItem.title = String.localized("react")
pickerViewController.delegate = self

let navigationController = UINavigationController(rootViewController: pickerViewController)
if #available(iOS 15.0, *) {
if let sheet = navigationController.sheetPresentationController {
sheet.detents = [.medium(), .large()]
sheet.preferredCornerRadius = 20
}
}
present(navigationController, animated: true)
} else {
dcContext.sendReaction(messageId: messageId, reaction: nil)
}
present(navigationController, animated: true)
}
)
}
Expand Down

0 comments on commit d6b3416

Please sign in to comment.