Skip to content

Commit 5682768

Browse files
author
Achyut Kumar M
committed
toggle button - wip
1 parent 05e1acd commit 5682768

File tree

1 file changed

+44
-5
lines changed

1 file changed

+44
-5
lines changed

GoInfoGame/GoInfoGame/UserProfile/View/UserProfileView.swift

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ struct UserProfileView: View {
1616

1717
@State private var useBiometricID: Bool = false
1818

19+
@State private var userManuallyToggled = false
20+
21+
@State private var showPasswordAuthenticationView: Bool = false
22+
1923
private var biometricToggleText: String {
2024
let context = LAContext()
2125
_ = context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
@@ -32,41 +36,72 @@ struct UserProfileView: View {
3236

3337
var body: some View {
3438
Group {
39+
ZStack {
3540
VStack {
3641
Text("My Profile")
3742
.font(.custom("Lato-Bold", size: 25))
3843
.padding(.bottom, 50)
3944
HStack(alignment: .center, spacing: 16) {
4045
profileImage
41-
46+
4247
VStack(alignment: .leading, spacing: 4) {
4348
Text(userFullName())
4449
.font(.custom("Lato-Bold", size: 20))
4550
Text(viewModel.user?.email ?? "")
4651
.font(.custom("Lato-Regular", size: 18))
4752
}
48-
53+
4954
Spacer()
5055
}
5156
.padding([.bottom], 200)
5257

5358
Toggle(isOn: $useBiometricID) {
5459
Text(biometricToggleText)
5560
}
61+
.gesture(
62+
TapGesture()
63+
.onEnded {
64+
userManuallyToggled = true
65+
}
66+
)
5667
.onChange(of: useBiometricID) { isEnabled in
57-
if !isEnabled {
58-
SessionManager.shared.logout(environment: APIConfiguration.shared.environment, clearBiometricCreds: true)
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
5978
}
6079
}
6180
.padding([.bottom], 30)
6281

6382

6483
logOutButton
65-
84+
6685
Spacer()
6786
}
6887
.padding(20)
6988
.navigationBarTitleDisplayMode(.inline)
89+
}
90+
.overlay {
91+
if showPasswordAuthenticationView {
92+
PasswordAuthenticationView {
93+
useBiometricID = true
94+
SessionManager.shared.setBiometricEnabled(true, for: APIConfiguration.shared.environment)
95+
showPasswordAuthenticationView = false
96+
} onCancel: {
97+
useBiometricID = false
98+
SessionManager.shared.setBiometricEnabled(false, for: APIConfiguration.shared.environment)
99+
showPasswordAuthenticationView = false
100+
}
101+
.transition(.scale)
102+
.zIndex(1)
103+
}
104+
}
70105
}
71106
.onAppear {
72107
useBiometricID = SessionManager.shared.isBiometricEnabled(for: APIConfiguration.shared.environment)
@@ -94,6 +129,10 @@ struct UserProfileView: View {
94129
Button {
95130
Utilities.clearAllData()
96131

132+
if useBiometricID == false {
133+
SessionManager.shared.logout(environment: APIConfiguration.shared.environment, clearBiometricCreds: true)
134+
}
135+
97136
if let window = UIApplication.window() {
98137
window.rootViewController = UIHostingController(rootView: PosmLoginView())
99138
}

0 commit comments

Comments
 (0)