Refresh

repository·master·Indexed 19 days ago

https://github.com/wxxsw/refresh

A SwiftUI-native library for implementing pull-to-refresh headers and infinite scrolling footers in ScrollViews. It provides components such as RefreshHeader and RefreshFooter, along with modifiers like .noMore(), .preload(), and .enableRefresh() to manage data reloading and pagination.

Tokens
624
Snippets
2
Records
3
Agent score
18%

What's inside Refresh

  1. Implement pull-to-refresh and load-more with RefreshHeader and RefreshFooter

    master

    Refresh provides SwiftUI-native components for handling data refreshing and pagination within a ScrollView.

    Key Components:

    • RefreshHeader: Handles drop-down pull-to-refresh logic. It requires a binding to a refreshing state (refreshing:), an asynchronous or synchronous action to perform the reload, and a view builder to customize the refresh indicator UI.
    • RefreshFooter: Handles scroll-up to load more logic. It requires a binding to a refreshing state (refreshing:), an action to load more data, and a view builder for the footer UI.
    • .noMore(Bool): A modifier for RefreshFooter to indicate when no further data is available.
    • .preload(offset: Int): A modifier for RefreshFooter to trigger the load-more action before the user reaches the absolute bottom, based on a pixel offset.
    • .enableRefresh(): A modifier applied to the ScrollView to enable the refresh capabilities.
    ScrollView {
        RefreshHeader(refreshing: $headerRefreshing, action: reload) {
            if self.headerRefreshing {
                Text("refreshing...")
            } else {
                Text("Pull to refresh")
            }
        }
    
        ForEach(items) { item in
            YourCell(item: item)
        }
    
        RefreshFooter(refreshing: $footerRefreshing, action: loadMore) {
            if self.noMore {
                Text("No more data !")
            } else {
                Text("refreshing...")
            }
        }
        .noMore(noMore)
        .preload(offset: 50)
    }
    .enableRefresh()
  2. Install Refresh via Swift Package Manager

    master

    To add Refresh to your Xcode project using Swift Package Manager (SPM):

    1. In Xcode, navigate to File -> Swift Packages -> Add Package Dependency....
    2. Enter the repository URL: https://github.com/wxxsw/Refresh.
    3. Select the version you wish to use and complete the installation process.
    https://github.com/wxxsw/Refresh