working longpress gesture but not holding on press
This commit is contained in:
@@ -9,23 +9,37 @@ import SwiftUI
|
||||
|
||||
struct FooterControlsView: View {
|
||||
@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 {
|
||||
HStack(alignment: .center) {
|
||||
Spacer()
|
||||
|
||||
Button(action: {
|
||||
print("pressed button")
|
||||
}) {
|
||||
Image(systemName: viewModel.isRecording ? "waveform" : "mic.fill")
|
||||
.foregroundColor(.white)
|
||||
.padding()
|
||||
.background(NirvanaColor.teal)
|
||||
.clipShape(Circle())
|
||||
.shadow(radius: 10)
|
||||
}
|
||||
|
||||
Image(systemName: self.isPressingRecord ? "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,
|
||||
anchor: .center)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
|
||||
@@ -9,14 +9,6 @@ import Foundation
|
||||
|
||||
|
||||
final class FooterControlsViewModel: ObservableObject {
|
||||
@Published var isRecording: Bool = false
|
||||
|
||||
init() {
|
||||
|
||||
}
|
||||
|
||||
func onStartRecording() {
|
||||
self.isRecording = true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user