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