Skip to content

atsed/UIRefreshKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UIRefreshKit

Languages CocoaPods Compatible Swift Package Manager License MIT

UIRefreshKit is a custom library that provides customizable pull-to-refresh and automatic pagination functionality for UICollectionView and UITableView.

Features

  • Customizable Pull-to-Refresh
  • Automatic Pagination
  • Easy Integration

Installation

Swift Package Manager (SPM)

To install UIRefreshKit using SPM, add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/atsed/UIRefreshKit.git", from: "2.0.0")
]

Then, in the target dependencies section, include UIRefreshKit:

.target(
    name: "YourTargetName",
    dependencies: ["UIRefreshKit"]
)

CocoaPods

To install UIRefreshKit using CocoaPods, add the following to your Podfile:

pod 'UIRefreshKit', '~> 2.0.0'

Then run:

pod install

Usage

PullToRefresh

View PullToRefresh Animation

To add PullToRefresh to your screen, you need to set the pullToRefresh property for your table/collection view. You can use RefreshControl for this or create your own:

collectionView.pullToRefresh = RefreshControl()

The action to be performed when PullToRefresh is triggered is wrapped in a block:

collectionView.pullToRefreshAction = {
    // Your action
}

To check if the PullToRefresh animation is currently happening in the table/collection view, you can use the isPullToRefreshing property:

if collectionView.isPullToRefreshing {
    // Do something
}

To end the PullToRefresh animation, call the endPullToRefresh method:

collectionView.endPullToRefresh()

If you need to add a static inset from the top from which the PullToRefresh animation starts, use the setPullToRefreshStaticInsetTop method:

collectionView.setPullToRefreshStaticInsetTop(value: 10.0)

Automatic Pagination

View Pagination Animation

To add Automatic Pagination to your screen, you need to set the paginationRefresh property for your table/collection view. You can use RefreshControl for this or create your own:

collectionView.paginationRefresh = RefreshControl()

The action to be performed when Automatic Pagination is triggered is wrapped in a block:

collectionView.paginationRefreshAction = {
    // Your action
}

To check if the Automatic Pagination animation is currently happening in the table/collection view, you can use the isPaginationRefreshing property:

if collectionView.isPaginationRefreshing {
    // Do something
}

If you need to disable Automatic Pagination, for instance, in case of an error or when loading the last page, call the disablePaginationRefresh method:

collectionView.disablePaginationRefresh()

To resume Automatic Pagination, for instance, after recovering from an error, call the reloadPaginationRefresh method:

collectionView.reloadPaginationRefresh()

Creating a Custom RefreshControl

To create a custom RefreshControl, you need to inherit from BaseRefreshControl and implement the required methods:

class CustomRefreshControl: BaseRefreshControl {
    override func setProgress(to newProgress: CGFloat) {
        // Update the appearance of your custom refresh control based on the progress
    }

    override func startRefreshing() {
        // Start the refreshing animation and the haptic
    }

    override func endRefreshing() {
        // Stop the refreshing animation
    }

    override func resume() {
        // Resume or complete the animation based on the current state
    }
}

Example

Here is a basic example of how to use UIRefreshKit in a view controller:

import UIKit
import UIRefreshKit

class ViewController: UIViewController {

    @IBOutlet weak var collectionView: UICollectionView!

    override func viewDidLoad() {
        super.viewDidLoad()

        collectionView.pullToRefresh = RefreshControl()
        collectionView.pullToRefreshAction = { [weak self] in
            // PullToRefresh action
            DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
                self?.collectionView.endPullToRefresh()
            }
        }

        collectionView.paginationRefresh = RefreshControl(size: .small, isHapticEnabled: false)
        collectionView.paginationRefreshAction = { [weak self] in
            // Pagination action
            DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
                self?.collectionView.reloadPaginationRefresh()
            }
        }
    }
}

License

UIRefreshKit is available under the MIT license. See the LICENSE file for more info.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published