RxReusable
RxReusable provides some APIs for managing life cycle of reusable cells and views.
APIs
⚠️ In order to use these features properly, you should set delegate by usingrx.setDelegate(_:).UITableView
- tableView.delegate = self + tableView.rx.setDelegate(self)UICollectionView
- collectionView.delegate = self + collectionView.rx.setDelegate(self)
-
var disposeBag: DisposeBagUITableViewCellandUICollectionViewnow has their owndisposeBagas a property. The dispose bag is automatically disposed onprepareForReuse().observable .subscribe() .addDisposableTo(cell.disposeBag)
-
var isDisplaying: ControlEvent<Bool>The reactive wrapper for the cell or view is currently displaying or not. This will emit
truewhen thetableView(_:willDisplay:forRowAt:)orcollectionView(_:willDisplay:forItemAt:)is executed andfalsewhen thetableView(_:didEndDisplaying:forRowAt:)orcollectionView(_:didEndDisplaying:forItemAt:)is executed.cell.rx.isDisplaying .subscribe(onNext: { isDisplaying in print("Cell became \(isDisplaying ? "visible" : "invisible")") })
-
func whileDisplaying(_:_:)This operator makes the observable emit items only when the cell or view is currently displaying or not.
observable.whileDisplaying(cell, true) // emit items when the cell is visible observable.whileDisplaying(cell, false) // emit items when the cell is not visible
Dependencies
Requirements
- Swift 3
- iOS 8+
Installation
License
RxReusable is under MIT license.
