Skip to content

Commit ac276c1

Browse files
committed
Make sure POSModalManager is always reset when it's no longer presented
1 parent b262860 commit ac276c1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

WooCommerce/Classes/POS/Presentation/Reusable Views/POSModalManager.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
import SwiftUI
2+
import Combine
23

34
class POSModalManager: ObservableObject {
45
@Published private(set) var isPresented: Bool = false
56
@Published private(set) var allowsInteractiveDismissal: Bool = true
67
private var contentBuilder: (() -> AnyView)?
78
private var onDismiss: (() -> Void)?
9+
private var subscriptions = Set<AnyCancellable>()
810

911
func present<Content: View>(onDismiss: @escaping () -> Void, content: @escaping () -> Content) {
1012
contentBuilder = { AnyView(content()) }
1113
self.onDismiss = onDismiss
1214
isPresented = true
15+
16+
$isPresented
17+
.sink { [weak self] _ in
18+
guard let self else { return }
19+
if !isPresented {
20+
reset()
21+
}
22+
}
23+
.store(in: &subscriptions)
1324
}
1425

1526
func dismiss() {
@@ -34,5 +45,6 @@ class POSModalManager: ObservableObject {
3445
onDismiss = nil
3546
allowsInteractiveDismissal = true
3647
contentBuilder = nil
48+
subscriptions = Set()
3749
}
3850
}

0 commit comments

Comments
 (0)