Skip to content

Commit

Permalink
Make an enable flag for the account modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Oct 23, 2023
1 parent 57b82c0 commit 63aab00
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Sources/SpeziFirebaseAccount/Views/FirebaseAccountModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,40 @@ import SwiftUI


struct FirebaseAccountModifier: ViewModifier {
private let enable: Bool

@EnvironmentObject private var account: Account

@Environment(\.authorizationController)
private var authorizationController


init(_ enable: Bool) {
self.enable = enable
}


func body(content: Content) -> some View {
content
.task {
for service in account.registeredAccountServices {
guard let firebaseService = service as? any FirebaseAccountService else {
continue
if enable {
content
.task {
for service in account.registeredAccountServices {
guard let firebaseService = service as? any FirebaseAccountService else {
continue
}

await firebaseService.inject(authorizationController: authorizationController)
}

await firebaseService.inject(authorizationController: authorizationController)
}
}
} else {
content
}
}
}


extension View {
public func firebaseAccount() -> some View {
modifier(FirebaseAccountModifier())
public func firebaseAccount(_ enable: Bool = true) -> some View {
modifier(FirebaseAccountModifier(enable))
}
}

0 comments on commit 63aab00

Please sign in to comment.