Skip to content

Commit 3128742

Browse files
chore: initial format of all swiftui code
1 parent 7f02ddb commit 3128742

File tree

10 files changed

+178
-175
lines changed

10 files changed

+178
-175
lines changed
Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import Combine
2+
import FirebaseAuth
3+
import FirebaseCore
4+
15
// The Swift Programming Language
26
// https://docs.swift.org/swift-book
37
import SwiftUI
4-
import FirebaseAuth
5-
import FirebaseCore
6-
import Combine
78

89
public protocol FUIAuthProvider {
910
var providerId: String { get }
@@ -14,81 +15,79 @@ public class FirebaseAuthSwiftUI {
1415
private var authProviders: [FUIAuthProvider] = []
1516

1617
public init(auth: Auth? = nil) {
17-
self.auth = auth ?? Auth.auth()
18+
self.auth = auth ?? Auth.auth()
1819
}
1920

2021
public func authProviders(providers: [FUIAuthProvider]) {
21-
self.authProviders = providers
22+
authProviders = providers
2223
}
2324
}
2425

25-
// main auth view - can be composed of custom views or fallback to default views. We can also pass state upwards as opposed to having callbacks.
26+
// main auth view - can be composed of custom views or fallback to default views. We can also pass
27+
// state upwards as opposed to having callbacks.
2628
// Negates the need for a delegate used in UIKit
2729
public struct FUIAuthView: View {
2830
private var FUIAuth: FirebaseAuthSwiftUI
2931
private var authPickerView: any AuthPickerView
30-
3132

32-
public init(FUIAuth: FirebaseAuthSwiftUI,_authPickerView: some AuthPickerView = FUIAuthPicker()) {
33+
public init(FUIAuth: FirebaseAuthSwiftUI,
34+
_authPickerView: some AuthPickerView = FUIAuthPicker()) {
3335
self.FUIAuth = FUIAuth
34-
self.authPickerView = _authPickerView
35-
36+
authPickerView = _authPickerView
3637
}
37-
38-
public var body: some View {
39-
VStack {
40-
AnyView(authPickerView)
41-
}
38+
39+
public var body: some View {
40+
VStack {
41+
AnyView(authPickerView)
4242
}
43+
}
4344
}
4445

45-
4646
public protocol AuthPickerView: View {
47-
var title: String { get }
47+
var title: String { get }
4848
}
4949

5050
public struct FUIAuthPicker: AuthPickerView {
5151
public var title: String
5252
private var emailAuthButton: any EmailAuthButton
53-
53+
5454
public init(title: String? = nil, _emailAuthButton: (any EmailAuthButton)? = nil) {
5555
self.title = title ?? "Auth Picker View"
56-
self.emailAuthButton = _emailAuthButton ?? EmailProviderButton() as! any EmailAuthButton
56+
emailAuthButton = _emailAuthButton ?? EmailProviderButton() as! any EmailAuthButton
5757
}
58-
59-
public var body: some View {
60-
VStack {
61-
Text(title)
62-
.font(.largeTitle)
63-
.padding()
64-
AnyView(emailAuthButton)
65-
}.padding(20)
66-
.background(Color.white)
67-
.cornerRadius(12)
68-
.shadow(radius: 10)
69-
.padding()
7058

71-
}
59+
public var body: some View {
60+
VStack {
61+
Text(title)
62+
.font(.largeTitle)
63+
.padding()
64+
AnyView(emailAuthButton)
65+
}.padding(20)
66+
.background(Color.white)
67+
.cornerRadius(12)
68+
.shadow(radius: 10)
69+
.padding()
70+
}
7271
}
7372

7473
public protocol EmailAuthButton: View {
75-
var text: String { get }
74+
var text: String { get }
7675
}
7776

7877
public struct EmailProviderButton: EmailAuthButton {
7978
public var text: String = "Sign in with email"
8079
public var body: some View {
8180
VStack {
8281
Button(action: {
83-
// Add the action you want to perform when the button is tapped
84-
print("Email sign-in button tapped")
85-
}) {
86-
Text(text)
87-
.padding()
88-
.background(Color.red)
89-
.foregroundColor(.white)
90-
.cornerRadius(8)
91-
}
82+
// Add the action you want to perform when the button is tapped
83+
print("Email sign-in button tapped")
84+
}) {
85+
Text(text)
86+
.padding()
87+
.background(Color.red)
88+
.foregroundColor(.white)
89+
.cornerRadius(8)
90+
}
9291
}
9392
}
9493
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Testing
21
@testable import FirebaseAuthSwiftUI
2+
import Testing
33

44
@Test func example() async throws {
5-
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
5+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
66
}
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// The Swift Programming Language
22
// https://docs.swift.org/swift-book
33

4-
import FirebaseAuthSwiftUI
54
import FirebaseAuth
5+
import FirebaseAuthSwiftUI
66

77
class EmailAuthProvider: FUIAuthProvider {
88
var providerId: String {
9-
return "password"
9+
return "password"
1010
}
11-
1211
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import Testing
21
@testable import FirebaseEmailAuthSwiftUI
2+
import Testing
33

44
@Test func example() async throws {
5-
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
5+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
66
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/ContentView.swift

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,57 +5,62 @@
55
// Created by Russell Wheatley on 18/02/2025.
66
//
77

8-
import SwiftUI
98
import SwiftData
9+
import SwiftUI
1010

1111
struct ContentView: View {
12-
@Environment(\.modelContext) private var modelContext
13-
@Query private var items: [Item]
12+
@Environment(\.modelContext) private var modelContext
13+
@Query private var items: [Item]
1414

15-
var body: some View {
16-
NavigationSplitView {
17-
List {
18-
ForEach(items) { item in
19-
NavigationLink {
20-
Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
21-
} label: {
22-
Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
23-
}
24-
}
25-
.onDelete(perform: deleteItems)
26-
}
27-
.toolbar {
28-
ToolbarItem(placement: .navigationBarTrailing) {
29-
EditButton()
30-
}
31-
ToolbarItem {
32-
Button(action: addItem) {
33-
Label("Add Item", systemImage: "plus")
34-
}
35-
}
36-
}
37-
} detail: {
38-
Text("Select an item")
15+
var body: some View {
16+
NavigationSplitView {
17+
List {
18+
ForEach(items) { item in
19+
NavigationLink {
20+
Text(
21+
"Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))"
22+
)
23+
} label: {
24+
Text(
25+
item.timestamp,
26+
format: Date.FormatStyle(date: .numeric, time: .standard)
27+
)
28+
}
29+
}
30+
.onDelete(perform: deleteItems)
31+
}
32+
.toolbar {
33+
ToolbarItem(placement: .navigationBarTrailing) {
34+
EditButton()
3935
}
36+
ToolbarItem {
37+
Button(action: addItem) {
38+
Label("Add Item", systemImage: "plus")
39+
}
40+
}
41+
}
42+
} detail: {
43+
Text("Select an item")
4044
}
45+
}
4146

42-
private func addItem() {
43-
withAnimation {
44-
let newItem = Item(timestamp: Date())
45-
modelContext.insert(newItem)
46-
}
47+
private func addItem() {
48+
withAnimation {
49+
let newItem = Item(timestamp: Date())
50+
modelContext.insert(newItem)
4751
}
52+
}
4853

49-
private func deleteItems(offsets: IndexSet) {
50-
withAnimation {
51-
for index in offsets {
52-
modelContext.delete(items[index])
53-
}
54-
}
54+
private func deleteItems(offsets: IndexSet) {
55+
withAnimation {
56+
for index in offsets {
57+
modelContext.delete(items[index])
58+
}
5559
}
60+
}
5661
}
5762

5863
#Preview {
59-
ContentView()
60-
.modelContainer(for: Item.self, inMemory: true)
64+
ContentView()
65+
.modelContainer(for: Item.self, inMemory: true)
6166
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/FirebaseSwiftUIExampleApp.swift

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,39 @@
55
// Created by Russell Wheatley on 18/02/2025.
66
//
77

8-
import SwiftUI
9-
import SwiftData
8+
import FirebaseAuth
109
import FirebaseAuthSwiftUI
1110
import FirebaseCore
12-
import FirebaseAuth
11+
import SwiftData
12+
import SwiftUI
1313

1414
@main
1515
struct FirebaseSwiftUIExampleApp: App {
16-
init() {
17-
FirebaseApp.configure()
18-
}
19-
var sharedModelContainer: ModelContainer = {
20-
let schema = Schema([
21-
Item.self,
22-
])
23-
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
16+
init() {
17+
FirebaseApp.configure()
18+
}
2419

25-
do {
26-
return try ModelContainer(for: schema, configurations: [modelConfiguration])
27-
} catch {
28-
fatalError("Could not create ModelContainer: \(error)")
29-
}
30-
}()
20+
var sharedModelContainer: ModelContainer = {
21+
let schema = Schema([
22+
Item.self,
23+
])
24+
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
25+
26+
do {
27+
return try ModelContainer(for: schema, configurations: [modelConfiguration])
28+
} catch {
29+
fatalError("Could not create ModelContainer: \(error)")
30+
}
31+
}()
3132

32-
var body: some Scene {
33-
WindowGroup {
34-
// Put this at top level so user can control it in their app
35-
NavigationView {
36-
let firebaseAuthUI = FirebaseAuthSwiftUI()
37-
FUIAuthView(FUIAuth: firebaseAuthUI)
38-
}
39-
}
40-
.modelContainer(sharedModelContainer)
33+
var body: some Scene {
34+
WindowGroup {
35+
// Put this at top level so user can control it in their app
36+
NavigationView {
37+
let firebaseAuthUI = FirebaseAuthSwiftUI()
38+
FUIAuthView(FUIAuth: firebaseAuthUI)
39+
}
4140
}
41+
.modelContainer(sharedModelContainer)
42+
}
4243
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExample/Item.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import SwiftData
1010

1111
@Model
1212
final class Item {
13-
var timestamp: Date
14-
15-
init(timestamp: Date) {
16-
self.timestamp = timestamp
17-
}
13+
var timestamp: Date
14+
15+
init(timestamp: Date) {
16+
self.timestamp = timestamp
17+
}
1818
}

samples/swiftui/FirebaseSwiftUIExample/FirebaseSwiftUIExampleTests/FirebaseSwiftUIExampleTests.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
// Created by Russell Wheatley on 18/02/2025.
66
//
77

8-
import Testing
98
@testable import FirebaseSwiftUIExample
9+
import Testing
1010

1111
struct FirebaseSwiftUIExampleTests {
12-
13-
@Test func example() async throws {
14-
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
15-
}
16-
12+
@Test func example() async throws {
13+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
14+
}
1715
}

0 commit comments

Comments
 (0)