I wonder if there's a simple way to make visible the activity indicator used by the refresh control of a SwiftUI List
? This would provide a consistent appearance of a refreshing UI, regardless of how the refresh was initiated.
After enabling pull to refresh on a List
by using the refreshable
modifier, the List
s environment has its refresh
item set, which is a RefreshAction
used by the refresh control. My guess was that using this RefreshAction
would maybe also trigger the visibility of the refresh control, which I tried:
struct MyView : View {
@State var content: Content
var body: some View {
_MyView(content: $content)
.refreshable { // assigning `refresh` to the environment
await refresh()
}
}
private func refresh() async {
// ...
content = newContent
// ...
}
}
struct _MyView : View {
@Environment(\.refresh) private var refresh
// [ content binding, etc... ]
var body: some View {
List {
// ...
}
.onAppear {
Task { await refresh?() } // doesn't show the activity indicator of the list
}
}
}
This didn't work.
Since I can't find a isRefreshing
/refreshState
or similar property of EnvironmentValues
I'm wondering if maybe there's another (simple) way to trigger its appearance?