diff --git a/Kordophone/Shared/ConversationView.swift b/Kordophone/Shared/ConversationView.swift index c5e3923..f3361ef 100644 --- a/Kordophone/Shared/ConversationView.swift +++ b/Kordophone/Shared/ConversationView.swift @@ -7,18 +7,25 @@ struct ConversationView : View { var messages: [Message] var body: some View { - ScrollView { - LazyVStack { - ForEach(messages) { message in - if message.sentByMe { - Spacer() - } - MessageView(message: message) - if !message.sentByMe { - Spacer() + ScrollViewReader { proxy in + ScrollView { + LazyVStack { + ForEach(messages) { message in + if message.sentByMe { + Spacer() + } + MessageView(message: message) + .id(message) + if !message.sentByMe { + Spacer() + } } } } + .navigationTitle(conversation.effectiveDisplayName) + .onChange(of: messages) { newValue in + proxy.scrollTo(newValue.last, anchor: .bottom) + } } } } @@ -29,6 +36,7 @@ struct ConversationViewWrapper : View { @EnvironmentObject private var connection: Connection private func refresh() { + messages.removeAll() Task { self.messages = await connection.messages(in: conversation) ?? .init() }