Simplified LoginDialog view

This commit is contained in:
dankito 2020-10-17 19:50:16 +02:00
parent 6759f3d319
commit cf0d721a1b
1 changed files with 30 additions and 30 deletions

View File

@ -37,52 +37,36 @@ struct LoginDialog: View {
var body: some View {
VStack {
if needsFaceIDToUnlockApp {
VStack {
Spacer()
Text(loginReason ?? "To unlock app please authenticate with FaceID")
.multilineTextAlignment(.center)
.padding()
.padding(.bottom, 30)
Spacer()
Text(authenticationReason)
.multilineTextAlignment(.center)
.padding(.bottom, 0)
FaceIDButton(50, self.loginWithBiometricAuthentication)
Spacer()
}
if needsFaceIDToUnlockApp {
FaceIDButton(50, self.loginWithBiometricAuthentication)
.padding(.top, 30)
}
else if needsTouchIDToUnlockApp {
VStack {
Spacer()
Text(loginReason ?? "To unlock app please authenticate with TouchID")
.multilineTextAlignment(.center)
.padding()
.padding(.bottom, 35)
TouchIDButton(self.loginWithBiometricAuthentication)
Spacer()
}
TouchIDButton(self.loginWithBiometricAuthentication)
.padding(.top, 35)
}
else {
Text(loginReason ?? "To unlock app please enter your password")
.multilineTextAlignment(.center)
.padding()
.padding(.bottom, 0)
Form {
Section {
LabelledUIKitTextField(label: "Password", text: $enteredPassword, placeholder: "Enter your password", isPasswordField: true, focusOnStart: true,
actionOnReturnKeyPress: { self.loginWithPasswordOnReturnKeyPress() })
}
Section {
Button("Login") { self.loginWithPassword() }
.alignHorizontally(.center)
}
}
.padding(.top, 0)
}
Spacer()
}
.showNavigationBarTitle("Login Dialog title")
.navigationBarItems(leading: allowCancellingLogin == false ? nil : createCancelButton {
@ -91,6 +75,22 @@ struct LoginDialog: View {
}
private var authenticationReason: LocalizedStringKey {
if let loginReason = loginReason {
return loginReason
}
if needsFaceIDToUnlockApp {
return LocalizedStringKey("To unlock app please authenticate with FaceID")
}
else if needsTouchIDToUnlockApp {
return LocalizedStringKey("To unlock app please authenticate with TouchID")
}
return LocalizedStringKey("To unlock app please enter your password")
}
private func loginWithBiometricAuthentication() {
authenticationService.loginUserWithBiometric("Authenticate with biometrics to unlock app reason", self.handleAuthenticationResult)
}