From 318ed30b39faff0b621ef0b4e7249e8d2b4465c4 Mon Sep 17 00:00:00 2001 From: Paul Kraft Date: Thu, 12 Sep 2024 11:02:59 -0700 Subject: [PATCH] Revert changes to AccountSetup to make setupComplete async --- Sources/SpeziAccount/AccountSetup.swift | 84 +++++++++++-------------- 1 file changed, 38 insertions(+), 46 deletions(-) diff --git a/Sources/SpeziAccount/AccountSetup.swift b/Sources/SpeziAccount/AccountSetup.swift index bbb8636..11e3190 100644 --- a/Sources/SpeziAccount/AccountSetup.swift +++ b/Sources/SpeziAccount/AccountSetup.swift @@ -7,7 +7,6 @@ // import OrderedCollections -import SpeziViews import SwiftUI @@ -67,7 +66,7 @@ public enum _AccountSetupState: EnvironmentKey, Sendable { // swiftlint:disable: /// - ``DefaultAccountSetupHeader`` @MainActor public struct AccountSetup: View { - private let setupCompleteClosure: (AccountDetails) async -> Void + private let setupCompleteClosure: (AccountDetails) -> Void private let header: Header private let continueButton: Continue @@ -79,7 +78,6 @@ public struct AccountSetup: View { @State private var setupState: _AccountSetupState = .generic @State private var compliance: SignupProviderCompliance? @State private var followUpSheet = false - @State private var isCompletingSetup = false private var hasSetupComponents: Bool { account.accountSetupComponents.contains { $0.configuration.isEnabled } @@ -88,7 +86,37 @@ public struct AccountSetup: View { public var body: some View { GeometryReader { proxy in ScrollView(.vertical) { - scrollableContentView + VStack { + if hasSetupComponents { + header + .environment(\._accountSetupState, setupState) + } + + Spacer() + + if let details = account.details, !details.isAnonymous { + switch setupState { + case let .requiringAdditionalInfo(keys): + followUpInformationSheet(details, requiredKeys: keys) + case .loadingExistingAccount: + // We allow the outer view to navigate away upon signup, before we show the existing account view + existingAccountLoading + default: + ExistingAccountView(details: details) { + continueButton + } + } + } else { + accountSetupView + .onAppear { + setupState = .setupShown + } + } + + Spacer() + Spacer() + Spacer() + } .padding(.horizontal, ViewSizing.outerHorizontalPadding) .frame(minHeight: proxy.size.height) .frame(maxWidth: .infinity) @@ -100,44 +128,10 @@ public struct AccountSetup: View { case .setupShown = setupState else { return } + handleSuccessfulSetup(details) } } - - @ViewBuilder private var scrollableContentView: some View { - VStack { - if hasSetupComponents { - header - .environment(\._accountSetupState, setupState) - } - Spacer() - if let details = account.details, !details.isAnonymous { - switch setupState { - case let .requiringAdditionalInfo(keys): - followUpInformationSheet(details, requiredKeys: keys) - case .loadingExistingAccount: - // We allow the outer view to navigate away upon signup, before we show the existing account view - existingAccountLoading - default: - if isCompletingSetup { - ProgressView() - } else { - ExistingAccountView(details: details) { - continueButton - } - } - } - } else { - accountSetupView - .onAppear { - setupState = .setupShown - } - } - Spacer() - Spacer() - Spacer() - } - } @ViewBuilder private var accountSetupView: some View { if !hasSetupComponents { @@ -195,7 +189,7 @@ public struct AccountSetup: View { /// - continue: A custom continue button you can place. This view will be rendered if the AccountSetup view is /// displayed with an already associated account. public init( - setupComplete: @escaping (AccountDetails) async -> Void = { _ in }, + setupComplete: @escaping (AccountDetails) -> Void = { _ in }, @ViewBuilder header: () -> Header = { DefaultAccountSetupHeader() }, @ViewBuilder `continue`: () -> Continue = { EmptyView() } ) { @@ -218,7 +212,8 @@ public struct AccountSetup: View { } .onChange(of: followUpSheet) { if !followUpSheet { // follow up information was completed! - handleSetupCompleted(details) + setupState = .loadingExistingAccount + setupCompleteClosure(details) } } } @@ -257,11 +252,8 @@ public struct AccountSetup: View { } private func handleSetupCompleted(_ details: AccountDetails) { - isCompletingSetup = true - Task { @MainActor in - await setupCompleteClosure(details) - isCompletingSetup = false - } + setupState = .loadingExistingAccount + setupCompleteClosure(details) } }