Skip to content

refactor: UI tweaks #1255

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public enum AuthView {
case authPicker
case passwordRecovery
case emailLink
case phoneAuth
case updatePassword
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public class StringUtils {
/// found in:
/// - SignInWithFacebookButton
public var facebookLoginButtonLabel: String {
return localizedString(for: "Continue with Facebook")
return localizedString(for: "Sign in with Facebook")
}

/// Facebook provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,51 @@ public struct AuthPickerView<Content: View> {

extension AuthPickerView: View {
public var body: some View {
VStack {
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 {
Text(authService.authenticationFlow == .login ? authService.string
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
VStack { Divider() }
ScrollView {
VStack {
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 {
Divider()
EmailLinkView()
} else if authService.authView == .phoneAuth {
// TODO: - how are we rendering the phone auth View??
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the nub of the problem and it is the same problem we have rendering the buttons. Core auth package doesn't know about PhoneAuthView so how can we render it?

We could:

  1. Use AnyView again like with rendering buttons.
  2. Move Phone Auth package in to Core Auth package - A couple hundred lines of code extra, not a tremendous amount.
  3. An alternative solution???

} else {
Divider()
Text(authService.authenticationFlow == .login ? authService.string
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
VStack { Divider() }

EmailAuthView()
VStack {
authService.renderButtons()
}.padding(.horizontal)
EmailAuthView()
VStack {
authService.renderButtons()
}.padding(.horizontal)

VStack { Divider() }
HStack {
Text(authService
.authenticationFlow == .login ? authService.string.dontHaveAnAccountYetLabel :
authService.string.alreadyHaveAnAccountLabel)
Button(action: {
withAnimation {
switchFlow()
VStack { 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)
}
}) {
Text(authService.authenticationFlow == .signUp ? authService.string
.emailLoginFlowLabel : authService.string.emailSignUpFlowLabel)
.fontWeight(.semibold)
.foregroundColor(.blue)
}
PrivacyTOCsView(displayMode: .footer)
Text(authService.errorMessage).foregroundColor(.red)
}
PrivacyTOCsView(displayMode: .footer)
Text(authService.errorMessage).foregroundColor(.red)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,90 +5,22 @@ import SwiftUI
@MainActor
public struct PhoneAuthButtonView {
@Environment(AuthService.self) private var authService
@State private var errorMessage = ""
@State private var phoneNumber = ""
@State private var showVerificationCodeInput = false
@State private var verificationCode = ""
@State private var verificationID = ""

public init() {}
}

extension PhoneAuthButtonView: View {
public var body: some View {
if authService.authenticationState != .authenticating {
VStack {
LabeledContent {
TextField(authService.string.enterPhoneNumberLabel, text: $phoneNumber)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.submitLabel(.next)
} label: {
Image(systemName: "at")
}.padding(.vertical, 6)
.background(Divider(), alignment: .bottom)
.padding(.bottom, 4)
Button(action: {
Task {
do {
let id = try await authService.verifyPhoneNumber(phoneNumber: phoneNumber)
verificationID = id
showVerificationCodeInput = true
} catch {
errorMessage = authService.string.localizedErrorMessage(
for: error
)
}
}
}) {
Text(authService.string.smsCodeSentLabel)
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
.disabled(!PhoneUtils.isValidPhoneNumber(phoneNumber))
.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
.buttonStyle(.borderedProminent)
Text(errorMessage).foregroundColor(.red)
}.sheet(isPresented: $showVerificationCodeInput) {
TextField(authService.string.phoneNumberVerificationCodeLabel, text: $verificationCode)
.keyboardType(.numberPad)
.padding()
.background(Color(.systemGray6))
.cornerRadius(8)
.padding(.horizontal)

Button(action: {
Task {
do {
try await authService.signInWithPhoneNumber(
verificationID: verificationID,
verificationCode: verificationCode
)
} catch {
errorMessage = authService.string.localizedErrorMessage(for: error)
}
showVerificationCodeInput = false
}
}) {
Text(authService.string.verifyPhoneNumberAndSignInLabel)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(Color.green)
.cornerRadius(8)
.padding(.horizontal)
}
}.onOpenURL { url in
authService.auth.canHandle(url)
}
} else {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
Button(action: {
authService.authView = .phoneAuth
}) {
Label("Sign in with Phone", systemImage: "phone.fill")
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
.background(Color.green.opacity(0.8)) // Light green
.cornerRadius(8)
}
Text(errorMessage).foregroundColor(.red)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
//
// PhoneAuthView.swift
// FirebaseUI
//
// Created by Russell Wheatley on 14/05/2025.
//

import FirebaseAuthSwiftUI
import FirebaseCore
import SwiftUI

@MainActor
public struct PhoneAuthView {
@Environment(AuthService.self) private var authService
@State private var errorMessage = ""
@State private var phoneNumber = ""
@State private var showVerificationCodeInput = false
@State private var verificationCode = ""
@State private var verificationID = ""

public init() {}
}

extension PhoneAuthView: View {
public var body: some View {
if authService.authenticationState != .authenticating {
VStack {
LabeledContent {
TextField(authService.string.enterPhoneNumberLabel, text: $phoneNumber)
.textInputAutocapitalization(.never)
.disableAutocorrection(true)
.submitLabel(.next)
} label: {
Image(systemName: "at")
}.padding(.vertical, 6)
.background(Divider(), alignment: .bottom)
.padding(.bottom, 4)
Button(action: {
Task {
do {
let id = try await authService.verifyPhoneNumber(phoneNumber: phoneNumber)
verificationID = id
showVerificationCodeInput = true
} catch {
errorMessage = authService.string.localizedErrorMessage(
for: error
)
}
}
}) {
Text(authService.string.smsCodeSentLabel)
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
.disabled(!PhoneUtils.isValidPhoneNumber(phoneNumber))
.padding([.top, .bottom], 8)
.frame(maxWidth: .infinity)
.buttonStyle(.borderedProminent)
Text(errorMessage).foregroundColor(.red)
}.sheet(isPresented: $showVerificationCodeInput) {
TextField(authService.string.phoneNumberVerificationCodeLabel, text: $verificationCode)
.keyboardType(.numberPad)
.padding()
.background(Color(.systemGray6))
.cornerRadius(8)
.padding(.horizontal)

Button(action: {
Task {
do {
try await authService.signInWithPhoneNumber(
verificationID: verificationID,
verificationCode: verificationCode
)
} catch {
errorMessage = authService.string.localizedErrorMessage(for: error)
}
showVerificationCodeInput = false
}
}) {
Text(authService.string.verifyPhoneNumberAndSignInLabel)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(Color.green)
.cornerRadius(8)
.padding(.horizontal)
}
}.onOpenURL { url in
authService.auth.canHandle(url)
}
} else {
ProgressView()
.progressViewStyle(CircularProgressViewStyle(tint: .white))
.padding(.vertical, 8)
.frame(maxWidth: .infinity)
}
Text(errorMessage).foregroundColor(.red)
}
}

#Preview {
FirebaseOptions.dummyConfigurationForPreview()
return PhoneAuthView()
.environment(AuthService())
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ struct ContentView: View {
configuration: configuration
)
.withGoogleSignIn()
.withFacebookSignIn()
.withPhoneSignIn()
.withFacebookSignIn()

}

var body: some View {
Expand Down