Skip to content

Commit

Permalink
Adaptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pauljohanneskraft committed Sep 25, 2024
1 parent f418458 commit 03427b1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
22 changes: 11 additions & 11 deletions Sources/SpeziAccount/AccountSetup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public struct AccountSetup<Header: View, Continue: View>: View {
@State private var compliance: SignupProviderCompliance?
@State private var followUpSheet = false
@State private var isCompletingSetup = false
@State private var accountSetupTask: Task<Void, Never>?

private var hasSetupComponents: Bool {
account.accountSetupComponents.contains { $0.configuration.isEnabled }
Expand All @@ -102,6 +103,9 @@ public struct AccountSetup<Header: View, Continue: View>: View {
}
handleSuccessfulSetup(details)
}
.onDisappear {
accountSetupTask?.cancel()
}
}

@ViewBuilder private var scrollableContentView: some View {
Expand All @@ -117,7 +121,11 @@ public struct AccountSetup<Header: View, Continue: View>: 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()
Expand Down Expand Up @@ -169,15 +177,7 @@ public struct AccountSetup<Header: View, Continue: View>: 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 }
Expand Down Expand Up @@ -258,7 +258,7 @@ public struct AccountSetup<Header: View, Continue: View>: View {

private func handleSetupCompleted(_ details: AccountDetails) {
isCompletingSetup = true
Task { @MainActor in
accountSetupTask = Task { @MainActor in
await setupCompleteClosure(details)
isCompletingSetup = false
}
Expand Down
16 changes: 11 additions & 5 deletions Sources/SpeziAccount/ViewModifier/AccountRequiredModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ private let logger = Logger(subsystem: "edu.stanford.sepzi.SepziAccount", catego

struct AccountRequiredModifier<SetupSheet: View>: ViewModifier {
private let enabled: Bool
private let isValid: (AccountDetails) -> Bool
private let accountSetupIsComplete: (AccountDetails) -> Bool
private let setupSheet: SetupSheet

@Environment(Account.self)
Expand All @@ -39,11 +39,11 @@ struct AccountRequiredModifier<SetupSheet: View>: 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()
}

Expand Down Expand Up @@ -98,9 +98,15 @@ extension View {
/// - Returns: The modified view.
public func accountRequired<SetupSheet: View>(
_ 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
)
)
}
}

0 comments on commit 03427b1

Please sign in to comment.