-
Notifications
You must be signed in to change notification settings - Fork 488
refactor: improve UI for password prompt & password recovery Views #1259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2bbc9e3
176f3eb
b4ea600
03ebaf2
c013f34
b738cf5
03aeb61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,50 +11,65 @@ public struct AuthPickerView { | |
| authService.authenticationFlow = authService | ||
| .authenticationFlow == .login ? .signUp : .login | ||
| } | ||
| } | ||
|
|
||
| extension AuthPickerView: View { | ||
| public var body: some View { | ||
| VStack { | ||
| @ViewBuilder | ||
| private var authPickerTitleView: some View { | ||
| if authService.authView == .authPicker { | ||
| Text(authService.string.authPickerTitle) | ||
| .font(.largeTitle) | ||
| .fontWeight(.bold) | ||
| .padding() | ||
| if authService.authenticationState == .authenticated { | ||
| SignedInView() | ||
| } else if authService.authView == .passwordRecovery { | ||
| PasswordRecoveryView() | ||
| } else if authService.authView == .emailLink { | ||
| EmailLinkView() | ||
| } else { | ||
| if authService.emailSignInEnabled { | ||
| Text(authService.authenticationFlow == .login ? authService.string | ||
| .emailLoginFlowLabel : authService.string.emailSignUpFlowLabel) | ||
| Divider() | ||
| EmailAuthView() | ||
| } | ||
| VStack { | ||
| authService.renderButtons() | ||
| }.padding(.horizontal) | ||
| if authService.emailSignInEnabled { | ||
| Divider() | ||
| HStack { | ||
| Text(authService | ||
| .authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel : | ||
| authService.string.alreadyHaveAnAccountLabel) | ||
| Button(action: { | ||
| withAnimation { | ||
| switchFlow() | ||
| } | ||
| }) { | ||
| Text(authService.authenticationFlow == .signUp ? authService.string | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension AuthPickerView: View { | ||
| public var body: some View { | ||
| ScrollView { | ||
| VStack { | ||
| authPickerTitleView | ||
| if authService.authenticationState == .authenticated { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could do this slightly more elegantly with a switch authService.authView {
case .passwordRecovery:
// ...
case .emailLink:
// ...
}
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using switch statement: The only thing I don't like is including the default case at the end to satisfy compiler as we're not using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can put
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| SignedInView() | ||
| } else { | ||
| switch authService.authView { | ||
| case .passwordRecovery: | ||
| PasswordRecoveryView() | ||
| case .emailLink: | ||
| EmailLinkView() | ||
| case .authPicker: | ||
| if authService.emailSignInEnabled { | ||
| Text(authService.authenticationFlow == .login ? authService.string | ||
| .emailLoginFlowLabel : authService.string.emailSignUpFlowLabel) | ||
| .fontWeight(.semibold) | ||
| .foregroundColor(.blue) | ||
| Divider() | ||
| EmailAuthView() | ||
| } | ||
| VStack { | ||
| authService.renderButtons() | ||
| }.padding(.horizontal) | ||
| if authService.emailSignInEnabled { | ||
| Divider() | ||
| HStack { | ||
| Text(authService | ||
| .authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel : | ||
| authService.string.alreadyHaveAnAccountLabel) | ||
| Button(action: { | ||
| withAnimation { | ||
| switchFlow() | ||
| } | ||
| }) { | ||
| Text(authService.authenticationFlow == .signUp ? authService.string | ||
| .emailLoginFlowLabel : authService.string.emailSignUpFlowLabel) | ||
| .fontWeight(.semibold) | ||
| .foregroundColor(.blue) | ||
| } | ||
| } | ||
| } | ||
| PrivacyTOCsView(displayMode: .footer) | ||
| Text(authService.errorMessage).foregroundColor(.red) | ||
| default: | ||
| // TODO: - possibly refactor this, see: https://github.com/firebase/FirebaseUI-iOS/pull/1259#discussion_r2105473437 | ||
| EmptyView() | ||
| } | ||
| PrivacyTOCsView(displayMode: .footer) | ||
| Text(authService.errorMessage).foregroundColor(.red) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import FirebaseCore | ||
| import SwiftUI | ||
|
|
||
| struct PasswordPromptSheet { | ||
|
|
@@ -9,26 +10,45 @@ struct PasswordPromptSheet { | |
| extension PasswordPromptSheet: View { | ||
| var body: some View { | ||
| VStack(spacing: 20) { | ||
| SecureField(authService.string.passwordInputLabel, text: $password) | ||
| .textFieldStyle(.roundedBorder) | ||
| Text(authService.string.confirmPasswordInputLabel) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| .font(.largeTitle) | ||
| .fontWeight(.bold) | ||
| .padding() | ||
|
|
||
| HStack { | ||
| Button(authService.string.cancelButtonLabel) { | ||
| coordinator.cancel() | ||
| } | ||
| Spacer() | ||
| Button(authService.string.okButtonLabel) { | ||
| coordinator.submit(password: password) | ||
| } | ||
| .disabled(password.isEmpty) | ||
| Divider() | ||
|
|
||
| LabeledContent { | ||
| TextField(authService.string.passwordInputLabel, text: $password) | ||
| .textInputAutocapitalization(.never) | ||
| .disableAutocorrection(true) | ||
| .submitLabel(.next) | ||
| } label: { | ||
| Image(systemName: "lock") | ||
| }.padding(.vertical, 10) | ||
| .background(Divider(), alignment: .bottom) | ||
| .padding(.bottom, 4) | ||
|
|
||
| Button(action: { | ||
| coordinator.submit(password: password) | ||
| }) { | ||
| Text(authService.string.okButtonLabel) | ||
| .padding(.vertical, 8) | ||
| .frame(maxWidth: .infinity) | ||
| } | ||
| .disabled(password.isEmpty) | ||
| .padding([.top, .bottom, .horizontal], 8) | ||
| .frame(maxWidth: .infinity) | ||
| .buttonStyle(.borderedProminent) | ||
|
|
||
| Button(authService.string.cancelButtonLabel) { | ||
| coordinator.cancel() | ||
| } | ||
| .padding(.horizontal) | ||
| } | ||
| .padding() | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| PasswordPromptSheet(coordinator: PasswordPromptCoordinator()) | ||
| FirebaseOptions.dummyConfigurationForPreview() | ||
| return PasswordPromptSheet(coordinator: PasswordPromptCoordinator()).environment(AuthService()) | ||
| } | ||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used existing "Error" title for alerts/modal.