From b0ef155be8fc332dafc765cb9e443710ba6d716e Mon Sep 17 00:00:00 2001 From: fmodf Date: Thu, 27 Jun 2024 09:23:09 +0200 Subject: [PATCH] wip --- .../AppCore/XMPP/XMPPService.swift | 1 + .../View/Screens/ConversationScreen.swift | 68 ++++++++++++++++++- .../View/UIToolkit/Colors+Tappable.swift | 13 ++++ 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 ConversationsClassic/View/UIToolkit/Colors+Tappable.swift diff --git a/ConversationsClassic/AppCore/XMPP/XMPPService.swift b/ConversationsClassic/AppCore/XMPP/XMPPService.swift index c3c1904..89a2b27 100644 --- a/ConversationsClassic/AppCore/XMPP/XMPPService.swift +++ b/ConversationsClassic/AppCore/XMPP/XMPPService.swift @@ -120,6 +120,7 @@ final class XMPPService: ObservableObject { switch res { case .success: completion(true) + case .failure: completion(false) } diff --git a/ConversationsClassic/View/Screens/ConversationScreen.swift b/ConversationsClassic/View/Screens/ConversationScreen.swift index c7f13d7..b903557 100644 --- a/ConversationsClassic/View/Screens/ConversationScreen.swift +++ b/ConversationsClassic/View/Screens/ConversationScreen.swift @@ -123,6 +123,7 @@ private struct ConversationMessageRow: View { @EnvironmentObject var store: AppStore let message: Message + @State private var offset: CGSize = .zero var body: some View { VStack(spacing: 0) { @@ -143,6 +144,27 @@ private struct ConversationMessageRow: View { } .padding(.vertical, 10) .padding(.horizontal, 16) + .background(Color.clearTappable) + .offset(offset) + .gesture( + DragGesture(minimumDistance: 20, coordinateSpace: .local) + .onEnded { value in + withAnimation(.easeOut(duration: 0.1)) { + if value.translation.width < 0 { + offset = CGSize(width: -50, height: 0) + // TODO: Quick message replay here + + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + withAnimation(.easeOut(duration: 0.1)) { + offset = .zero + } + } + } else { + offset = .zero + } + } + } + ) } .sharedListRow() } @@ -200,6 +222,22 @@ struct MessageAttr: View { } } + // self.conversationLogController?.getTextOfSelectedRows(paths: [indexPath], withTimestamps: false, handler: { [weak self] texts in + // let text: String = texts.flatMap { $0.split(separator: "\n")}.map { + // if $0.starts(with: ">") { + // return ">\($0)"; + // } else { + // return "> \($0)" + // } + // }.joined(separator: "\n"); + // + // if let current = self?.messageText, !current.isEmpty { + // self?.messageText = "\(current)\n\(text)\n"; + // } else { + // self?.messageText = "\(text)\n"; + // } + // }) + // Preview #if DEBUG struct ConversationScreen_Previews: PreviewProvider { @@ -234,9 +272,35 @@ struct MessageAttr: View { date: Date(), pending: true, sentError: false ), - Message(id: "2", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for testsdfsdf sdfsdf sdfs sdf sdffsdf sdf sdf sdf sdf sdf sdff sdfffwwe ", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false, sentError: false), + Message( + id: "2", + type: .chat, + contentType: .text, + from: contact, + to: acc, + body: "this is for testsdfsdf sdfsdf sdfs sdf sdffsdf sdf sdf sdf sdf sdf sdff sdfffwwe ", + subject: nil, + thread: nil, + oobUrl: nil, + date: Date(), + pending: false, + sentError: false + ), Message(id: "3", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for test", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false, sentError: true), - Message(id: "4", type: .chat, contentType: .text, from: acc, to: contact, body: "this is for test sdfkjwek jwkjfh jwerf jdfhskjdhf jsdhfjhwefh sjdhfh fsdjhfh sd ", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false, sentError: false), + Message( + id: "4", + type: .chat, + contentType: .text, + from: acc, + to: contact, + body: "this is for test sdfkjwek jwkjfh jwerf jdfhskjdhf jsdhfjhwefh sjdhfh fsdjhfh sd ", + subject: nil, + thread: nil, + oobUrl: nil, + date: Date(), + pending: false, + sentError: false + ), Message(id: "5", type: .chat, contentType: .text, from: contact, to: acc, body: "this is for test sdfjkkeke kekkddjw;; w;edkdjfj l kjwekrjfk wef", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false, sentError: false), Message(id: "6", type: .chat, contentType: .text, from: acc, to: contact, body: "this is for testsdf dsdkkekkddn wejkjfj ", subject: nil, thread: nil, oobUrl: nil, date: Date(), pending: false, sentError: false), Message( diff --git a/ConversationsClassic/View/UIToolkit/Colors+Tappable.swift b/ConversationsClassic/View/UIToolkit/Colors+Tappable.swift new file mode 100644 index 0000000..718a3df --- /dev/null +++ b/ConversationsClassic/View/UIToolkit/Colors+Tappable.swift @@ -0,0 +1,13 @@ +import SwiftUI + +public extension Color { + static let clearTappable = Color.white.opacity(0.0001) + // static func random(randomOpacity: Bool = false) -> Color { + // Color( + // red: .random(in: 0 ... 1), + // green: .random(in: 0 ... 1), + // blue: .random(in: 0 ... 1), + // opacity: randomOpacity ? .random(in: 0 ... 1) : 1 + // ) + // } +}