From 4c71da3f2dead52e84eb6d7b81297d34602acb78 Mon Sep 17 00:00:00 2001 From: Peter Hajas Date: Tue, 17 May 2022 13:39:33 -0400 Subject: [PATCH] add enter key to log in --- Kordophone/Shared/LoginView.swift | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Kordophone/Shared/LoginView.swift b/Kordophone/Shared/LoginView.swift index 9c73375..18a97c8 100644 --- a/Kordophone/Shared/LoginView.swift +++ b/Kordophone/Shared/LoginView.swift @@ -7,19 +7,38 @@ struct LoginView : View { @AppStorage("username") var username: String = "" @AppStorage("password") var password: String = "" + @State private var loggingIn = false + var onLogin: (ConnectionInfo) -> Void = { _ in } + private func login() { + loggingIn = true + onLogin(ConnectionInfo(serverAddress: serverAddress, + credentials: Credentials(username: username, + password: password))) + } + var body: some View { VStack { TextField("server", text: $serverAddress) + .onSubmit { + login() + } TextField("username", text: $username) + .onSubmit { + login() + } SecureField("password", text: $password) + .onSubmit { + login() + } Button("Login") { - onLogin(ConnectionInfo(serverAddress: serverAddress, - credentials: Credentials(username: username, - password: password))) + login() } + .keyboardShortcut(.return) } + .disabled(loggingIn) + .animation(.spring(), value: loggingIn) .padding() } }