diff --git a/Sources/SpeziAccount/AccountSetup.swift b/Sources/SpeziAccount/AccountSetup.swift index bbb8636..722708a 100644 --- a/Sources/SpeziAccount/AccountSetup.swift +++ b/Sources/SpeziAccount/AccountSetup.swift @@ -80,6 +80,7 @@ public struct AccountSetup: View { @State private var compliance: SignupProviderCompliance? @State private var followUpSheet = false @State private var isCompletingSetup = false + @State private var accountSetupTask: Task? private var hasSetupComponents: Bool { account.accountSetupComponents.contains { $0.configuration.isEnabled } @@ -102,6 +103,9 @@ public struct AccountSetup: View { } handleSuccessfulSetup(details) } + .onDisappear { + accountSetupTask?.cancel() + } } @ViewBuilder private var scrollableContentView: some View { @@ -117,7 +121,11 @@ public struct AccountSetup: View { followUpInformationSheet(details, requiredKeys: keys) case .loadingExistingAccount: // We allow the outer view to navigate away upon signup, before we show the existing account view - existingAccountLoading + ProgressView() + .task { + try? await Task.sleep(for: .seconds(2)) + setupState = .generic + } default: if isCompletingSetup { ProgressView() @@ -169,15 +177,7 @@ public struct AccountSetup: View { } } } - - @ViewBuilder private var existingAccountLoading: some View { - ProgressView() - .task { - try? await Task.sleep(for: .seconds(2)) - setupState = .generic - } - } - + fileprivate init(state: _AccountSetupState) where Header == DefaultAccountSetupHeader, Continue == EmptyView { self.setupCompleteClosure = { _ in } @@ -258,7 +258,7 @@ public struct AccountSetup: View { private func handleSetupCompleted(_ details: AccountDetails) { isCompletingSetup = true - Task { @MainActor in + accountSetupTask = Task { @MainActor in await setupCompleteClosure(details) isCompletingSetup = false } diff --git a/Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift b/Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift index d364de3..854928c 100644 --- a/Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift +++ b/Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift @@ -15,7 +15,7 @@ private let logger = Logger(subsystem: "edu.stanford.sepzi.SepziAccount", catego struct AccountRequiredModifier: ViewModifier { private let enabled: Bool - private let isValid: (AccountDetails) -> Bool + private let accountSetupIsComplete: (AccountDetails) -> Bool private let setupSheet: SetupSheet @Environment(Account.self) @@ -39,11 +39,11 @@ struct AccountRequiredModifier: ViewModifier { init( enabled: Bool, - isValid: @escaping (AccountDetails) -> Bool, + accountSetupIsComplete: @escaping (AccountDetails) -> Bool, @ViewBuilder setupSheet: () -> SetupSheet ) { self.enabled = enabled - self.isValid = isValid + self.accountSetupIsComplete = accountSetupIsComplete self.setupSheet = setupSheet() } @@ -98,9 +98,15 @@ extension View { /// - Returns: The modified view. public func accountRequired( _ required: Bool = true, - isValid: @escaping (AccountDetails) -> Bool = { !$0.isAnonymous }, + accountSetupIsComplete: @escaping (AccountDetails) -> Bool = { !$0.isAnonymous }, @ViewBuilder setupSheet: () -> SetupSheet ) -> some View { - modifier(AccountRequiredModifier(enabled: required, isValid: isValid, setupSheet: setupSheet)) + modifier( + AccountRequiredModifier( + enabled: required, + accountSetupIsComplete: accountSetupIsComplete, + setupSheet: setupSheet + ) + ) } }