Skip to content

Instantly share code, notes, and snippets.

@aabanaag
Created December 18, 2018 05:58
Show Gist options
  • Save aabanaag/f24d02e2f24d30e5da122e8b845dfe17 to your computer and use it in GitHub Desktop.
Save aabanaag/f24d02e2f24d30e5da122e8b845dfe17 to your computer and use it in GitHub Desktop.
UITableView nearBottom scroll
import UIKit
import RxSwift
import RxCocoa
extension Reactive where Base: UITableView {
var nearBottom: Driver<Bool> {
func isNearBottomEdge(tableView: UITableView, edgeOffset: CGFloat = 20.0) -> Bool {
return tableView.contentOffset.y + tableView.frame.size.height + edgeOffset > tableView.contentSize.height
}
return self.contentOffset.asDriver()
.flatMap { _ -> Driver<Bool> in
isNearBottomEdge(tableView: self.base, edgeOffset: 20.0) ? Driver.just(true) : Driver.just(false)
}
}
var isEmpty: Driver<Bool> {
func isTableEmpty(tableView: UITableView) -> Bool {
let rowCount: Int = tableView.numberOfRows(inSection: 0)
return (rowCount != 0)
}
return Driver.just(isTableEmpty(tableView: self.base))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment