Giter VIP home page Giter VIP logo

rrpagingcollectionview's Introduction

RRPagingCollectionView

License: MIT Platform Swift 5.1

The simplest way to add paginate function to your collection view.
All you have to do is just set your collection view class in the storyboard to RRPagingCollectionView, and implement the RRPagingCollectionViewDelegate#paginate

Example

alt text

Requirements

pod 'RxCocoa'

pod 'RxSwift'

pod 'RxGesture'

pod 'Kingfisher'

Installation

Manually

  1. Download the project.
  2. Add RRPagingCollectionView.swift, RRPagingCollectionViewDelegate.swift & RRLoadingFooter.swift with necessary files in your project.
  3. Congratulations!

Usage example

First set your collection view class in the storyboard to RRPagingCollectionView

Then implement paginate function. If isLoading is set to true, an indicator is displayed at the bottom of the collection view. Otherwise, the indicator disappears and UICollectionView.reloadData is called.

//Create RRPagingCollectionView class CollectionView outlet and set storyboard file itself
@IBOutlet weak var collectionView: RRPagingCollectionView!

//set pagingDelegate in viewDidLoad method
collectionView.pagingDelegate = self

//Start paging animation while data load from server
// MARK: - PagingCollectionViewDelegate -
func paginateCtn(_ collectionView: RRPagingCollectionView, to page: Int) {
    if !collectionView.isLoading && totalDataCount > dataArray.count {
        collectionView.isLoading = true
        //API call for getting new data
    }
}

//Set loading CollectionView Loading Footer view
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
    return collectionView.collectionView(collectionView, viewForSupplementaryElementOfKind: kind, at: indexPath)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
    return collectionView.collectionView(collectionView, layout: collectionViewLayout, referenceSizeForHeaderInSection: section)
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
    return collectionView.collectionView(collectionView, layout: collectionViewLayout, referenceSizeForFooterInSection: section)
}

//Stop paging animation after get API response
collectionView.reloadData()
collectionView.isLoading = false

To run the example project, clone the repo, and run pod install from the Example directory first.

APIs

Name Type Description
pagingDelegate RRPagingCollectionViewDelegate Delegate pagination processing
currentPage Int Returns the current page
isLoading Bool Shows and hides the loading indicator. Reload collection view data after loading
reset() Void Return page to 0 and call paginate function

Contribute

We would love you for the contribution to RRPagingCollectionView, check the LICENSE file for more info.

License

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

rrpagingcollectionview's People

Contributors

rahul-mayani avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.