Skip to content

Commit

Permalink
chore: initial format of all swiftui code
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Mar 5, 2025
1 parent 7f02ddb commit 3128742
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 175 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Combine
import FirebaseAuth
import FirebaseCore

// The Swift Programming Language
// https://docs.swift.org/swift-book
import SwiftUI
import FirebaseAuth
import FirebaseCore
import Combine

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

public init(auth: Auth? = nil) {
self.auth = auth ?? Auth.auth()
self.auth = auth ?? Auth.auth()
}

public func authProviders(providers: [FUIAuthProvider]) {
self.authProviders = providers
authProviders = providers
}
}

// 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.
// 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.
// Negates the need for a delegate used in UIKit
public struct FUIAuthView: View {
private var FUIAuth: FirebaseAuthSwiftUI
private var authPickerView: any AuthPickerView


public init(FUIAuth: FirebaseAuthSwiftUI,_authPickerView: some AuthPickerView = FUIAuthPicker()) {
public init(FUIAuth: FirebaseAuthSwiftUI,
_authPickerView: some AuthPickerView = FUIAuthPicker()) {
self.FUIAuth = FUIAuth
self.authPickerView = _authPickerView

authPickerView = _authPickerView
}

public var body: some View {
VStack {
AnyView(authPickerView)
}

public var body: some View {
VStack {
AnyView(authPickerView)
}
}
}


public protocol AuthPickerView: View {
var title: String { get }
var title: String { get }
}

public struct FUIAuthPicker: AuthPickerView {
public var title: String
private var emailAuthButton: any EmailAuthButton

public init(title: String? = nil, _emailAuthButton: (any EmailAuthButton)? = nil) {
self.title = title ?? "Auth Picker View"
self.emailAuthButton = _emailAuthButton ?? EmailProviderButton() as! any EmailAuthButton
emailAuthButton = _emailAuthButton ?? EmailProviderButton() as! any EmailAuthButton
}

public var body: some View {
VStack {
Text(title)
.font(.largeTitle)
.padding()
AnyView(emailAuthButton)
}.padding(20)
.background(Color.white)
.cornerRadius(12)
.shadow(radius: 10)
.padding()

}
public var body: some View {
VStack {
Text(title)
.font(.largeTitle)
.padding()
AnyView(emailAuthButton)
}.padding(20)
.background(Color.white)
.cornerRadius(12)
.shadow(radius: 10)
.padding()
}
}

public protocol EmailAuthButton: View {
var text: String { get }
var text: String { get }
}

public struct EmailProviderButton: EmailAuthButton {
public var text: String = "Sign in with email"
public var body: some View {
VStack {
Button(action: {
// Add the action you want to perform when the button is tapped
print("Email sign-in button tapped")
}) {
Text(text)
.padding()
.background(Color.red)
.foregroundColor(.white)
.cornerRadius(8)
}
// Add the action you want to perform when the button is tapped
print("Email sign-in button tapped")
}) {
Text(text)
.padding()
.background(Color.red)
.foregroundColor(.white)
.cornerRadius(8)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Testing
@testable import FirebaseAuthSwiftUI
import Testing

@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// The Swift Programming Language
// https://docs.swift.org/swift-book

import FirebaseAuthSwiftUI
import FirebaseAuth
import FirebaseAuthSwiftUI

class EmailAuthProvider: FUIAuthProvider {
var providerId: String {
return "password"
return "password"
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Testing
@testable import FirebaseEmailAuthSwiftUI
import Testing

@Test func example() async throws {
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,57 +5,62 @@
// Created by Russell Wheatley on 18/02/2025.
//

import SwiftUI
import SwiftData
import SwiftUI

struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Query private var items: [Item]
@Environment(\.modelContext) private var modelContext
@Query private var items: [Item]

var body: some View {
NavigationSplitView {
List {
ForEach(items) { item in
NavigationLink {
Text("Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))")
} label: {
Text(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))
}
}
.onDelete(perform: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
} detail: {
Text("Select an item")
var body: some View {
NavigationSplitView {
List {
ForEach(items) { item in
NavigationLink {
Text(
"Item at \(item.timestamp, format: Date.FormatStyle(date: .numeric, time: .standard))"
)
} label: {
Text(
item.timestamp,
format: Date.FormatStyle(date: .numeric, time: .standard)
)
}
}
.onDelete(perform: deleteItems)
}
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addItem) {
Label("Add Item", systemImage: "plus")
}
}
}
} detail: {
Text("Select an item")
}
}

private func addItem() {
withAnimation {
let newItem = Item(timestamp: Date())
modelContext.insert(newItem)
}
private func addItem() {
withAnimation {
let newItem = Item(timestamp: Date())
modelContext.insert(newItem)
}
}

private func deleteItems(offsets: IndexSet) {
withAnimation {
for index in offsets {
modelContext.delete(items[index])
}
}
private func deleteItems(offsets: IndexSet) {
withAnimation {
for index in offsets {
modelContext.delete(items[index])
}
}
}
}

#Preview {
ContentView()
.modelContainer(for: Item.self, inMemory: true)
ContentView()
.modelContainer(for: Item.self, inMemory: true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,39 @@
// Created by Russell Wheatley on 18/02/2025.
//

import SwiftUI
import SwiftData
import FirebaseAuth
import FirebaseAuthSwiftUI
import FirebaseCore
import FirebaseAuth
import SwiftData
import SwiftUI

@main
struct FirebaseSwiftUIExampleApp: App {
init() {
FirebaseApp.configure()
}
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Item.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)
init() {
FirebaseApp.configure()
}

do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
}()
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Item.self,
])
let modelConfiguration = ModelConfiguration(schema: schema, isStoredInMemoryOnly: false)

do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
}()

var body: some Scene {
WindowGroup {
// Put this at top level so user can control it in their app
NavigationView {
let firebaseAuthUI = FirebaseAuthSwiftUI()
FUIAuthView(FUIAuth: firebaseAuthUI)
}
}
.modelContainer(sharedModelContainer)
var body: some Scene {
WindowGroup {
// Put this at top level so user can control it in their app
NavigationView {
let firebaseAuthUI = FirebaseAuthSwiftUI()
FUIAuthView(FUIAuth: firebaseAuthUI)
}
}
.modelContainer(sharedModelContainer)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import SwiftData

@Model
final class Item {
var timestamp: Date
init(timestamp: Date) {
self.timestamp = timestamp
}
var timestamp: Date

init(timestamp: Date) {
self.timestamp = timestamp
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
// Created by Russell Wheatley on 18/02/2025.
//

import Testing
@testable import FirebaseSwiftUIExample
import Testing

struct FirebaseSwiftUIExampleTests {

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

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

0 comments on commit 3128742

Please sign in to comment.