简体   繁体   中英

RxSwift Observable.empty() is calling onNext

detect when reached tableview bottom if not bottom return Observable.empty() if tableview is bottom return Observable.just(())

as i Know is Observable.empty() is not calling onNext

but empty() or just() calling onNext

tableView.rx.contentOffset
            .map {
                self.isNearTheBottomEdge(contentOffset: $0, self.tableView) && self.postModel.isLoadingComplete.value
                    ? Observable.just(())
                    : Observable.empty()
            }
            .throttle(3, scheduler: MainScheduler.instance)

            .subscribe(onNext: {
                print("reached bottom")
                self.postModel.nextPage.onNext(())
            },onCompleted: {
                print("complete")
            }
            )
            .disposed(by: disposeBag)

return Observable.empty() in debug but always print("reached bottom")

If you want to have subscribe(onNext) to be not called on Observable.empty(), just change .map{} to .flatMap{}

tableView.rx.contentOffset
            .flatMap {
                self.isNearTheBottomEdge(contentOffset: $0, self.tableView) && self.postModel.isLoadingComplete.value
                    ? Observable.just(())
                    : Observable.empty()
            }

Here you can read about difference between map vs flatMap

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM