Skip to content

Commit

Permalink
[iOS] - Send out the message when the user presses command + return k…
Browse files Browse the repository at this point in the history
…eys on a keyboard. (#677)

[iOS] - Send out the message when the user presses Command + return keys on a keyboard.
  • Loading branch information
JakeLin authored Aug 7, 2023
1 parent 18b0bdd commit 26a8b41
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions ios/MLCChat/ChatView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ChatView.swift

import SwiftUI

import GameController

struct ChatView: View {
@State var inputMessage: String = ""
Expand Down Expand Up @@ -96,10 +96,14 @@ struct ChatView: View {
.textFieldStyle(RoundedBorderTextFieldStyle())
.frame(minHeight: CGFloat(30))
.focused($inputIsFocused)
.onSubmit {
let isKeyboardConnected = GCKeyboard.coalesced != nil
if isKeyboardConnected {
send()
}
}
Button("Send") {
self.inputIsFocused = false
chatState.requestGenerate(prompt: inputMessage)
inputMessage = ""
send()
}.bold().disabled(!(chatState.chattable() && inputMessage != ""))
}.frame(minHeight: CGFloat(70)).padding()
}
Expand All @@ -126,3 +130,11 @@ struct ChatView: View {
}
}
}

private extension ChatView {
func send() {
inputIsFocused = false
chatState.requestGenerate(prompt: inputMessage)
inputMessage = ""
}
}

0 comments on commit 26a8b41

Please sign in to comment.