Skip to content

🌀Pull to refresh and load more function for UIScrollView

License

Notifications You must be signed in to change notification settings

hoangtaiki/Refreshable

Repository files navigation

Refreshable

Version License Platform Language

Refreshable is a component that give pull to refresh and load more (infinite scrolling) feature for UIScrollView. By extension to UIScrollView, you can easily add features for any subclass of UIScrollView. Refreshable is developed to you can easily customize its UI style.

Requirements

  • Xcode 12 or later
  • iOS 13.0 or later
  • Swift 5.0 or later

Features

  • Support UIScrollView and its subclasses UICollectionView UITableView UITextView
  • Pull down to refresh and pull up to load more
  • Support customize your own style(s)

Getting Started

CocoaPods

Install with CocoaPods by adding the following to your Podfile:

platform :ios, '13.0'
use_frameworks!
pod 'Refreshable'

Swift Package Manager

Install with Swift Package Manager by adding the following to your Package.swift:

dependencies: [
    .package(url: "https://github.com/hoangtaiki/Refreshable", from: "1.3.0"),
],

Submodules

Or manually checkout the submodule with git submodule add git@github.com:hoangtaiki/Refreshable.git, drag Refreshable.xcodeproj to your project, and add Refreshable as a build dependency.

Usage

Add Pull to refresh

The easiest way to use the pull to refresh feature is use default style from us.

tableView.addPullToRefresh(action: { [weak self] in
    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
        self?.tableView.stopPullToRefresh()
    }
})

Add if you want to custom UI you just need conform the PullToRefreshDelegate protocol You can refer TextLoadingAnimator we implemented

Add Load more

tableView.addLoadMore(action: { [weak self] in
    DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
       	self?.tableView.stopLoadMore()
    }
})

We support disable load more when no more data

tableView.setLoadMoreEnable(false)

Use with RxSwift

I am a fan of reactive programming. I use RxSwift for my projects. If you want use Refreshable with RxSwift. Create new file with name Refreshable+Rx.swift then copy below code into that file.

import RxSwift
import RxCocoa
import Refreshable

extension Reactive where Base: UIScrollView {
    
    public var refreshing: Binder<Bool> {
        return Binder(base) { scrollView, isShow in
            if isShow {
            	scrollView.startPullToRefresh()
            } else {
                scrollView.stopPullToRefresh()
            }
        }
    }
    
    public var loadingMore: Binder<Bool> {
        return Binder(base) { scrollView, isShow in
            if isShow {
            	scrollView.startLoadMore()
            } else {
                scrollView.stopLoadMore()
            }
        }
    }

}

Contributing

We’re glad you’re interested in Refreshable, and we’d love to see where you take it. If you have suggestions or bug reports, feel free to send pull request or create new issue.

Thanks, and please do take it for a joyride!