.onReceive construction isn't working with button long press gesture but tap is working, it increases count by 1. Construction should increase count every 0.5 seconds if button pressed
struct Test: View {
@State private var count = 0
@State private var isLongPressed = false
var body: some View {
VStack {
Text("Count: \(count)")
Button("Increase") {
count += 1
print("Button tapped")
}
.onLongPressGesture {
isLongPressed = true
print("Long press started")
}
.onLongPressGesture(minimumDuration: 0) {
isLongPressed = false
print("Long press ended")
}
}
.onReceive(Timer.publish(every: 0.5, on: .main, in: .common).autoconnect()) { _ in
if isLongPressed {
count += 1
print("Count increased: \(count)")
}
}
}
}
Post
Replies
Boosts
Views
Activity
I have a wave and I can change height (progress var). How I can output it in Text on the screen in another view?
Cup view
When I doing wave higher or lower it printed in console
I want to print on the screen
I have no idea what write instead Binding (it's a suggestion by Xcode)
I tried clean project with Shift + Command + K, there is no errors but any file preview won't load in this project. App can be compiled and started on iPhone. How fix it?
Xcode 13.2.1