Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Sources/FlowStack/FlowTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
14 changes: 9 additions & 5 deletions Sources/FlowStack/View+InteractiveDismiss.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ struct InteractiveDismissContainer<T: View>: UIViewControllerRepresentable {
var threshold: Double

var onPan: (CGPoint) -> Void
var isEnabled: Bool
var isDismissing: Bool

var swipeUpToDismiss: Bool
Expand All @@ -56,11 +57,12 @@ struct InteractiveDismissContainer<T: View>: UIViewControllerRepresentable {
}

func updateUIViewController(_ uiViewController: InteractiveDismissViewController<T>, 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)
}
}

Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -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)
}
}