Forked from devxoul/UICollectionView+RxReachedBottom.swift
Created
September 27, 2016 07:42
-
-
Save juliengdt/978b83b54d9ffc7f30cae28b94be2722 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UICollectionView { | |
public var rx_reachedBottom: Observable<Void> { | |
return self.rx.contentOffset | |
.map { contentOffset in | |
var responder: UIResponder = self | |
var viewController: UIViewController? = nil | |
while let next = responder.next { | |
viewController = next as? UIViewController | |
if viewController != nil { | |
break | |
} | |
responder = next | |
} | |
let statusBarHeight = UIApplication.shared.statusBarFrame.height | |
let navigationBarHeight = viewController?.navigationController?.navigationBar.bounds.height ?? 0 | |
let tabBarHeight = viewController?.tabBarController?.tabBar.bounds.height ?? 0 | |
let bottomOffset = contentOffset.y + self.contentInset.top + self.bounds.height | |
- statusBarHeight - navigationBarHeight - tabBarHeight | |
return bottomOffset >= self.contentSize.height - self.bounds.height / 2 | |
} | |
.distinctUntilChanged() | |
.filter { $0 } | |
.map { _ in Void() } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment