Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gumob/rxpulltorefresh
A Swift library allows you to create a flexibly customizable pull-to-refresh view supporting RxSwift.
https://github.com/gumob/rxpulltorefresh
animation ios pull-to-refresh pulltorefresh rxswift swift
Last synced: 11 days ago
JSON representation
A Swift library allows you to create a flexibly customizable pull-to-refresh view supporting RxSwift.
- Host: GitHub
- URL: https://github.com/gumob/rxpulltorefresh
- Owner: gumob
- License: mit
- Created: 2019-01-04T04:52:40.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-24T05:57:20.000Z (over 4 years ago)
- Last Synced: 2024-10-11T19:33:20.635Z (about 1 month ago)
- Topics: animation, ios, pull-to-refresh, pulltorefresh, rxswift, swift
- Language: Swift
- Homepage: https://gumob.github.io/RxPullToRefresh/index.html
- Size: 2.39 MB
- Stars: 17
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg)](https://github.com/gumob/RxPullToRefresh)
[![Version](http://img.shields.io/cocoapods/v/RxPullToRefresh.svg)](http://cocoadocs.org/docsets/RxPullToRefresh)
[![Platform](http://img.shields.io/cocoapods/p/RxPullToRefresh.svg)](http://cocoadocs.org/docsets/RxPullToRefresh)
[![Build Status](https://travis-ci.com/gumob/RxPullToRefresh.svg?branch=master)](https://travis-ci.com/gumob/RxPullToRefresh)
[![codecov](https://codecov.io/gh/gumob/RxPullToRefresh/branch/master/graph/badge.svg)](https://codecov.io/gh/gumob/RxPullToRefresh)
[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
![Language](https://img.shields.io/badge/Language-Swift%204.2-orange.svg)
![Packagist](https://img.shields.io/packagist/l/doctrine/orm.svg)# RxPullToRefresh
A Swift library allows you to create a flexibly customizable pull-to-refresh view supporting RxSwift.## Features
- Support UIScrollView, UITableView, and UICollectionView
- Customizable refresh view
- Customizable animaton options
- Configurable option whether to load while dragging or to load after an user release a finger
- Error handling
- Support RxSwift/RxCocoa## Requirements
- iOS 10.0 or later
- Swift 5.0 or later## Installation
### Carthage
Add the following to your `Cartfile` and follow [these instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application).
```
github "gumob/RxPullToRefresh" # Swift 5.0
github "gumob/RxPullToRefresh" ~> 1.0 # Swift 5.0
github "gumob/RxPullToRefresh" ~> 0.1 # Swift 4.2
```Do not forget to include RxSwift.framework and RxCocoa.framework. Otherwise it will fail to build the application.
### CocoaPods
To integrate RxPullToRefresh into your project, add the following to your `Podfile`.
```ruby
platform :ios, '10.0'
use_frameworks!pod 'RxPullToRefresh', '~> 1.0' # Swift 5.0
pod 'RxPullToRefresh', '~> 0.1' # Swift 4.2
```## Usage
Read the [API reference](https://gumob.github.io/RxPullToRefresh/Classes/RxPullToRefresh.html) and the [USAGE.md](https://gumob.github.io/RxPullToRefresh/usage.html) for detailed information.
### Basic Usage
#### Import frameworks to your project
```swift
import RxSwift
import RxCocoa
import RxPullToRefresh
```#### Add RxPullToRefresh
Create a RxPullToRefresh object.
```swift
// Create a RxPullToRefresh object
self.topPullToRefresh = RxPullToRefresh(position: .top)
// Add a RxPullToRefresh object to UITableView
self.tableView.p2r.addPullToRefresh(self.topPullToRefresh)
```#### Observe RxPullToRefreshDelegate
By observing [RxPullToRefreshDelegate](https://gumob.github.io/RxPullToRefresh/Protocols/RxPullToRefreshDelegate.html), you can watch the state of a RxPullToRefresh object. This delegate is get called by the RxPullToRefresh object every time its [state](https://gumob.github.io/RxPullToRefresh/Enums/RxPullToRefreshState.html) or scrolling rate is changed.
```swift
// Observe RxPullToRefreshDelegate
self.topPullToRefresh.rx.action
.subscribe(onNext: { [weak self] (state: RxPullToRefreshState, progress: CGFloat, scroll: CGFloat) in
// Send request if RxPullToRefreshState is changed to .loading
switch state {
case .loading: self?.prepend()
default: break
}
})
.disposed(by: self.disposeBag)
```#### Load and append contents
```swift
self.viewModel.prepend()
.subscribe(onSuccess: { [weak self] in
// Successfully loaded, collapse refresh view immediately
self?.tableView.p2r.endRefreshing(at: .top)
}, onError: { [weak self] (_: Error) in
// Failed to load, show error
self?.tableView.p2r.failRefreshing(at: .top)
})
.disposed(by: self.disposeBag)
```#### Disable refreshing by binding Boolean value to canLoadMore property
```swift
self.viewModel.canPrepend
.asDriver()
.drive(self.topPullToRefresh.rx.canLoadMore)
.disposed(by: self.disposeBag)
```#### Dispose RxPullToRefresh objects
```swift
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
self.tableView.p2r.endAllRefreshing()
self.tableView.p2r.removeAllPullToRefresh()
}
```### Advanced Usage
#### About the example project
`RxPullToRefresh` allows you flexibly customize a refresh view by inheriting [RxPullToRefresh](https://gumob.github.io/RxPullToRefresh/Classes/RxPullToRefresh.html) and [RxPullToRefreshView](https://gumob.github.io/RxPullToRefresh/Classes/RxPullToRefreshView.html) classes. Please check [example sources](https://github.com/gumob/RxPullToRefresh/blob/master/Example/) for advanced usage.
- [CustomRefresh](https://github.com/gumob/RxPullToRefresh/blob/master/Example/CustomRefresh.swift): A class inheriting from `RxPullToRefresh`.
- [CustomRefreshView](https://github.com/gumob/RxPullToRefresh/blob/master/Example/CustomRefresh.swift): A class inheriting from `RxPullToRefreshView`. Animation logics are implemented in this class.
- [BaseTableViewController](https://github.com/gumob/RxPullToRefresh/blob/master/Example/TableViewController.swift): A view controller that conforms to MVVM architecture.
- [CustomTableViewController](https://github.com/gumob/RxPullToRefresh/blob/master/Example/TableViewController.swift): A view controller that creates a `CustomPullToRefresh` instance.
- [TableViewModel](https://github.com/gumob/RxPullToRefresh/blob/master/Example/TableViewModel.swift): A view model that manipulates data sources.#### Build the example app
1. Update Carthage frameworks
```bash
$ carthage update --platform iOS
```
2. Open `RxPullToRefresh.xcodeproj`
3. Select the scheme `RxPullToRefreshExample` from the drop-down menu in the upper left of the Xcode window
4. Press ⌘R## Copyright
RxPullToRefresh is released under MIT license, which means you can modify it, redistribute it or use it however you like.