Guest User

Untitled

a guest
Jan 24th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import UIKit
  2. import ReactorKit
  3. import SkyFloatingLabelTextField
  4. import RxCocoa
  5. import RxSwift
  6.  
  7. class ViewController: UIViewController, UITextFieldForValidation {
  8.  
  9. internal let input = SkyFloatingLabelTextField(frame: CGRect.init(x: 50, y: 50, width: 300, height: 40))
  10.  
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. input.title = "Email"
  14. view.addSubview(input)
  15. self.reactor = EmailValidationReactor()
  16. }
  17. }
  18.  
  19. extension ViewController: View, HasDisposeBag {
  20. func bind(reactor: EmailValidationReactor) {
  21. self.bindEmailValidation(reactor: reactor)
  22. input.rx.text
  23. .map { Reactor.Action.setEmail($0) }
  24. .bind(to: reactor.action)
  25. .disposed(by: disposeBag)
  26. }
  27. }
  28.  
  29. extension Reactive where Base: SkyFloatingLabelTextField {
  30. var error: Binder<ValidationResult?> {
  31. return Binder(self.base) { input, validation in
  32. switch validation {
  33. case .no(let error)?:
  34. input.errorMessage = error
  35. default:
  36. input.errorMessage = ""
  37. }
  38. }
  39. }
  40. }
Add Comment
Please, Sign In to add comment