Skip to content

Instantly share code, notes, and snippets.

@apatronl
Created May 2, 2024 00:42
Show Gist options
  • Save apatronl/c4c4235ce39f3ba38de9f8b89dc41ddf to your computer and use it in GitHub Desktop.
Save apatronl/c4c4235ce39f3ba38de9f8b89dc41ddf to your computer and use it in GitHub Desktop.
struct ChatMessagesList: View {
@Bindable var viewModel: ChatViewModel
@State private var loadingViewId: UUID? = UUID()
var body: some View {
ScrollView {
ForEach(viewModel.messages) { message in
MessageCell(message: message)
.padding(message.role.padding)
.id(message.id)
}
if viewModel.waitingForResponse {
HStack {
LoadingView()
Spacer()
}
.id(loadingViewId)
.padding(.leading, 8)
}
}
.scrollPosition(id: viewModel.waitingForResponse ? $loadingViewId : $viewModel.scrollPosition, anchor: .bottom)
.defaultScrollAnchor(.bottom)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment