diff --git a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift index d24a8e42a..a39bbb078 100644 --- a/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift +++ b/Linphone/UI/Main/Conversations/Fragments/ChatBubbleView.swift @@ -441,12 +441,16 @@ struct ChatBubbleView: View { } .onTapGesture {} .onLongPressGesture(minimumDuration: .infinity, maximumDistance: .infinity, pressing: { (value) in - self.isPressed = value - if value == true { - self.timePassed = 0 - self.ticker.start(interval: 0.2) + if !self.conversationViewModel.isSwiping { + self.isPressed = value + if value == true { + self.timePassed = 0 + self.ticker.start(interval: 0.2) + } + } else { + self.ticker.stop() + return } - }, perform: {}) .onReceive(ticker.objectWillChange) { (_) in // Stop timer and reset the start date if the button in not pressed @@ -456,8 +460,11 @@ struct ChatBubbleView: View { } self.timePassed = self.ticker.timeIntervalSinceStarted - withAnimation { - conversationViewModel.selectedMessage = eventLogMessage + + if !self.conversationViewModel.isSwiping { + withAnimation { + conversationViewModel.selectedMessage = eventLogMessage + } } } } else if !eventLogMessage.eventModel.text.isEmpty { diff --git a/Linphone/UI/Main/Conversations/Fragments/UIList.swift b/Linphone/UI/Main/Conversations/Fragments/UIList.swift index 998629e39..e7040c5d3 100644 --- a/Linphone/UI/Main/Conversations/Fragments/UIList.swift +++ b/Linphone/UI/Main/Conversations/Fragments/UIList.swift @@ -444,6 +444,19 @@ struct UIList: UIViewRepresentable { tableViewCell.backgroundColor = UIColor(.white) let row = sections[indexPath.section].rows[indexPath.row] + + let pan = CustomPanRecognizer() + pan.onBeginSwipe = { [self] in + self.parent.conversationViewModel.isSwiping = true + DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) { + self.parent.conversationViewModel.isSwiping = false + } + } + + if !(tableViewCell.gestureRecognizers?.contains(where: { $0 is CustomPanRecognizer }) ?? false) { + tableViewCell.addGestureRecognizer(pan) + } + if #available(iOS 16.0, *) { tableViewCell.contentConfiguration = UIHostingConfiguration { ChatBubbleView(eventLogMessage: row, geometryProxy: geometryProxy) @@ -492,7 +505,6 @@ 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) completionHandler(true) @@ -597,6 +609,25 @@ final class ChatViewModel: ObservableObject { didSendMessage(message) } } + +class CustomPanRecognizer: UIPanGestureRecognizer, UIGestureRecognizerDelegate { + var onBeginSwipe: (() -> Void)? + + override init(target: Any?, action: Selector?) { + super.init(target: target, action: action) + self.delegate = self + self.cancelsTouchesInView = false + } + + func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool { + let velocity = self.velocity(in: self.view) + if abs(velocity.x) > abs(velocity.y) { + onBeginSwipe?() + } + return false + } +} + // swiftlint:enable large_tuple // swiftlint:enable line_length // swiftlint:enable cyclomatic_complexity diff --git a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift index 2571d7827..cfe860eb0 100644 --- a/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift +++ b/Linphone/UI/Main/Conversations/ViewModel/ConversationViewModel.swift @@ -103,6 +103,8 @@ class ConversationViewModel: ObservableObject { @Published var attachments: [Attachment] = [] @Published var attachmentTransferInProgress: Attachment? + @Published var isSwiping = false + struct SheetCategory: Identifiable { let id = UUID() let name: String