Created
September 27, 2016 07:33
-
-
Save devxoul/07cbc8e0307d769c3b0fd6357840da70 to your computer and use it in GitHub Desktop.
This file contains hidden or 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