Giter Site home page Giter Site logo

hyouuu / infinitescrolling Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vishal-singh-panwar/infinitescrolling

0.0 3.0 0.0 50 KB

Add infinite scrolling to collection view.

License: MIT License

Swift 47.32% Objective-C 4.27% Ruby 4.78% Shell 43.63%

infinitescrolling's Introduction

InfiniteScrolling

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: 3.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.

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.