Skip to content

Commit 176f3eb

Browse files
chore: furhter UI tweaks
1 parent 2bbc9e3 commit 176f3eb

File tree

3 files changed

+96
-53
lines changed

3 files changed

+96
-53
lines changed

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Utils/StringUtils.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,11 @@ public class StringUtils {
350350
public var privacyPolicyLabel: String {
351351
return localizedString(for: "PrivacyPolicy")
352352
}
353+
354+
/// Alert Error title
355+
/// found in:
356+
/// PasswordRecoveryView
357+
public var alertErrorTitle: String {
358+
return localizedString(for: "Error")
359+
}
353360
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/AuthPickerView.swift

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,50 @@ public struct AuthPickerView {
1515

1616
extension AuthPickerView: View {
1717
public var body: some View {
18-
VStack {
19-
Text(authService.string.authPickerTitle)
20-
.font(.largeTitle)
21-
.fontWeight(.bold)
22-
.padding()
23-
if authService.authenticationState == .authenticated {
24-
SignedInView()
25-
} else if authService.authView == .passwordRecovery {
26-
PasswordRecoveryView()
27-
} else if authService.authView == .emailLink {
28-
EmailLinkView()
29-
} else {
30-
if authService.emailSignInEnabled {
31-
Text(authService.authenticationFlow == .login ? authService.string
32-
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
33-
Divider()
34-
EmailAuthView()
18+
ScrollView {
19+
VStack {
20+
if authService.authView == .authPicker {
21+
Text(authService.string.authPickerTitle)
22+
.font(.largeTitle)
23+
.fontWeight(.bold)
24+
.padding()
3525
}
36-
VStack {
37-
authService.renderButtons()
38-
}.padding(.horizontal)
39-
if authService.emailSignInEnabled {
40-
Divider()
41-
HStack {
42-
Text(authService
43-
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
44-
authService.string.alreadyHaveAnAccountLabel)
45-
Button(action: {
46-
withAnimation {
47-
switchFlow()
26+
if authService.authenticationState == .authenticated {
27+
SignedInView()
28+
} else if authService.authView == .passwordRecovery {
29+
PasswordRecoveryView()
30+
} else if authService.authView == .emailLink {
31+
EmailLinkView()
32+
} else {
33+
if authService.emailSignInEnabled {
34+
Text(authService.authenticationFlow == .login ? authService.string
35+
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
36+
Divider()
37+
EmailAuthView()
38+
}
39+
VStack {
40+
authService.renderButtons()
41+
}.padding(.horizontal)
42+
if authService.emailSignInEnabled {
43+
Divider()
44+
HStack {
45+
Text(authService
46+
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
47+
authService.string.alreadyHaveAnAccountLabel)
48+
Button(action: {
49+
withAnimation {
50+
switchFlow()
51+
}
52+
}) {
53+
Text(authService.authenticationFlow == .signUp ? authService.string
54+
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
55+
.fontWeight(.semibold)
56+
.foregroundColor(.blue)
4857
}
49-
}) {
50-
Text(authService.authenticationFlow == .signUp ? authService.string
51-
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
52-
.fontWeight(.semibold)
53-
.foregroundColor(.blue)
5458
}
59+
PrivacyTOCsView(displayMode: .footer)
60+
Text(authService.errorMessage).foregroundColor(.red)
5561
}
56-
PrivacyTOCsView(displayMode: .footer)
57-
Text(authService.errorMessage).foregroundColor(.red)
5862
}
5963
}
6064
}

FirebaseSwiftUI/FirebaseAuthSwiftUI/Sources/Views/PasswordRecoveryView.swift

Lines changed: 49 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
11
import FirebaseCore
22
import SwiftUI
33

4+
enum PasswordRecoveryResult: Identifiable {
5+
case success
6+
case failure
7+
8+
var id: String {
9+
switch self {
10+
case .success: return "success"
11+
case .failure: return "failure"
12+
}
13+
}
14+
}
15+
416
public struct PasswordRecoveryView {
517
@Environment(AuthService.self) private var authService
618
@State private var email = ""
7-
@State private var showModal = false
19+
@State private var result: PasswordRecoveryResult?
820

921
public init() {}
1022

1123
private func sendPasswordRecoveryEmail() async {
1224
do {
1325
try await authService.sendPasswordRecoveryEmail(to: email)
14-
showModal = true
15-
} catch {}
26+
result = .success
27+
} catch {
28+
result = .failure
29+
}
1630
}
1731
}
1832

@@ -46,30 +60,48 @@ extension PasswordRecoveryView: View {
4660
.frame(maxWidth: .infinity)
4761
}
4862
.disabled(!CommonUtils.isValidEmail(email))
49-
.padding([.top, .bottom], 8)
63+
.padding([.top, .bottom, .horizontal], 8)
5064
.frame(maxWidth: .infinity)
5165
.buttonStyle(.borderedProminent)
52-
}.sheet(isPresented: $showModal) {
66+
}.sheet(item: $result) { result in
5367
VStack {
54-
Text(authService.string.passwordRecoveryEmailSentTitle)
55-
.font(.largeTitle)
56-
.fontWeight(.bold)
57-
.padding()
58-
Text(authService.string.passwordRecoveryHelperMessage)
68+
switch result {
69+
case .success:
70+
Text(authService.string.passwordRecoveryEmailSentTitle)
71+
.font(.largeTitle)
72+
.fontWeight(.bold)
73+
.padding()
74+
Text(authService.string.passwordRecoveryHelperMessage)
75+
.padding()
76+
77+
Divider()
78+
79+
Text(authService.string.passwordRecoveryEmailSentMessage)
80+
.padding()
81+
Button(authService.string.okButtonLabel) {
82+
self.result = nil
83+
}
5984
.padding()
85+
case .failure:
86+
Text(authService.string.alertErrorTitle)
87+
.font(.title)
88+
.fontWeight(.semibold)
89+
.padding()
6090

61-
Divider()
91+
Divider()
6292

63-
Text(authService.string.passwordRecoveryEmailSentMessage)
93+
Text(authService.errorMessage)
94+
.padding()
95+
96+
Divider()
97+
98+
Button(authService.string.okButtonLabel) {
99+
self.result = nil
100+
}
64101
.padding()
65-
Button(authService.string.okButtonLabel) {
66-
showModal = false
67102
}
68-
.padding()
69103
}
70104
.padding()
71-
}.onOpenURL { _ in
72-
// move the user to email/password View
73105
}
74106
.navigationBarItems(leading: Button(action: {
75107
authService.authView = .authPicker

0 commit comments

Comments
 (0)