From 5b4d1bee695535f9afa1f2651bf2bbbf832d0092 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Mon, 28 Jul 2025 23:55:45 +0200 Subject: [PATCH] Open keyboard when replying to a message --- .../Fragments/ConversationFragment.swift | 14 +++++++++++--- .../UI/Main/Conversations/Fragments/UIList.swift | 7 ++++++- .../ViewModel/ConversationViewModel.swift | 10 +++++----- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift index a06e890f2..8d1cc607d 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ConversationFragment.swift @@ -444,8 +444,13 @@ struct ConversationFragment: View { ZStack(alignment: .bottomTrailing) { UIList( geometryProxy: geometry, - sections: conversationViewModel.conversationMessagesSection - ) + sections: conversationViewModel.conversationMessagesSection, + isMessageTextFocused: Binding(get: { + isMessageTextFocused + }, set: { newValue in + isMessageTextFocused = newValue + }) + ) .environmentObject(conversationViewModel) .environmentObject(conversationsListViewModel) } @@ -1095,7 +1100,10 @@ struct ConversationFragment: View { Button { let indexMessage = conversationViewModel.conversationMessagesSection[0].rows.firstIndex(where: {$0.message.id == conversationViewModel.selectedMessage!.message.id}) conversationViewModel.selectedMessage = nil - conversationViewModel.replyToMessage(index: indexMessage ?? 0) + if !isMessageTextFocused { + isMessageTextFocused = true + } + conversationViewModel.replyToMessage(index: indexMessage ?? 0, isMessageTextFocused: isMessageTextFocused) } label: { HStack { Text("menu_reply_to_chat_message") diff --git a/Linphone/UI/Main/Conversations/Fragments/UIList.swift b/Linphone/UI/Main/Conversations/Fragments/UIList.swift index 667dc886a..8d0015c3d 100644 --- a/Linphone/UI/Main/Conversations/Fragments/UIList.swift +++ b/Linphone/UI/Main/Conversations/Fragments/UIList.swift @@ -108,6 +108,8 @@ struct UIList: UIViewRepresentable { let geometryProxy: GeometryProxy let sections: [MessagesSection] + + @Binding var isMessageTextFocused: Bool @State private var isScrolledToTop = false @State private var isScrolledToBottom = true @@ -501,7 +503,10 @@ struct UIList: UIViewRepresentable { func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { let archiveAction = UIContextualAction(style: .normal, title: "") { _, _, completionHandler in - self.parent.conversationViewModel.replyToMessage(index: indexPath.row) + if !self.parent.isMessageTextFocused { + self.parent.isMessageTextFocused = true + } + self.parent.conversationViewModel.replyToMessage(index: indexPath.row, isMessageTextFocused: self.parent.isMessageTextFocused) completionHandler(true) } diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index b27afcbb7..cc2b4064a 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -1547,13 +1547,13 @@ class ConversationViewModel: ObservableObject { conversationMessagesSection = [] } - func replyToMessage(index: Int) { + func replyToMessage(index: Int, isMessageTextFocused: Bool) { coreContext.doOnCoreQueue { _ in let messageToReplyTmp = self.conversationMessagesSection[0].rows[index] - DispatchQueue.main.async { - withAnimation(.linear(duration: 0.15)) { - self.messageToReply = messageToReplyTmp - } + DispatchQueue.main.asyncAfter(deadline: .now() + (isMessageTextFocused ? 0 : 0.22)){ + withAnimation(.linear(duration: 0.15)) { + self.messageToReply = messageToReplyTmp + } } } }