Created
October 5, 2018 02:53
-
-
Save Revolucent/416fb22b9c39e29ec35001378fc9752f to your computer and use it in GitHub Desktop.
isFirstResponder observable with RxSwift
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
import RxCocoa | |
import RxSwift | |
import UIKit | |
extension Reactive where Base: UIView { | |
var isFirstResponder: Observable<Bool> { | |
return Observable | |
.merge( | |
methodInvoked(#selector(UIView.becomeFirstResponder)), | |
methodInvoked(#selector(UIView.resignFirstResponder)) | |
) | |
.map{ [weak view = self.base] _ in | |
view?.isFirstResponder ?? false | |
} | |
.startWith(base.isFirstResponder) | |
.distinctUntilChanged() | |
.share(replay: 1) | |
} | |
} |
I haven't used this in quite a while. It worked at the time. What does not work?
Seems to work for me...
Works fine for me, thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't work.