I tried the same code with an Int instead of messages, it worked.
When I try and use the message object, for some reason it's not liking it. Even though the .id is UUID().
The messages appear in scrollView and can be scrolled manually although it's not scrolling automatically to the bottom once a message is added.
I've tried .self instead of .id in the ForEach, flipping the order of ScrollView and ScrollViewReader, not using a .id on MessageRow, downcast to UUID inside scrollTo, nothing seems to be working...
What am I missing?
Thank you in advance!
ScrollViewReader { scrollView in
ScrollView(.vertical) {
LazyVStack {
ForEach(groupViewModel.messages) { message in
MessageRowView(message: message)
.padding(.leading)
}
}
.onAppear {
if !groupViewModel.messages.isEmpty {
if let last = groupViewModel.messages.last {
scrollView.scrollTo(last)
}
}
}
}
}
struct Message: Codable, Equatable, Identifiable, Hashable {
let id: UUID
let sender: FSUser
let message: String
let sendDate: Date
}