@@ -51,38 +51,6 @@ public struct BooleanPresentationManager: PresentationManager {
51
51
}
52
52
}
53
53
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
-
86
54
// MARK: - Conformances -
87
55
88
56
public struct AnyPresentationManager : PresentationManager {
@@ -115,3 +83,43 @@ extension Binding: PresentationManager where Value == PresentationMode {
115
83
wrappedValue. dismiss ( )
116
84
}
117
85
}
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