Skip to content

Commit

Permalink
Update to internal onPreferenceChange function so it runs on the main…
Browse files Browse the repository at this point in the history
… actor in Swift 5 as well.
  • Loading branch information
ryanlintott committed Nov 29, 2024
1 parent a7a7d88 commit 3b46ddc
Showing 1 changed file with 0 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@ import SwiftUI

internal extension View {
@preconcurrency @inlinable nonisolated func onPreferenceChangeMainActor<K>(_ key: K.Type = K.self, perform action: @escaping @MainActor (K.Value) -> Void) -> some View where K : PreferenceKey, K.Value : Equatable & Sendable {
#if swift(>=6)
onPreferenceChange(key) { newValue in
Task { @MainActor in
action(newValue)
}
}
#else
onPreferenceChange(key, perform: action)
#endif
}
}

0 comments on commit 3b46ddc

Please sign in to comment.