Skip to content

Commit 9831ec8

Browse files
committed
method picker button styles
1 parent 0f9e403 commit 9831ec8

File tree

9 files changed

+405
-140
lines changed

9 files changed

+405
-140
lines changed
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
//
2+
// AuthProvider.swift
3+
// AuthSwiftUIExample
4+
//
5+
// Created by Ademola Fadumo on 19/10/2025.
6+
//
7+
8+
import SwiftUI
9+
import FirebaseAuth
10+
11+
enum AuthProvider: CaseIterable {
12+
case google
13+
case facebook
14+
case twitter
15+
case github
16+
case email
17+
case phone
18+
case anonymous
19+
case microsoft
20+
case yahoo
21+
case apple
22+
23+
var id: String {
24+
switch self {
25+
case .google: return GoogleAuthProvider.id
26+
case .facebook: return FacebookAuthProvider.id
27+
case .twitter: return TwitterAuthProvider.id
28+
case .github: return GitHubAuthProvider.id
29+
case .email: return EmailAuthProvider.id
30+
case .phone: return PhoneAuthProvider.id
31+
case .anonymous: return "anonymous"
32+
case .microsoft: return "microsoft.com"
33+
case .yahoo: return "yahoo.com"
34+
case .apple: return "apple.com"
35+
}
36+
}
37+
38+
var buttonTitle: String {
39+
switch self {
40+
case .google:
41+
return "Sign in with Google"
42+
case .facebook:
43+
return "Sign in with Facebook"
44+
case .twitter:
45+
return "Sign in with Twitter"
46+
case .github:
47+
return "Sign in with GitHub"
48+
case .email:
49+
return "Sign in with Email"
50+
case .phone:
51+
return "Sign in with Phone"
52+
case .anonymous:
53+
return "Sign in Anonymously"
54+
case .microsoft:
55+
return "Sign in with Microsoft"
56+
case .yahoo:
57+
return "Sign in with Yahoo"
58+
case .apple:
59+
return "Sign in with Apple"
60+
}
61+
}
62+
63+
var isSocialProvider: Bool {
64+
switch self {
65+
case .google, .facebook, .twitter, .github:
66+
return true
67+
default:
68+
return false
69+
}
70+
}
71+
72+
static func from(id: String) -> AuthProvider? {
73+
Self.allCases.first { $0.id == id }
74+
}
75+
76+
var providerStyle: ProviderStyle {
77+
switch self {
78+
case .google:
79+
return ProviderStyle(
80+
icon: .fuiIcGoogleg,
81+
backgroundColor: Color(hex: 0xFFFFFF),
82+
contentColor: Color(hex: 0x757575)
83+
)
84+
case .facebook:
85+
return ProviderStyle(
86+
icon: .fuiIcFacebook,
87+
backgroundColor: Color(hex: 0x3B5998),
88+
contentColor: Color(hex: 0xFFFFFF)
89+
)
90+
case .twitter:
91+
return ProviderStyle(
92+
icon: .fuiIcTwitterBird,
93+
backgroundColor: Color(hex: 0x5BAAF4),
94+
contentColor: Color(hex: 0xFFFFFF)
95+
)
96+
case .github:
97+
return ProviderStyle(
98+
icon: .fuiIcGithub,
99+
backgroundColor: Color(hex: 0x24292E),
100+
contentColor: Color(hex: 0xFFFFFF)
101+
)
102+
case .email:
103+
return ProviderStyle(
104+
icon: .fuiIcMail,
105+
backgroundColor: Color(hex: 0xD0021B),
106+
contentColor: Color(hex: 0xFFFFFF)
107+
)
108+
case .phone:
109+
return ProviderStyle(
110+
icon: .fuiIcPhone,
111+
backgroundColor: Color(hex: 0x43C5A5),
112+
contentColor: Color(hex: 0xFFFFFF)
113+
)
114+
case .anonymous:
115+
return ProviderStyle(
116+
icon: .fuiIcAnonymous,
117+
backgroundColor: Color(hex: 0xF4B400),
118+
contentColor: Color(hex: 0xFFFFFF)
119+
)
120+
case .microsoft:
121+
return ProviderStyle(
122+
icon: .fuiIcMicrosoft,
123+
backgroundColor: Color(hex: 0x2F2F2F),
124+
contentColor: Color(hex: 0xFFFFFF)
125+
)
126+
case .yahoo:
127+
return ProviderStyle(
128+
icon: .fuiIcYahoo,
129+
backgroundColor: Color(hex: 0x720E9E),
130+
contentColor: Color(hex: 0xFFFFFF)
131+
)
132+
case .apple:
133+
return ProviderStyle(
134+
icon: .fuiIcApple,
135+
backgroundColor: Color(hex: 0x000000),
136+
contentColor: Color(hex: 0xFFFFFF)
137+
)
138+
}
139+
}
140+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Color+Hex.swift
3+
// AuthSwiftUIExample
4+
//
5+
// Created by Ademola Fadumo on 19/10/2025.
6+
//
7+
8+
import SwiftUI
9+
10+
// MARK: - Hex color extension
11+
extension Color {
12+
init(hex: Int, opacity: Double = 1.0) {
13+
let red = Double((hex & 0xFF0000) >> 16) / 255.0
14+
let green = Double((hex & 0xFF00) >> 8) / 255.0
15+
let blue = Double((hex & 0xFF) >> 0) / 255.0
16+
self.init(.sRGB, red: red, green: green, blue: blue, opacity: opacity)
17+
}
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// ProviderStyle.swift
3+
// AuthSwiftUIExample
4+
//
5+
// Created by Ademola Fadumo on 19/10/2025.
6+
//
7+
8+
import SwiftUI
9+
10+
struct ProviderStyle {
11+
let icon: ImageResource?
12+
let backgroundColor: Color
13+
let contentColor: Color
14+
var iconTint: Color? = nil
15+
let shape: AnyShape = AnyShape(RoundedRectangle(cornerRadius: 4, style: .continuous))
16+
let elevation: CGFloat = 2
17+
18+
static let empty = ProviderStyle(
19+
icon: nil,
20+
backgroundColor: .white,
21+
contentColor: .black
22+
)
23+
24+
static var `default`: [String: ProviderStyle] {
25+
Dictionary(uniqueKeysWithValues: AuthProvider.allCases.map { provider in
26+
(provider.id, provider.providerStyle)
27+
})
28+
}
29+
}

samples/auth-swiftui/AuthSwiftUIExample/Views/AuthMethodPicker.swift

Lines changed: 0 additions & 92 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// AuthMethodPickerListView.swift
3+
// AuthSwiftUIExample
4+
//
5+
// Created by Ademola Fadumo on 18/10/2025.
6+
//
7+
8+
import SwiftUI
9+
10+
struct AuthMethodPickerListView: View {
11+
var onProviderSelected: (AuthProvider) -> Void
12+
13+
var body: some View {
14+
GeometryReader { proxy in
15+
ScrollView {
16+
VStack(spacing: 16) {
17+
AuthProviderButton(
18+
provider: .apple,
19+
onClick: onProviderSelected
20+
)
21+
AuthProviderButton(
22+
provider: .anonymous,
23+
onClick: onProviderSelected
24+
)
25+
AuthProviderButton(
26+
provider: .email,
27+
onClick: onProviderSelected
28+
)
29+
AuthProviderButton(
30+
provider: .phone,
31+
onClick: onProviderSelected
32+
)
33+
AuthProviderButton(
34+
provider: .google,
35+
onClick: onProviderSelected
36+
)
37+
AuthProviderButton(
38+
provider: .facebook,
39+
onClick: onProviderSelected
40+
)
41+
AuthProviderButton(
42+
provider: .twitter,
43+
onClick: onProviderSelected
44+
)
45+
AuthProviderButton(
46+
provider: .github,
47+
onClick: onProviderSelected
48+
)
49+
AuthProviderButton(
50+
provider: .microsoft,
51+
onClick: onProviderSelected
52+
)
53+
AuthProviderButton(
54+
provider: .yahoo,
55+
onClick: onProviderSelected
56+
)
57+
}
58+
.padding(.horizontal, proxy.size.width * 0.18)
59+
}
60+
}
61+
}
62+
}
63+
64+
#Preview {
65+
AuthMethodPickerListView { selectedProvider in }
66+
}

0 commit comments

Comments
 (0)