Hello,
I am encountering an issue with .refreshable(action:) in ScrollView.
The refresh action works as expected when performing a pull-to-refresh. However, if I put the app in the background while the refresh operation is in progress, the refresh indicator remains visible on the screen when I return to the foreground and does not disappear.
Once I interact with the ScrollView after returning to the foreground, the refresh indicator disappears, and the functionality itself is not affected.
I initially attempted to resolve this issue by triggering a view redraw when scenePhase changes. However, since my app presents the SwiftUI view using UIHostingController, the scenePhase from the environment does not seem to function correctly.
This issue occurs on iOS 17.1 but does not appear on iOS 16.1.1.
Is there a known way to resolve this unexpected behavior?
Below is a simplified sample code (some parts are omitted):
struct MyView: View {
@StateObject private var model: MyModel
var body: some View {
ScrollView {
// My ContentViews...
}
.refreshable {
do {
try await self.model.refresh()
} catch {
// Handle error
}
}
}
}
@MainActor
final class MyModel: ObservableObject {
// === Some Code ===
func refresh() async throws {
let data = try await self.fetchData()
self.data = Array(OrderedSet(data))
}
}
I apologize for any mistakes in my English, as I am using a translation tool. Thank you in advance for your help!
Best regards,