Last active
November 27, 2018 10:49
-
-
Save Sajjon/00df48ede361edf342cb9cf3af3cd411 to your computer and use it in GitHub Desktop.
Medium article: SLC part 1 - SignInView
This file contains hidden or 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
| final class SignInView: UIView { | |
| // Some loading view, it might contain a `UIActivityIndicatorView` | |
| // it has reactive binding for `isLoading`, but starts invisible | |
| private lazy var loadingView = LoadingView() | |
| // In fact these TextFields are some subclass capable of displaying validation errors | |
| private lazy var usernameField = UITextField() | |
| private lazy var passwordField = UITextField() | |
| private lazy var confirmPasswordField = UITextField() | |
| private lazy var signInButton = UIButton() | |
| .disabled() // button starts as disabled until form is valid | |
| private lazy var stackView = UIStackView(arrangedSubviews: [usernameField, passwordField, confirmPasswordField, signInButton]) | |
| // Call some setupViews methods, which populates the view and sets up constraints | |
| } | |
| extension SignInView: ViewModelled { | |
| typealias ViewModel = SignInViewModel | |
| var inputFromView: ViewModel.Input.FromView { | |
| return ViewModel.Input.FromView( | |
| username: usernameField.rx.text.orEmpty.asDriver(), | |
| password: passwordField.rx.text.orEmpty.asDriver(), | |
| confirmPassword: confirmPasswordField.rx.text.orEmpty.asDriver(), | |
| signInTrigger: signInButton.rx.tap.asDriver() | |
| ) | |
| } | |
| func populate(with viewModel: ViewModel.Output) -> [Disposable] { | |
| return [ | |
| output.isSignInButtonEnabled.drive(signInButton.rx.isEnabled), | |
| output.isSigningIn.drive(loadingView.rx.isLoading), | |
| // Simple means of displaying a validation error, if any. | |
| output.usernameValidation.drive(usernameField.rx.validation), | |
| // Confirm password and password validation are aggregated and displayed in `passwordField` | |
| output.passwordValidation.drive(passwordField.rx.validation) | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment