From ba9401d60562fc8397c261192675b4c10a13143f Mon Sep 17 00:00:00 2001 From: talksik Date: Sun, 12 Dec 2021 19:43:07 -0800 Subject: [PATCH] trying drag and longpress gestures together --- .../FooterControlsView.swift | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/nirvana-ios/Views/FooterControlsView/FooterControlsView.swift b/nirvana-ios/Views/FooterControlsView/FooterControlsView.swift index afef137..6240a42 100644 --- a/nirvana-ios/Views/FooterControlsView/FooterControlsView.swift +++ b/nirvana-ios/Views/FooterControlsView/FooterControlsView.swift @@ -10,19 +10,44 @@ import SwiftUI struct FooterControlsView: View { @StateObject var viewModel:FooterControlsViewModel = FooterControlsViewModel() - @GestureState var isPressingRecord: Bool = false + @GestureState var isLongPressingRecord: Bool = false + @State var isHolding = false @State var completedLongPress = false + var dragGesture: some Gesture { + DragGesture(minimumDistance: 0, coordinateSpace: .local) + .onChanged {_ in + self.isHolding = true + + print("started drag") + + } + .onEnded {_ in + self.isHolding = false + + print("ended drag") + + } + } + var longPress: some Gesture { LongPressGesture(minimumDuration: 1) - .updating($isPressingRecord) { currentState, gestureState, + .updating($isLongPressingRecord) { currentState, gestureState, transaction in gestureState = currentState transaction.animation = Animation.easeIn(duration: 2.0) + + self.isHolding = true + + print("started long press") } .onEnded { finished in print(finished) self.completedLongPress = finished + + self.isHolding = false + + print("ended long press") } } @@ -30,16 +55,19 @@ struct FooterControlsView: View { HStack(alignment: .center) { Spacer() - Image(systemName: self.isPressingRecord ? "waveform" : "mic.fill") + Image(systemName: self.isHolding ? "waveform" : "mic.fill") .foregroundColor(.white) .padding() .background(NirvanaColor.teal) .clipShape(Circle()) .shadow(radius: 10) .gesture(longPress) - .scaleEffect(x: self.isPressingRecord ? 1.2: 1, - y: self.isPressingRecord ? 1.2: 1, + .simultaneousGesture(dragGesture) + .scaleEffect(x: self.isHolding ? 1.2: 1, + y: self.isHolding ? 1.2: 1, anchor: .center) + + Text("currently is \(self.isHolding ? "recording": "not recording")") } .padding() }