diff --git a/Sources/FlowStack/FlowTransition.swift b/Sources/FlowStack/FlowTransition.swift index 30edb9f..55a7014 100644 --- a/Sources/FlowStack/FlowTransition.swift +++ b/Sources/FlowStack/FlowTransition.swift @@ -162,11 +162,10 @@ extension AnyTransition { let scaleRatio = context.shouldScaleHorizontally ? zoomRect.size.width / proxy.size.width : 1.0 content - .onInteractiveDismissGesture(threshold: 80, isDismissing: isDismissing, swipeUpToDismiss: context.swipeUpToDismiss, onDismiss: { + .onInteractiveDismissGesture(threshold: 80, isEnabled: !isDisabled, isDismissing: isDismissing, swipeUpToDismiss: context.swipeUpToDismiss, onDismiss: { defer { isDismissing = true } guard !isDisabled else { return } dismiss() - isDismissing = true }, onPan: { offset in defer { self.isEnded = false } guard !isDisabled else { return } diff --git a/Sources/FlowStack/View+InteractiveDismiss.swift b/Sources/FlowStack/View+InteractiveDismiss.swift index c19ca55..3e6ed07 100644 --- a/Sources/FlowStack/View+InteractiveDismiss.swift +++ b/Sources/FlowStack/View+InteractiveDismiss.swift @@ -42,6 +42,7 @@ struct InteractiveDismissContainer: UIViewControllerRepresentable { var threshold: Double var onPan: (CGPoint) -> Void + var isEnabled: Bool var isDismissing: Bool var swipeUpToDismiss: Bool @@ -56,11 +57,12 @@ struct InteractiveDismissContainer: UIViewControllerRepresentable { } func updateUIViewController(_ uiViewController: InteractiveDismissViewController, context: Context) { + context.coordinator.isEnabled = isEnabled context.coordinator.isDismissing = isDismissing } func makeCoordinator() -> InteractiveDismissCoordinator { - InteractiveDismissCoordinator(threshold: threshold, onPan: onPan, isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded) + InteractiveDismissCoordinator(threshold: threshold, isEnabled: isEnabled, onPan: onPan, isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded) } } @@ -125,6 +127,7 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn var threshold: Double var onPan: (CGPoint) -> Void + var isEnabled: Bool var isDismissing: Bool { didSet { guard isDismissing else { return } @@ -169,10 +172,11 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn } } - init(threshold: Double, onPan: @escaping (CGPoint) -> Void, isDismissing: Bool, swipeUpToDismiss: Bool, onDismiss: @escaping () -> Void, onEnded: @escaping (Bool) -> Void) { + init(threshold: Double, isEnabled: Bool, onPan: @escaping (CGPoint) -> Void, isDismissing: Bool, swipeUpToDismiss: Bool, onDismiss: @escaping () -> Void, onEnded: @escaping (Bool) -> Void) { self.threshold = threshold self.onPan = onPan + self.isEnabled = isEnabled self.isDismissing = isDismissing self.swipeUpToDismiss = swipeUpToDismiss self.onDismiss = onDismiss @@ -212,7 +216,7 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn onPan(offset) let shouldDismiss = offset.y > threshold || (offset.x > threshold && isEdge) || (-offset.y > threshold * 2 && swipeUpToDismiss) - if shouldDismiss != isPastThreshold && shouldDismiss, edgeGestureRecognizer.isEnabled, panGestureRecognizer.isEnabled { + if shouldDismiss != isPastThreshold && shouldDismiss, isEnabled { impactGenerator.impactOccurred() } @@ -278,7 +282,7 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn } extension View { - 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 { - InteractiveDismissContainer(threshold: threshold, onPan: onPan, isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded, content: self) + 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 { + InteractiveDismissContainer(threshold: threshold, onPan: onPan, isEnabled: isEnabled, isDismissing: isDismissing, swipeUpToDismiss: swipeUpToDismiss, onDismiss: onDismiss, onEnded: onEnded, content: self) } }