I want to be able to display the system keyboard and my app take inputs from the keyboard without using a TextField
or the like. My simple example app is as follows:
struct TypingGameView: View {
let text = “Some example text”
@State var displayedText: String = ""
var body: some View {
Text(displayedText)
}
}
I'm making a memorization app, so when I user types an input on the keyboard, it should take the next word from text
and add it to displayedText
to display onscreen. The keyboard should automatically pop up when the view is displayed.
If there is, a native SwiftUI solution would be great, something maybe as follows:
struct TypingGameView: View {
let text = “Some example text”
@State var displayedText: String = ""
var body: some View {
Text(displayedText)
.onAppear {
showKeyboard()
}
.onKeyboardInput { keyPress in
displayedText += keyPress
}
}
}
A TextField
could work if there is some way to 1. Make it so that whatever is typed does not display in the TextField
, 2. Disable tapping the text (e.g. moving the cursor or selecting), 3. Disable deleting text.