File tree Expand file tree Collapse file tree
FirebaseSwiftUI/FirebasePhoneAuthSwiftUI/Sources Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222import FirebaseAuthSwiftUI
2323
2424public extension AuthService {
25+ /// Register phone sign-in with default behavior (navigates to enter phone number view)
2526 @discardableResult
2627 func withPhoneSignIn( ) -> AuthService {
27- registerProvider ( providerWithButton: PhoneAuthProviderAuthUI ( ) )
28+ return withPhoneSignIn { [ weak self] in
29+ self ? . navigator. push ( . enterPhoneNumber)
30+ }
31+ }
32+
33+ /// Register phone sign-in with custom behavior
34+ @discardableResult
35+ func withPhoneSignIn( onTap: @escaping @MainActor ( ) -> Void ) -> AuthService {
36+ registerProvider ( providerWithButton: PhoneAuthProviderAuthUI ( onTap: onTap) )
2837 return self
2938 }
3039}
Original file line number Diff line number Diff line change @@ -25,11 +25,15 @@ public class PhoneAuthProviderAuthUI: AuthProviderUI {
2525 public var provider : AuthProviderSwift { typedProvider }
2626 public let id : String = " phone "
2727
28- public init ( ) {
28+ // Callback for when the phone auth button is tapped
29+ private let onTap : @MainActor ( ) -> Void
30+
31+ public init ( onTap: @escaping @MainActor ( ) -> Void ) {
2932 typedProvider = PhoneProviderSwift ( )
33+ self . onTap = onTap
3034 }
3135
3236 @MainActor public func authButton( ) -> AnyView {
33- AnyView ( PhoneAuthButtonView ( ) )
37+ AnyView ( PhoneAuthButtonView ( onTap : onTap ) )
3438 }
3539}
Original file line number Diff line number Diff line change @@ -20,8 +20,11 @@ import SwiftUI
2020@MainActor
2121public struct PhoneAuthButtonView {
2222 @Environment ( AuthService . self) private var authService
23+ private let onTap : @MainActor ( ) -> Void
2324
24- public init ( ) { }
25+ public init ( onTap: @escaping @MainActor ( ) -> Void ) {
26+ self . onTap = onTap
27+ }
2528}
2629
2730extension PhoneAuthButtonView : View {
@@ -31,13 +34,15 @@ extension PhoneAuthButtonView: View {
3134 style: . phone,
3235 accessibilityId: " sign-in-with-phone-button "
3336 ) {
34- authService . navigator . push ( . enterPhoneNumber )
37+ onTap ( )
3538 }
3639 }
3740}
3841
3942#Preview {
4043 FirebaseOptions . dummyConfigurationForPreview ( )
41- return PhoneAuthButtonView ( )
42- . environment ( AuthService ( ) )
44+ return PhoneAuthButtonView {
45+ print ( " Phone auth tapped " )
46+ }
47+ . environment ( AuthService ( ) )
4348}
You can’t perform that action at this time.
0 commit comments