wip
This commit is contained in:
parent
31592a0e17
commit
c3bd783769
|
@ -113,10 +113,7 @@ final class XMPPService: ObservableObject {
|
|||
message.to = JID(to)
|
||||
message.body = message.body
|
||||
|
||||
client.module(MessageModule.self)
|
||||
.chatManager
|
||||
.chat(for: client.context, with: JID(to).bareJid)?
|
||||
.send(message: message) { res in
|
||||
client.context.writer.write(message) { res in
|
||||
switch res {
|
||||
case .success:
|
||||
completion(true)
|
||||
|
|
|
@ -6,6 +6,8 @@ import SwiftUI
|
|||
struct ConversationScreen: View {
|
||||
@EnvironmentObject var store: AppStore
|
||||
|
||||
@State private var autoScroll = true
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
// Background color
|
||||
|
@ -20,14 +22,45 @@ struct ConversationScreen: View {
|
|||
// Msg list
|
||||
let messages = store.state.conversationsState.currentMessages
|
||||
if !messages.isEmpty {
|
||||
ScrollViewReader { proxy in
|
||||
List {
|
||||
ForEach(messages) { message in
|
||||
ConversationMessageRow(message: message)
|
||||
.id(message.id)
|
||||
.onAppear {
|
||||
if message.id == messages.last?.id {
|
||||
autoScroll = true
|
||||
}
|
||||
}
|
||||
.onDisappear {
|
||||
if message.id == messages.last?.id {
|
||||
autoScroll = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.background(Color.Main.backgroundLight)
|
||||
.scrollDismissesKeyboard(.immediately)
|
||||
.scrollIndicators(.hidden)
|
||||
.onChange(of: messages) { _ in
|
||||
if autoScroll {
|
||||
withAnimation {
|
||||
proxy.scrollTo(messages.last?.id, anchor: .bottom)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: autoScroll) { new in
|
||||
if new {
|
||||
withAnimation {
|
||||
proxy.scrollTo(messages.last?.id, anchor: .bottom)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
proxy.scrollTo(messages.last?.id, anchor: .bottom)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Spacer()
|
||||
}
|
||||
|
@ -35,6 +68,15 @@ struct ConversationScreen: View {
|
|||
.onTapGesture {
|
||||
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
||||
}
|
||||
|
||||
// Jump to last button
|
||||
if !autoScroll {
|
||||
Button {
|
||||
autoScroll = true
|
||||
} label: {
|
||||
Text("TEST")
|
||||
}
|
||||
}
|
||||
}
|
||||
.safeAreaInset(edge: .bottom, spacing: 0) {
|
||||
ConversationTextInput()
|
||||
|
|
Loading…
Reference in a new issue