Swipe to Dismiss Images

Closes: #343
This commit is contained in:
Joel Klabo authored and William Casarin committed 2023-01-18 13:36:57 -08:00
1 parent 8ffa8446b6
commit 1ecfb0487e
4 files changed
+54 -2

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
//
// SwipeToDismiss.swift
// damus
//
// Created by Joel Klabo on 1/18/23.
//
import SwiftUI
struct SwipeToDismissModifier: ViewModifier {
var onDismiss: () -> Void
@State private var offset: CGSize = .zero
func body(content: Content) -> some View {
content
.offset(y: offset.height)
.animation(.interactiveSpring(), value: offset)
.simultaneousGesture(
DragGesture()
.onChanged { gesture in
if gesture.translation.width < 50 {
offset = gesture.translation
}
}
.onEnded { _ in
if abs(offset.height) > 100 {
onDismiss()
} else {
offset = .zero
}
}
)
}
}