Skip to content

Commit 529a114

Browse files
committed
Update package
1 parent 9ddd533 commit 529a114

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

Sources/Intramodular/Presentation/CocoaPresentationCoordinator.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ extension CocoaPresentationCoordinator: DynamicViewPresenter {
173173

174174
#if os(iOS) || os(tvOS) || targetEnvironment(macCatalyst)
175175
return .init { attemptToFulfill in
176-
if viewController.presentedViewController != nil {
176+
if let presentedViewController = viewController.presentedViewController {
177+
// Don't call `UIViewController.dismiss` if the presented view controller is already being dismissed. Otherwise, it causes the _presenter_ to dismiss itself.
178+
guard !presentedViewController.isBeingDismissed else {
179+
return attemptToFulfill(.success(false))
180+
}
181+
177182
viewController.dismiss(animated: animation != nil) {
178183
if let presentation = presentation {
179184
presentation.onDismiss()

Sources/Intramodular/Presentation/PresentationManager.swift

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -51,38 +51,6 @@ public struct BooleanPresentationManager: PresentationManager {
5151
}
5252
}
5353

54-
// MARK: - Auxiliary Implementation -
55-
56-
private struct _PresentationManagerEnvironmentKey: ViewInteractorEnvironmentKey {
57-
typealias ViewInteractor = PresentationManager
58-
59-
static var defaultValue: PresentationManager? {
60-
get {
61-
return nil
62-
}
63-
}
64-
}
65-
66-
extension EnvironmentValues {
67-
public var presentationManager: PresentationManager {
68-
get {
69-
#if os(iOS) || os(tvOS) || os(macOS) || targetEnvironment(macCatalyst)
70-
if navigator == nil && presentationMode.isPresented {
71-
return presentationMode
72-
} else {
73-
return self[_PresentationManagerEnvironmentKey.self]
74-
?? (_appKitOrUIKitViewControllerBox?.value?._cocoaPresentationCoordinator).flatMap({ CocoaPresentationMode(coordinator: $0) })
75-
?? presentationMode
76-
}
77-
#else
78-
return self[_PresentationManagerEnvironmentKey.self] ?? presentationMode
79-
#endif
80-
} set {
81-
self[_PresentationManagerEnvironmentKey.self] = newValue
82-
}
83-
}
84-
}
85-
8654
// MARK: - Conformances -
8755

8856
public struct AnyPresentationManager: PresentationManager {
@@ -115,3 +83,43 @@ extension Binding: PresentationManager where Value == PresentationMode {
11583
wrappedValue.dismiss()
11684
}
11785
}
86+
87+
// MARK: - Auxiliary Implementation -
88+
89+
private struct _PresentationManagerEnvironmentKey: ViewInteractorEnvironmentKey {
90+
typealias ViewInteractor = PresentationManager
91+
92+
static var defaultValue: PresentationManager? {
93+
get {
94+
return nil
95+
}
96+
}
97+
}
98+
99+
extension EnvironmentValues {
100+
public var presentationManager: PresentationManager {
101+
get {
102+
#if os(iOS) || os(tvOS) || os(macOS) || targetEnvironment(macCatalyst)
103+
if navigator == nil && presentationMode.isPresented {
104+
if let existingPresentationManager = self[_PresentationManagerEnvironmentKey.self], existingPresentationManager.isPresented {
105+
if #available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *) {
106+
return existingPresentationManager
107+
} else {
108+
return presentationMode
109+
}
110+
} else {
111+
return presentationMode
112+
}
113+
} else {
114+
return self[_PresentationManagerEnvironmentKey.self]
115+
?? (_appKitOrUIKitViewControllerBox?.value?._cocoaPresentationCoordinator).flatMap({ CocoaPresentationMode(coordinator: $0) })
116+
?? presentationMode
117+
}
118+
#else
119+
return self[_PresentationManagerEnvironmentKey.self] ?? presentationMode
120+
#endif
121+
} set {
122+
self[_PresentationManagerEnvironmentKey.self] = newValue
123+
}
124+
}
125+
}

0 commit comments

Comments
 (0)