Latest 1.0.3
Homepage https://github.com/Vishal-Singh-Panwar/InfiniteScrolling
License MIT
Platforms ios 9.0
Authors

CI Status
Version
License
Platform
Code Climate

Add infinite scrolling to collection view.

This is a basic implementation to add infinite scrolling behaviour in a UICollectionView.

Usage

Usage is pretty simple. InfiniteScrollingBehaviour has one designated initializer.

init(withCollectionView collectionView: UICollectionView, andData dataSet: [InfiniteScollingData], delegate: InfiniteScrollingBehaviourDelegate, configuration: CollectionViewConfiguration = .default)

InfiniteScrollingData is a protocol which your modal needs to conform to. Right now its an empty protocol, but for scalability purpose, I felt like adding data set as collection of custom protocol instead of Any.

CollectionViewConfiguration can be used to tweak some behaviour of the infinite scrolling.
You neeed to provide layoutType and scrollingDirection. Based on these two properties, boundary elements are added as well as size for cell is calculated.
By default, InfiniteScrollingBehaviour has a CollectionViewConfiguration with layout value .numberOfCellsOnScreen(5) and scrollingDirection is horizontal.

LayoutType

LayoutType has two case:

  • case fixedSize(sizeValue: CGFloat, lineSpacing: CGFloat): If you need fixed size (if horizontal scrolling, sizeValue value will be cell’s width, whereas in vertical scrolling, it will be cell’s height. )
  • case numberOfCellOnScreen(Double): If you dont care about size and you need fixed number of elements on screen irrespective of screen size.

Incase you need to have infinite scrolling with pagination, enable pagination in the collectionView and pass in numberOfCellsOnScreen 1.

Note: Currently does not support custom flow layout and unequal cell sizes.

InfiniteScrollingBehaviourDelegate

The delegate has two methods.

func configuredCell(forItemAtIndexPath indexPath: IndexPath, originalIndex: Int, andData data: InfiniteScollingData, forInfiniteScrollingBehaviour behaviour: InfiniteScrollingBehaviour) -> UICollectionViewCell
func didSelectItem(atIndexPath indexPath: IndexPath, originalIndex: Int, andData data: InfiniteScollingData, inInfiniteScrollingBehaviour behaviour: InfiniteScrollingBehaviour) -> Void

First is a required method. Implementation needs to provide a configured UICollectionViewCell based on following parameters.

  • indexPath: Actual indexpath in the collectionView.
  • originalIndex: Index in the original data set.
  • data: InfiniteScollingData which will be used to configure your cell.

Note: If the number of elements in the data set is smaller than the maxNumberOfCellsOnScreen, than it automatically adjusts boundary to repeat the same elements on screen.

Example

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

2017-01-23 00_52_09

Requirements

  • Minimum iOS version: 9.0
  • Swift: 4.0
  • Xcode 8

Installation

InfiniteScrolling is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "InfiniteScrolling"

License

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

Latest podspec

{
    "name": "InfiniteScrolling",
    "version": "1.0.3",
    "summary": "Add infinite scrolling to collection view.",
    "description": "'This pod adds infinite scrolling ability in UICollectionView'.",
    "homepage": "https://github.com/Vishal-Singh-Panwar/InfiniteScrolling",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Vishal Singh Panwar": "[email protected]"
    },
    "source": {
        "git": "https://github.com/Vishal-Singh-Panwar/InfiniteScrolling.git",
        "tag": "1.0.3"
    },
    "platforms": {
        "ios": "9.0"
    },
    "source_files": "InfiniteScrolling/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This