mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 02:58:07 +00:00
Fix conflict between swipe and long press on message
This commit is contained in:
parent
2a04fb7254
commit
67041c20f8
3 changed files with 48 additions and 8 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue