Last active
May 1, 2024 20:09
-
-
Save apatronl/506da11c24d880bafba520a44ba26f5c 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
@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