Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliengdt/978b83b54d9ffc7f30cae28b94be2722 to your computer and use it in GitHub Desktop.
Save juliengdt/978b83b54d9ffc7f30cae28b94be2722 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