Skip to content

Commit daf6e9e

Browse files
author
Achyut Kumar M
committed
replace toggle and modify overlay
1 parent c9848ed commit daf6e9e

File tree

2 files changed

+33
-55
lines changed

2 files changed

+33
-55
lines changed

GoInfoGame/GoInfoGame/Login/PasswordAuthenticationPopupView.swift

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,15 @@
88
import SwiftUI
99
import LocalAuthentication
1010

11-
import SwiftUI
12-
1311
struct PasswordAuthenticationPopupView: View {
12+
@ObservedObject var viewModel: PasswordAuthenticationViewModel
1413
let onSuccess: () -> Void
1514
let onCancel: () -> Void
16-
17-
@StateObject private var viewModel = PasswordAuthenticationViewModel()
18-
15+
let onFailure: (String) -> Void
16+
1917
var body: some View {
2018
ZStack {
21-
Color.black.opacity(0.4)
22-
.ignoresSafeArea()
23-
.onTapGesture {
24-
onCancel()
25-
}
19+
Color.black.opacity(0.4).ignoresSafeArea()
2620

2721
VStack(spacing: 16) {
2822
Text("Enable Biometric Login")
@@ -43,22 +37,21 @@ struct PasswordAuthenticationPopupView: View {
4337
Button("Continue") {
4438
handleContinue()
4539
}
46-
.frame(maxWidth: .infinity)
4740
.padding()
41+
.frame(maxWidth: .infinity)
4842
.background(Color.blue)
4943
.foregroundColor(.white)
5044
.cornerRadius(8)
5145

5246
Button("Cancel") {
5347
onCancel()
5448
}
55-
.foregroundColor(.gray)
5649
.padding(.top, 4)
5750
}
5851
.padding()
5952
.background(Color.white)
6053
.cornerRadius(16)
61-
.padding(.horizontal, 40)
54+
.padding(40)
6255

6356
if viewModel.isLoading {
6457
ProgressView("Logging in...")
@@ -70,33 +63,33 @@ struct PasswordAuthenticationPopupView: View {
7063

7164
private func handleContinue() {
7265
let environment = APIConfiguration.shared.environment
73-
guard let username = KeychainManager.load(.username, for: environment) else {
74-
viewModel.errorMessage = "Username not found"
75-
return
76-
}
66+
let username = KeychainManager.load(.username, for: environment) ?? ""
7767

7868
viewModel.performBiometricEnrollment(
7969
username: username,
8070
environment: environment,
8171
onSuccess: {
8272
onSuccess()
8373
},
84-
onFailure: {
85-
viewModel.errorMessage = "Failed to enroll"
74+
onFailure: { error in
75+
// Nothing here; viewModel will handle errorMessage
76+
viewModel.errorMessage = error
77+
onFailure(error)
8678
}
8779
)
8880
}
8981
}
9082

9183

9284

93-
#Preview {
94-
PasswordAuthenticationPopupView(
95-
onSuccess: {
96-
print("Biometric setup successful")
97-
},
98-
onCancel: {
99-
print("Biometric setup cancelled")
100-
}
101-
)
102-
}
85+
86+
//#Preview {
87+
// PasswordAuthenticationPopupView(
88+
// viewModel: <#PasswordAuthenticationViewModel#>, onSuccess: {
89+
// print("Biometric setup successful")
90+
// },
91+
// onCancel: {
92+
// print("Biometric setup cancelled")
93+
// }
94+
// )
95+
//}

GoInfoGame/GoInfoGame/UserProfile/View/UserProfileView.swift

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ struct UserProfileView: View {
2020

2121
@State private var showPasswordAuthenticationView: Bool = false
2222

23+
@StateObject private var passwordAuthenticationViewModel = PasswordAuthenticationViewModel()
24+
2325
private var biometricToggleText: String {
2426
let context = LAContext()
2527
_ = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
@@ -55,27 +57,8 @@ struct UserProfileView: View {
5557
}
5658
.padding([.bottom], 200)
5759

58-
Toggle(isOn: $useBiometricID) {
59-
Text(biometricToggleText)
60-
}
61-
.gesture(
62-
TapGesture()
63-
.onEnded {
64-
userManuallyToggled = true
65-
}
66-
)
67-
.onChange(of: useBiometricID) { isEnabled in
68-
let env = APIConfiguration.shared.environment
69-
70-
guard userManuallyToggled else { return }
71-
userManuallyToggled = false
72-
73-
if isEnabled {
74-
75-
showPasswordAuthenticationView = true
76-
} else {
77-
useBiometricID = false
78-
}
60+
BiometricToggleView(isEnabled: $useBiometricID) {
61+
showPasswordAuthenticationView = true
7962
}
8063
.padding([.bottom], 30)
8164

@@ -89,17 +72,19 @@ struct UserProfileView: View {
8972
}
9073
.overlay {
9174
if showPasswordAuthenticationView {
92-
PasswordAuthenticationView {
75+
PasswordAuthenticationPopupView(viewModel: passwordAuthenticationViewModel) {
9376
useBiometricID = true
94-
SessionManager.shared.setBiometricEnabled(true, for: APIConfiguration.shared.environment)
9577
showPasswordAuthenticationView = false
78+
print("TO DO : Handle password authentication")
9679
} onCancel: {
9780
useBiometricID = false
98-
SessionManager.shared.setBiometricEnabled(false, for: APIConfiguration.shared.environment)
81+
showPasswordAuthenticationView = false
82+
} onFailure: { error in
83+
useBiometricID = false
9984
showPasswordAuthenticationView = false
85+
10086
}
101-
.transition(.scale)
102-
.zIndex(1)
87+
10388
}
10489
}
10590
}

0 commit comments

Comments
 (0)