Created
October 19, 2018 09:12
-
-
Save Sajjon/94e7af9923b7eee9f74aacb787055a71 to your computer and use it in GitHub Desktop.
Simple Settings View
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
| import UIKit | |
| import RxSwift | |
| import RxCocoa | |
| // MARK: - SettingsView | |
| final class SettingsView: ScrollingStackView { | |
| private lazy var signOutButton: UIButton = "Sign out" | |
| // Two `UILabel`s grouped together | |
| private lazy var appVersionLabels = LabelsView( | |
| titleStyle: "App Version", | |
| valueStyle: "🤷♀️", | |
| stackViewStyle: UIStackView.Style(alignment: .center) | |
| ) | |
| // Config type used to create a UIStackView conforming to `ExpressibleByArrayLiteral` | |
| // initialized by UIViews as `arrangedSubviews` | |
| lazy var stackViewStyle: UIStackView.Style = [ | |
| signOutButton, | |
| appVersionLabels, | |
| .spacer | |
| ] | |
| } | |
| extension SettingsView: ViewModelled { | |
| typealias ViewModel = SettingsViewModel | |
| // Forward user input from this View to the ViewModel | |
| var inputFromView: ViewModel.Input { | |
| return ViewModel.Input( | |
| signOutTrigger: signOutButton.rx.tap.asDriver() | |
| ) | |
| } | |
| // Update this View with formatted data from the ViewModel | |
| func populate(with viewModel: ViewModel.Output) -> [Disposable] { | |
| // Populate `UILabel` in `LabelsView` holding value | |
| return [ | |
| viewModel.appVersion.drive(appVersionLabels.rx.value) | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment