This commit is contained in:
Woit 2024-12-09 20:28:46 +01:00
parent 868f326bbc
commit 55b3469284
5 changed files with 14 additions and 9 deletions

View file

@ -2,7 +2,7 @@ import Foundation
import SwiftUI
struct ConversationMessageRow: View {
@EnvironmentObject var chatWrapper: WrapperXMPP
@ObservedObject var chatWrapper: WrapperChat
let message: Message
@State private var offset: CGSize = .zero
@ -51,7 +51,7 @@ struct ConversationMessageRow: View {
}
if value.translation.width <= targetWidth {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.02) {
// messages.replyText = message.body ?? ""
chatWrapper.replyText = message.body
}
}
}

View file

@ -22,6 +22,7 @@ struct ConversationScreen: View {
leftButton: .init(
image: Image(systemName: "chevron.left"),
action: {
chatWrapper.deactivate()
router.dismissScreen()
}
),
@ -30,8 +31,7 @@ struct ConversationScreen: View {
image: Image(systemName: "gear"),
action: {
router.showScreen(.push) { _ in
ConversationSettingsScreen()
.environmentObject(chatWrapper)
ConversationSettingsScreen(chatWrapper: chatWrapper)
.navigationBarHidden(true)
}
}
@ -51,7 +51,7 @@ struct ConversationScreen: View {
ScrollView {
LazyVStack(spacing: 0) {
ForEach(chatWrapper.messages) { message in
ConversationMessageRow(message: message)
ConversationMessageRow(chatWrapper: chatWrapper, message: message)
.id(message.id)
.flip()
.onAppear {
@ -116,8 +116,7 @@ struct ConversationScreen: View {
}
}
.safeAreaInset(edge: .bottom, spacing: 0) {
ConversationTextInput(autoScroll: $autoScroll)
.environmentObject(chatWrapper)
ConversationTextInput(chatWrapper: chatWrapper, autoScroll: $autoScroll)
}
.onLoad {
if chatWrapper.messages.isEmpty {

View file

@ -3,7 +3,7 @@ import Foundation
import SwiftUI
struct ConversationSettingsScreen: View {
@EnvironmentObject var chatWrapper: WrapperChat
@ObservedObject var chatWrapper: WrapperChat
@Environment(\.router) var router
var body: some View {

View file

@ -3,7 +3,7 @@ import UIKit
struct ConversationTextInput: View {
@Environment(\.router) var router
@EnvironmentObject var chatWrapper: WrapperChat
@ObservedObject var chatWrapper: WrapperChat
@State private var messageStr = ""
@FocusState private var isFocused: Bool

View file

@ -107,6 +107,12 @@ final class WrapperChat: ObservableObject {
}
}
}
func deactivate() {
messages = []
notificationObservers.forEach { NotificationCenter.default.removeObserver($0) }
print("Chat wrapper unsubscribed")
}
}
private extension WrapperChat {