Skip to content

Commit

Permalink
fix: improve chat scroll behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
didhd committed Feb 19, 2025
1 parent 0296ec7 commit 1c41d73
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Amazon Bedrock Client for Mac/Views/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ struct ChatView: View {
messageList
}
.onChange(of: viewModel.messages) { _ in
guard isAtBottom else { return }
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) {
if isAtBottom {
// If the user was at bottom, wait briefly for layout and scroll down again
if isAtBottom {
Task {
try? await Task.sleep(nanoseconds: 50_000_000) // 0.05s
withAnimation {
proxy.scrollTo("Bottom", anchor: .bottom)
}
}
}
}
// Scroll to bottom whenever the count of messages changes
.onChange(of: viewModel.messages.count) { _ in
withAnimation {
proxy.scrollTo("Bottom", anchor: .bottom)
Expand Down

0 comments on commit 1c41d73

Please sign in to comment.