Created
March 28, 2020 16:56
-
-
Save alldne/79456afae60f6faba72b68be62091a57 to your computer and use it in GitHub Desktop.
RxSwift UIScrollView loadMore
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 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