Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,22 @@ struct MessageView: View {
var body: some View {
VStack(spacing: 0) {
ScrollView {
VStack(spacing: 12) {
ForEach(0..<messages.count, id: \.self) { i in
ChatBubbleView(message: messages[i], index: i)
// Add the new scroll view reader as a child to the scrollview
ScrollViewReader { scrollView in
VStack(spacing: 12) {
ForEach(0..<messages.count, id: \.self) { i in
ChatBubbleView(message: messages[i], index: i)
}
}
.padding()
// Add a listener to the messages array to listen for changes
.onReceive(messages.publisher) { _ in
// Add animation block to animate in new message
withAnimation {
scrollView.scrollTo(messages.endIndex - 1)
}
}
}
.padding()
}

TextField("iMessage", text: $message, onCommit: { self.sendMessage() })
Expand Down