Skip to content

Commit

Permalink
Make sure POSModalManager is always reset when it's no longer presented
Browse files Browse the repository at this point in the history
staskus committed Jan 30, 2025
1 parent b262860 commit ac276c1
Showing 1 changed file with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
import SwiftUI
import Combine

class POSModalManager: ObservableObject {
@Published private(set) var isPresented: Bool = false
@Published private(set) var allowsInteractiveDismissal: Bool = true
private var contentBuilder: (() -> AnyView)?
private var onDismiss: (() -> Void)?
private var subscriptions = Set<AnyCancellable>()

func present<Content: View>(onDismiss: @escaping () -> Void, content: @escaping () -> Content) {
contentBuilder = { AnyView(content()) }
self.onDismiss = onDismiss
isPresented = true

$isPresented
.sink { [weak self] _ in
guard let self else { return }
if !isPresented {
reset()
}
}
.store(in: &subscriptions)
}

func dismiss() {
@@ -34,5 +45,6 @@ class POSModalManager: ObservableObject {
onDismiss = nil
allowsInteractiveDismissal = true
contentBuilder = nil
subscriptions = Set()
}
}

0 comments on commit ac276c1

Please sign in to comment.