SwiftUI Pull to Refresh in 100 lines of code
SwiftUI Pull to Refresh
⇣ SwiftUI Pull to Refresh in 100 lines of code.
Complementary repository for article [SwiftUI Pull to Refresh] (in progress). See [ContentView.swift
] for usage, and [RefreshControl.swift
] for the source.
struct ContentView: View {
@State var isRefreshing: Bool = false
var body: some View {
List {
RefreshControl(isRefreshing: $isRefreshing) {
self.refresh()
}
ForEach(1...100, id: \.self) { eachRowIndex in
Text("Row \(eachRowIndex)")
}
.opacity(isRefreshing ? 0.2 : 1.0)
}
.onAppear {
self.isRefreshing = true
self.refresh()
}
}
func refresh() {
DispatchQueue.main.asyncAfter(deadline: .now() + 3.0) {
self.isRefreshing = false
}
}
}
GitHub
https://github.com/Geri-Borbas/iOS.Blog.SwiftUI_Pull_to_Refresh