Skip to content

Commit 04289a3

Browse files
refactor: remove VStack from button, add button styling
1 parent 3d6b7b1 commit 04289a3

3 files changed

Lines changed: 15 additions & 33 deletions

File tree

FirebaseSwiftUI/FirebaseEmailAuthSwiftUI/Sources/FirebaseEmailAuthSwiftUI/Views/EmailAuth.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,17 @@ class EmailUtils {
1010
}
1111
}
1212

13-
public struct EmailAuth<
14-
StackStyle: FUIVStackStyle
15-
>: View {
16-
private var emailAuthButton: EmailAuthButton<StackStyle>?
17-
18-
public init(emailAuthButton: EmailAuthButton<StackStyle>? = nil) {
13+
public struct EmailAuth<EmailButtonStyle: ButtonStyle>: View {
14+
private var emailAuthButton: EmailAuthButton<EmailButtonStyle>?
15+
public init(emailAuthButton: EmailAuthButton<EmailButtonStyle>? = nil) {
1916
self.emailAuthButton = emailAuthButton
2017
}
2118

2219
public var body: some View {
2320
if let emailAuthButton = emailAuthButton {
2421
emailAuthButton
2522
} else {
26-
EmailAuthButton<DefaultVStackStyle>()
23+
EmailAuthButton<DefaultEmailAuthButtonStyle>(buttonStyle: DefaultEmailAuthButtonStyle())
2724
}
2825
}
2926
}
Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
11
import SwiftUI
22

3-
public protocol FUIVStackStyle {
4-
associatedtype Body: View
5-
6-
@ViewBuilder func body(content: VStack<Button<Text>>) -> Body
7-
}
8-
9-
public struct DefaultVStackStyle: FUIVStackStyle {
10-
public init() {}
11-
12-
public func body(content: VStack<Button<Text>>) -> some View {
13-
content
3+
public struct DefaultEmailAuthButtonStyle: ButtonStyle {
4+
public func makeBody(configuration: Configuration) -> some View {
5+
configuration.label
146
.padding()
15-
.background(Color.gray.opacity(0.2))
7+
.background(Color.blue)
8+
.foregroundColor(.white)
169
.cornerRadius(10)
1710
}
1811
}
1912

20-
public struct EmailAuthButton<StackStyle: FUIVStackStyle>: View {
13+
public struct EmailAuthButton<ButtonStyleType: ButtonStyle>: View {
2114
@State private var emailAuthView = false
2215
private var buttonText: String
23-
private var vStackStyle: StackStyle?
16+
private var buttonStyle: ButtonStyleType
2417

25-
public init(buttonText: String = "Sign in with email", vStackStyle: StackStyle? = nil) {
18+
public init(buttonText: String = "Sign in with email", buttonStyle: ButtonStyleType) {
2619
self.buttonText = buttonText
27-
self.vStackStyle = vStackStyle
20+
self.buttonStyle = buttonStyle
2821
}
2922

3023
public var body: some View {
@@ -36,14 +29,6 @@ public struct EmailAuthButton<StackStyle: FUIVStackStyle>: View {
3629
textView
3730
}
3831

39-
let vStackView = VStack {
40-
buttonView
41-
}
42-
43-
if let vStackStyle = vStackStyle {
44-
vStackStyle.body(content: vStackView)
45-
} else {
46-
DefaultVStackStyle().body(content: vStackView)
47-
}
32+
buttonView.buttonStyle(buttonStyle)
4833
}
4934
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/FirebaseSwiftUIExampleApp.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct FirebaseSwiftUIExampleApp: App {
3939
}) {
4040
VStack {
4141
// method 2 of setting view modifier
42-
EmailAuth<DefaultVStackStyle>()
42+
EmailAuth<DefaultEmailAuthButtonStyle>()
4343
}
4444
}
4545
)

0 commit comments

Comments
 (0)