1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Gestures/View+SwipeGesture.swift

23 lines
561 B
Swift
Raw Normal View History

2021-10-21 03:51:50 +05:30
import SwiftUI
extension View {
func onSwipeGesture(
up: @escaping () -> Void = {},
down: @escaping () -> Void = {}
) -> some View {
gesture(
DragGesture(minimumDistance: 10)
.onEnded { gesture in
let translation = gesture.translation
if abs(translation.height) > 100_000 {
return
}
let isUp = translation.height < 0
isUp ? up() : down()
}
)
}
}