From cf0d721a1bce777f31534daab1fc07f828ab4a1a Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 17 Oct 2020 19:50:16 +0200 Subject: [PATCH] Simplified LoginDialog view --- .../ui/dialogs/LoginDialog.swift | 60 +++++++++---------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift index 6002c203..78b4e475 100644 --- a/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift +++ b/ui/BankingiOSApp/BankingiOSApp/ui/dialogs/LoginDialog.swift @@ -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) }