Skip to content

Commit

Permalink
Improving gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
joogps committed Nov 21, 2020
1 parent 7ee473e commit 50e39e3
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions Sources/SlideOverCard/SlideOverCard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct SlideOverCardView<Content:View>: View {
self.content = content()
}

@State private var viewOffset: CGFloat = 0.0
@GestureState private var viewOffset: CGFloat = 0.0

public var body: some View {
VStack(alignment: .trailing, spacing: 0) {
Expand All @@ -49,17 +49,14 @@ public struct SlideOverCardView<Content:View>: View {
.gesture(
dragEnabled.wrappedValue ?
DragGesture()
.onChanged { gesture in
withAnimation(nil) {
viewOffset = gesture.translation.height
}
.updating($viewOffset) { value, state, transaction in
state = value.translation.height
}
.onEnded() { _ in
if viewOffset > 175 && dragToDismiss.wrappedValue {
.onEnded() { value in
if value.predictedEndTranslation.height > 175 && dragToDismiss.wrappedValue {
isPresented.wrappedValue = false
if (onDismiss != nil) { onDismiss!() }
}
viewOffset = .zero
} : nil
)
}
Expand Down

0 comments on commit 50e39e3

Please sign in to comment.