Skip to content

Instantly share code, notes, and snippets.

@devxoul
Created September 27, 2016 07:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save devxoul/07cbc8e0307d769c3b0fd6357840da70 to your computer and use it in GitHub Desktop.
Save devxoul/07cbc8e0307d769c3b0fd6357840da70 to your computer and use it in GitHub Desktop.
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