Skip to content
Merged
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
12 changes: 8 additions & 4 deletions Sources/FlowStack/View+InteractiveDismiss.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct InteractiveDismissContainer<T: View>: UIViewControllerRepresentable {

class InteractiveDismissViewController<Content: View>: UIHostingController<Content> {

var coordinator: InteractiveDismissCoordinator
private var coordinator: InteractiveDismissCoordinator
private var frameObservation: NSKeyValueObservation?

init(rootView: Content, coordinator: InteractiveDismissCoordinator) {
Expand All @@ -83,7 +83,7 @@ class InteractiveDismissViewController<Content: View>: UIHostingController<Conte
frameObservation = view.observe(\.frame) { [weak self] theView, _ in
guard let self = self else { return }
self.additionalSafeAreaInsets = UIEdgeInsets(
top: theView.overlappingTopInset,
top: coordinator.isUpdating ? theView.overlappingTopInset : 0,
left: 0,
bottom: 0,
right: 0
Expand Down Expand Up @@ -144,6 +144,9 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
private var panGestureRecognizer: UIPanGestureRecognizer!
private var edgeGestureRecognizer: UIScreenEdgePanGestureRecognizer!

/// Bool that tracks active dragging to be used to track tool bar position for overlappingTopInset
@Published var isUpdating: Bool = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Maybe private here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zac Has to be public so that the InteractiveDismissViewController has access to it.


private var isPastThreshold: Bool = false
private var impactGenerator: UIImpactFeedbackGenerator

Expand Down Expand Up @@ -197,7 +200,6 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
private func edgeGestureUpdated(recognizer: UIScreenEdgePanGestureRecognizer) {
guard let view = recognizer.view else { return }
let offset = recognizer.translation(in: view)

update(offset: offset, isEdge: true, hasEnded: recognizer.state == .ended)
}

Expand All @@ -210,6 +212,7 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
}

private func update(offset: CGPoint, isEdge: Bool, hasEnded: Bool) {
isUpdating = true
onPan(offset)

let shouldDismiss = offset.y > threshold || (offset.x > threshold && isEdge)
Expand All @@ -224,8 +227,9 @@ class InteractiveDismissCoordinator: NSObject, ObservableObject, UIGestureRecogn
isEnabled = false
onDismiss()
isPastThreshold = false
} else {
isUpdating = false
}

onEnded(shouldDismiss)
}
}
Expand Down
Loading