Access UIBarButtonItems tap?
Sajjon opened this issue · comments
Alexander Cyon commented
Hi! Would it be possible to extend RxViewController tap events of the optional leftBarButtonItem
and rightBarButtonItem
?
var leftBarButtonTapped: Driver<Void> { get }
var rightBarButtonTapped: Driver<Void> { get }
It would be awesome to listen to these!
Alexander Cyon commented
If using custom inside the barButtonItem, maybe something like:
extension Reactive where Base: UIViewController {
public var leftBarButtonTapped: ControlEvent<Void> {
guard let button = self.base.navigationItem.leftBarButtonItem?.customView as? UIButton else { return ControlEvent(events: Observable.empty()) }
return button.rx.tap
}
public var rightBarButtonTapped: ControlEvent<Void> {
guard let button = self.base.navigationItem.rightBarButtonItem?.customView as? UIButton else { return ControlEvent(events: Observable.empty()) }
return button.rx.tap
}
}
credit goes to @oscarsilver
Suyeol Jeon commented
It would not work if the left bar button is not a custom button. RxCocoa already supports UIBarButtonItem+Rx so you may use that.