I have a SwiftUI List with .refreshable modifier that works perfectly when users manually pull to refresh.
However, I need to programmatically trigger the same refresh animation when certain conditions change (like triggered by a Button action).
When refresh() is triggered by Button, I want to show the same pull-to-refresh loading animation that appears when users manually pull down the refreshable. Currently, it seems only manually pull-to-refresh can triggers the animation?
struct ContentView: View {
@State private var refreshTimes = 0
var body: some View {
List{
Text("refresh times: \(refreshTimes)")
Button("click me to refresh") {
refresh()
}
}
.refreshable {
refresh()
}
}
func refresh() {
refreshTimes += 1
print("refresh at :\(Date())")
}
}
Question:
Is there a way to programmatically trigger SwiftUI's native .refreshable loading animation, or do I need to implement a custom refresh indicator that mimics the native appearance?