Add interactive swipe-to-dismiss for iOS toasts

Toast cards now follow the finger upward and dismiss on either a
sufficient drag or a fast flick (via predicted-end translation). The
auto-dismiss timer pauses while the user is dragging and re-arms if
they release without dismissing.
This commit is contained in:
Arkadiusz Fal
2026-05-08 03:00:29 +02:00
parent 4f763373c1
commit b163864628
3 changed files with 69 additions and 16 deletions

View File

@@ -380,6 +380,20 @@ final class ToastManager {
LoggingService.shared.info("Dismissed toast: \(id)", category: .general)
}
/// Cancel the pending auto-dismiss timer for a toast (e.g. while user is interacting with it).
func pauseAutoDismiss(id: UUID) {
dismissTasks[id]?.cancel()
dismissTasks.removeValue(forKey: id)
}
/// Re-arm the auto-dismiss timer for a toast using its original delay.
func resumeAutoDismiss(id: UUID) {
guard let toast = activeToasts.first(where: { $0.id == id }) else { return }
guard !toast.isPersistent || toast.autoDismissDelay > 0 else { return }
dismissTasks[id]?.cancel()
scheduleAutoDismiss(for: toast)
}
private func scheduleAutoDismiss(for toast: Toast) {
let task = Task { [weak self] in
try? await Task.sleep(for: .seconds(toast.autoDismissDelay))