Skip to content

Instantly share code, notes, and snippets.

@alldne
Created March 28, 2020 16:56
Show Gist options
  • Save alldne/79456afae60f6faba72b68be62091a57 to your computer and use it in GitHub Desktop.
Save alldne/79456afae60f6faba72b68be62091a57 to your computer and use it in GitHub Desktop.
RxSwift UIScrollView loadMore
extension Reactive where Base: UIScrollView {
var loadMore: Observable<Void> {
return contentOffset
.map({ [weak base] (offset) in
guard let scrollView = base else { return false }
return offset.y + scrollView.bounds.size.height - scrollView.adjustedContentInset.bottom >= scrollView.contentSize.height
})
.distinctUntilChanged()
.filter({ $0 })
.mapTo(Void())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment