@@ -42,7 +42,6 @@ struct InteractiveDismissContainer<T: View>: UIViewControllerRepresentable {
4242 var threshold : Double
4343
4444 var onPan : ( CGPoint ) -> Void
45- var isEnabled : Bool
4645 var isDismissing : Bool
4746
4847 var swipeUpToDismiss : Bool
@@ -57,12 +56,11 @@ struct InteractiveDismissContainer<T: View>: UIViewControllerRepresentable {
5756 }
5857
5958 func updateUIViewController( _ uiViewController: InteractiveDismissViewController < T > , context: Context ) {
60- context. coordinator. isEnabled = isEnabled
6159 context. coordinator. isDismissing = isDismissing
6260 }
6361
6462 func makeCoordinator( ) -> InteractiveDismissCoordinator {
65- InteractiveDismissCoordinator ( threshold: threshold, onPan: onPan, isEnabled : isEnabled , isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded)
63+ InteractiveDismissCoordinator ( threshold: threshold, onPan: onPan, isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded)
6664 }
6765}
6866
@@ -127,12 +125,6 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
127125 var threshold : Double
128126
129127 var onPan : ( CGPoint ) -> Void
130- var isEnabled : Bool {
131- didSet {
132- panGestureRecognizer. isEnabled = isEnabled
133- edgeGestureRecognizer. isEnabled = isEnabled
134- }
135- }
136128 var isDismissing : Bool {
137129 didSet {
138130 guard isDismissing else { return }
@@ -177,11 +169,10 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
177169 }
178170 }
179171
180- init ( threshold: Double , onPan: @escaping ( CGPoint ) -> Void , isEnabled : Bool , isDismissing: Bool , swipeUpToDismiss: Bool , onDismiss: @escaping ( ) -> Void , onEnded: @escaping ( Bool ) -> Void ) {
172+ init ( threshold: Double , onPan: @escaping ( CGPoint ) -> Void , isDismissing: Bool , swipeUpToDismiss: Bool , onDismiss: @escaping ( ) -> Void , onEnded: @escaping ( Bool ) -> Void ) {
181173 self . threshold = threshold
182174
183175 self . onPan = onPan
184- self . isEnabled = isEnabled
185176 self . isDismissing = isDismissing
186177 self . swipeUpToDismiss = swipeUpToDismiss
187178 self . onDismiss = onDismiss
@@ -193,12 +184,10 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
193184
194185 self . panGestureRecognizer = UIPanGestureRecognizer ( target: self , action: #selector( panGestureUpdated ( recognizer: ) ) )
195186 self . panGestureRecognizer. delegate = self
196- self . panGestureRecognizer. isEnabled = isEnabled
197187
198188 self . edgeGestureRecognizer = UIScreenEdgePanGestureRecognizer ( target: self , action: #selector( edgeGestureUpdated ( recognizer: ) ) )
199189 self . edgeGestureRecognizer. edges = [ . left]
200190 self . edgeGestureRecognizer. delegate = self
201- self . edgeGestureRecognizer. isEnabled = isEnabled
202191
203192 self . panGestureRecognizer. require ( toFail: self . edgeGestureRecognizer)
204193 }
@@ -223,15 +212,14 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
223212 onPan ( offset)
224213
225214 let shouldDismiss = offset. y > threshold || ( offset. x > threshold && isEdge) || ( - offset. y > threshold * 2 && swipeUpToDismiss)
226- if shouldDismiss != isPastThreshold && shouldDismiss {
215+ if shouldDismiss != isPastThreshold && shouldDismiss, edgeGestureRecognizer . isEnabled , panGestureRecognizer . isEnabled {
227216 impactGenerator. impactOccurred ( )
228217 }
229218
230219 isPastThreshold = shouldDismiss
231220
232221 if hasEnded {
233222 if shouldDismiss {
234- isEnabled = false
235223 onDismiss ( )
236224 isPastThreshold = false
237225 } else {
@@ -290,7 +278,7 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
290278}
291279
292280extension View {
293- func onInteractiveDismissGesture( threshold: Double = 50 , isEnabled : Bool = true , isDismissing: Bool = false , swipeUpToDismiss: Bool , onDismiss: @escaping ( ) -> Void , onPan: @escaping ( CGPoint ) -> Void = { _ in } , onEnded: @escaping ( Bool ) -> Void = { _ in } ) -> some View {
294- InteractiveDismissContainer ( threshold: threshold, onPan: onPan, isEnabled : isEnabled , isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded, content: self )
281+ func onInteractiveDismissGesture( threshold: Double = 50 , isDismissing: Bool = false , swipeUpToDismiss: Bool , onDismiss: @escaping ( ) -> Void , onPan: @escaping ( CGPoint ) -> Void = { _ in } , onEnded: @escaping ( Bool ) -> Void = { _ in } ) -> some View {
282+ InteractiveDismissContainer ( threshold: threshold, onPan: onPan, isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded, content: self )
295283 }
296284}
0 commit comments