Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/AppPear/SwiftUI-PullToRefresh
Pull to refresh in SwiftUI for List, NavigationView
https://github.com/AppPear/SwiftUI-PullToRefresh
Last synced: 2 months ago
JSON representation
Pull to refresh in SwiftUI for List, NavigationView
- Host: GitHub
- URL: https://github.com/AppPear/SwiftUI-PullToRefresh
- Owner: AppPear
- License: mit
- Created: 2019-09-15T18:30:58.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-29T09:41:18.000Z (over 4 years ago)
- Last Synced: 2024-11-09T19:39:47.218Z (2 months ago)
- Language: Swift
- Homepage:
- Size: 486 KB
- Stars: 411
- Watchers: 9
- Forks: 51
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- fucking-about-SwiftUI - Pull to Refresh
README
# SwiftUI-PullToRefresh
Pull to refresh implementation in SwiftUI for **List and NavigationView**
This article helped me a lot: https://swiftui-lab.com/scrollview-pull-to-refresh/
Thanks!![pulltorefresh](./pull.gif "pulltorefresh")
## Installation:
It requires iOS 13 and Xcode 11!
In Xcode got to `File -> Swift Packages -> Add Package Dependency` and paste inthe repo's url: `https://github.com/AppPear/SwiftUI-PullToRefresh`
## Usage:
You need to add `RefreshableNavigationView(title: String, action: () -> Void, content: () -> View)` to your View. Title is the navigationView title, and the action takes the refresh function. RefreshableNavigationView already encapsulates a List() so in the content you only need to define your cells. If you want TableViewCellSeparators don't forget to add a `Divider()` at the bottom of your cell.Example:
```swift
import SwiftUIPullToRefreshstruct ContentView: View {
@State var numbers:[Int] = [23,45,76,54,76,3465,24,423]
var body: some View {
RefreshableNavigationView(title: "Numbers", action:{
self.numbers = self.generateRandomNumbers()
}){
ForEach(self.numbers, id: \.self){ number in
VStack(alignment: .leading){
Text("\(number)")
Divider()
}
}
}
}
func generateRandomNumbers() -> [Int] {
var sequence = [Int]()
for _ in 0...30 {
sequence.append(Int.random(in: 0 ..< 100))
}
return sequence
}
}
```