From 50e39e3ed2e7614d56c82231be5b2f1fa44a3311 Mon Sep 17 00:00:00 2001 From: joogps Date: Sat, 21 Nov 2020 20:23:32 -0300 Subject: [PATCH] Improving gestures --- Sources/SlideOverCard/SlideOverCard.swift | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/Sources/SlideOverCard/SlideOverCard.swift b/Sources/SlideOverCard/SlideOverCard.swift index 83b2cd3..b1ecb12 100644 --- a/Sources/SlideOverCard/SlideOverCard.swift +++ b/Sources/SlideOverCard/SlideOverCard.swift @@ -27,7 +27,7 @@ public struct SlideOverCardView: 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) { @@ -49,17 +49,14 @@ public struct SlideOverCardView: 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 ) }