From 65ffb20ac7b4d0b2fb3bf46fc47aeccae3348474 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Fri, 16 Jul 2021 23:12:01 -0400 Subject: [PATCH] Add an IP address textfield and conditionally enable the listen button on validating the IP address (not implemented yet). --- ListenerApp/ContentView.swift | 14 ++++++++++++++ ListenerApp/Info.plist | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ListenerApp/ContentView.swift b/ListenerApp/ContentView.swift index ef232fe..49086bd 100644 --- a/ListenerApp/ContentView.swift +++ b/ListenerApp/ContentView.swift @@ -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) { diff --git a/ListenerApp/Info.plist b/ListenerApp/Info.plist index 298ef92..51f2e1a 100644 --- a/ListenerApp/Info.plist +++ b/ListenerApp/Info.plist @@ -17,7 +17,7 @@ CFBundleShortVersionString 1.0 CFBundleVersion - 29 + 36 LSRequiresIPhoneOS NSSpeechRecognitionUsageDescription