We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
.every(_:perform:)
1 parent f22edbc commit 9042fcbCopy full SHA for 9042fcb
Sources/ShinySwiftUI/Extensions/SwiftUI/View/View.swift
@@ -308,9 +308,14 @@ public extension View {
308
- parameter action: The action to perform.
309
*/
310
func every(_ interval: TimeInterval, perform action: @escaping () -> Void) -> some View {
311
- self.onReceive(Timer.publish(every: interval, on: .main, in: .common).autoconnect()) { _ in
312
- action()
313
- }
+ let timer = Timer.publish(every: interval, on: .main, in: .common).autoconnect()
+ return self
+ .onReceive(timer) { _ in
314
+ action()
315
+ }
316
+ .onDisappear {
317
+ timer.upstream.connect().cancel()
318
319
}
320
321
/**
0 commit comments