working longpress gesture but not holding on press

This commit is contained in:
talksik
2021-12-12 19:07:06 -08:00
parent b5faa82a16
commit 3c8b6b6d48
2 changed files with 26 additions and 20 deletions
@@ -9,23 +9,37 @@ import SwiftUI
struct FooterControlsView: View { struct FooterControlsView: View {
@StateObject var viewModel:FooterControlsViewModel = FooterControlsViewModel() @StateObject var viewModel:FooterControlsViewModel = FooterControlsViewModel()
@State private var scaleValue = CGFloat(1)
@GestureState var isPressingRecord: Bool = false
@State var completedLongPress = false
var longPress: some Gesture {
LongPressGesture(minimumDuration: 1)
.updating($isPressingRecord) { currentState, gestureState,
transaction in
gestureState = currentState
transaction.animation = Animation.easeIn(duration: 2.0)
}
.onEnded { finished in
print(finished)
self.completedLongPress = finished
}
}
var body: some View { var body: some View {
HStack(alignment: .center) { HStack(alignment: .center) {
Spacer() Spacer()
Button(action: { Image(systemName: self.isPressingRecord ? "waveform" : "mic.fill")
print("pressed button") .foregroundColor(.white)
}) { .padding()
Image(systemName: viewModel.isRecording ? "waveform" : "mic.fill") .background(NirvanaColor.teal)
.foregroundColor(.white) .clipShape(Circle())
.padding() .shadow(radius: 10)
.background(NirvanaColor.teal) .gesture(longPress)
.clipShape(Circle()) .scaleEffect(x: self.isPressingRecord ? 1.2: 1,
.shadow(radius: 10) y: self.isPressingRecord ? 1.2: 1,
} anchor: .center)
} }
.padding() .padding()
} }
@@ -9,14 +9,6 @@ import Foundation
final class FooterControlsViewModel: ObservableObject { final class FooterControlsViewModel: ObservableObject {
@Published var isRecording: Bool = false
init() {
}
func onStartRecording() {
self.isRecording = true
}
} }