Skip to content

Commit

Permalink
Prevent task from being called multiple times on iOS 14 (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamede1945 authored Jan 11, 2024
1 parent 6935abc commit a9c9fa8
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,16 @@ public struct BackwardCompatibleTaskModifier: ViewModifier {
} else {
content
.onAppear {
if appeared {
return
}
appeared = true
task = Task {
await action()
}
}
.onDisappear {
appeared = false
task?.cancel()
task = nil
}
Expand All @@ -55,4 +60,5 @@ public struct BackwardCompatibleTaskModifier: ViewModifier {
private var priority: TaskPriority
private var action: @Sendable () async -> Void
@State private var task: Task<Void, Never>?
@State private var appeared = false
}

0 comments on commit a9c9fa8

Please sign in to comment.