Latest 1.0.0
Homepage https://github.com/pgherveou/RxPager
License MIT
Platforms ios 8.0
Dependencies RxSwift
Authors

CI Status
Version
License
Platform

Usage

// MARK: Example 1

typealias Page = [Int]
typealias Callback = () -> Void

// take previous Page, and create next one
let nextPage = { (previousPage: Page?) -> Observable<Page> in
let last = previousPage?.last ?? 0
return Observable.just([last + 1, last + 2, last + 3])
}

// return true if there are more pages to be emitted
let hasNext = { (page: Page) -> Bool in
guard let last = page.last else { return true }
return last < 10 // arbitrary condition for the demo
}

// create the pager
let trigger = PublishSubject<Void>()
let page$ = Observable.page(nextPage, while: hasNext, when: trigger)
let next = trigger.onNext

page$.subscribe(onNext: { print($0) })
// print [1, 2 ,3]

next() // print [4, 5, 6]
next() // print [7, 8, 9]
next() // print [10, 11, 12]

// MARK: Example 2 (page from array)

Observable
.page(Array(1...10), by: 3, when: trigger)
.subscribe(onNext: { print($0) })

// print [1, 2 ,3]
next() // print [4, 5, 6]
next() // print [4, 5, 6]
next() // print [10]

See Demo for more examples

Example

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

Requirements

Installation

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

pod "RxPager"

Credits

This pod is inspired by inspired by @mttkay work https://gist.github.com/mttkay/24881a0ce986f6ec4b4d
and was refactored using ideas discussed here https://github.com/RxSwiftCommunity/RxSwiftExt/issues/30

License

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

Latest podspec

{
    "name": "RxPager",
    "version": "1.0.0",
    "summary": "A simple Pager class fo Rx.",
    "homepage": "https://github.com/pgherveou/RxPager",
    "license": "MIT",
    "authors": {
        "Pierre-Guillaume Herveou": "[email protected]"
    },
    "source": {
        "git": "https://github.com/pgherveou/RxPager.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/pgherveou",
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "RxPager/Classes/**/*",
    "dependencies": {
        "RxSwift": [
            "~> 3.0.0-beta.1"
        ]
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This