Skip to content

Instantly share code, notes, and snippets.

@apatronl
Last active May 1, 2024 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apatronl/506da11c24d880bafba520a44ba26f5c to your computer and use it in GitHub Desktop.
Save apatronl/506da11c24d880bafba520a44ba26f5c to your computer and use it in GitHub Desktop.
@MainActor
@Observable
class ChatViewModel {
// ...
var scrollPosition: UUID? = nil
func sendMessage() {
guard canSendMessage else { return }
// In a real chat app this would make a server call to send the message
let message = Message(role: .sender, text: draftMessage)
messages.append(message)
scrollPosition = message.id // Set scroll position to newly sent message
draftMessage.removeAll()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment