Add an IP address textfield and conditionally enable the listen button on validating the IP address (not implemented yet).

This commit is contained in:
Jeremy Rand 2021-07-16 23:12:01 -04:00
parent 7f8328cc9b
commit 65ffb20ac7
2 changed files with 15 additions and 1 deletions

View File

@ -10,7 +10,10 @@ import Speech
struct ContentView: View {
@State private var listening = false
@State private var listenEnabled = false
@State private var textHeard = ""
@State private var ipAddress = ""
@State private var isEditing = false
private let speechRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))!
@ -22,6 +25,12 @@ struct ContentView: View {
var body: some View {
VStack {
TextField("IP Address", text: $ipAddress) { isEditing in
self.isEditing = isEditing
} onCommit: {
validate(destination: ipAddress)
}
.padding()
Label(textHeard, systemImage:"")
.labelStyle(TitleOnlyLabelStyle())
.padding()
@ -31,9 +40,14 @@ struct ContentView: View {
.padding()
.background(listening ? Color.red : Color.white)
.foregroundColor(listening ? .black : .blue)
.disabled(listenEnabled == false)
}
}
func validate(destination : String) {
listenEnabled = true
}
func listen() {
self.listening.toggle()
if (self.listening) {

View File

@ -17,7 +17,7 @@
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>29</string>
<string>36</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSSpeechRecognitionUsageDescription</key>