Browse Source

add enter key to log in

master
Peter Hajas 3 years ago
parent
commit
4c71da3f2d
  1. 25
      Kordophone/Shared/LoginView.swift

25
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()
}
}

Loading…
Cancel
Save