Skip to content

Commit aa603ab

Browse files
committed
Ensures endRefreshing is called on the MainActor
1 parent 69f38bf commit aa603ab

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Sources/SwiftUIBackports/Shared/Refreshable/Refreshable.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ extension Backport where Wrapped: View {
4545

4646
#if os(iOS)
4747
private final class RefreshControl: UIRefreshControl {
48-
var handler: (() -> Void)?
48+
var handler: (() async -> Void)?
4949

5050
init(_ handler: @escaping () async -> Void) {
5151
super.init()
5252
self.handler = { [weak self] in
53-
Task {
53+
Task { [weak self] in
5454
await handler()
5555
self?.endRefreshing()
5656
}
@@ -59,8 +59,13 @@ private final class RefreshControl: UIRefreshControl {
5959
addTarget(self, action: #selector(update), for: .valueChanged)
6060
}
6161

62+
@MainActor
63+
override func endRefreshing() {
64+
super.endRefreshing()
65+
}
66+
6267
@objc private func update() {
63-
handler?()
68+
Task { await handler?() }
6469
}
6570

6671
required init?(coder: NSCoder) {

0 commit comments

Comments
 (0)