Created
May 2, 2024 00:42
-
-
Save apatronl/c4c4235ce39f3ba38de9f8b89dc41ddf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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