mirror of
https://github.com/yattee/yattee.git
synced 2024-12-25 15:03:41 +00:00
23 lines
561 B
Swift
23 lines
561 B
Swift
|
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()
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
}
|