Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

SwiftUI refreshable never dismisses

$
0
0

I'm using .refreshable() on a List in SwiftUI. With the following code, I pull to refresh in an iOS 17.4 simulator, the spinner appears, and then goes away after a couple of seconds.

var body: some View {  List() {    // items ...  }  .refreshable { try? await Task.sleep(nanoseconds: 3_000_000_000) }}

However, when I put my actual refresh logic into the refreshable function, the spinner no longer goes away, even though my refresh function completes without error (which I verified using breakpoints in Xcode). Instead, the spinner just spins forever.

var body: some View {  List() {    // items ...  }  .refreshable { await query.refetchAsync() }}

query.refetchAsync() triggers a refetch that runs on a background Task and then waits for an update by iterating over a NotificationCenter.notifications() object returned by self.client.queryUpdatesAsync():

  public func refetchAsync() async {    self.refetch()    for await update in self.client.queryUpdatesAsync() {      if update.key != self.key { continue }      switch self.dataStatus {      case .idle, .pending: continue      default: break      }    }  }

How do I fix this bug?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>