From 27d0f0f3abf5a563fdf0ed4a4f4709fefcc60448 Mon Sep 17 00:00:00 2001 From: "B. Petersen" <r10s@b44t.com> Date: Mon, 8 Apr 2024 16:17:50 +0200 Subject: [PATCH] always show the selected reaction in menu if a reaction was selected, show that instead of "...". this is what whatsapp/signal are doing - as well as deltachat android since https://github.com/deltachat/deltachat-android/pull/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 - consistency --- deltachat-ios/Chat/ChatViewController.swift | 46 ++++++++++++++------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/deltachat-ios/Chat/ChatViewController.swift b/deltachat-ios/Chat/ChatViewController.swift index 829fcc8404..41a9892186 100644 --- a/deltachat-ios/Chat/ChatViewController.swift +++ b/deltachat-ios/Chat/ChatViewController.swift @@ -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 } @@ -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) } ) }