Last active
June 30, 2018 19:33
-
-
Save bobgodwinx/fea906321ac1b5750bf82aa9cf11ac26 to your computer and use it in GitHub Desktop.
OST08
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
/// `ViewController` | |
class ViewController: UIViewController { | |
private let bag = DisposeBag() | |
private let indicator = PublishRelay<RxMBProgressHUD.State>() | |
private let viewModel: ViewModelType | |
init(_ viewModel: ViewModelType = ViewModel()) { | |
self.viewModel = viewModel | |
super.init(nibName: nil, bundle: nil) | |
configure() | |
} | |
required init?(coder aDecoder: NSCoder) { fatalError("Please initialise programmatically") } | |
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
indicator.accept(RxMBProgressHUD.State.show(view: self.view, animated: true)) | |
let imageView = configuredImageView() | |
view.addSubview(imageView) | |
viewModel | |
.source | |
.drive(imageView.rx.image) | |
.disposed(by: bag) | |
} | |
private func configure() { | |
self.view.backgroundColor = .red | |
indicator.bind(to: RxMBProgressHUD.shared).disposed(by: bag) | |
viewModel.finished | |
.subscribe(onCompleted: { self.indicator.accept(RxMBProgressHUD.State.hide(view: self.view, animated: true)) }) | |
.disposed(by: bag) | |
} | |
private func configuredImageView() -> UIImageView { | |
let imageView = UIImageView(frame: CGRect(x: 0, y: 0, width: 375.0, height: 668.0)) | |
imageView.contentMode = .scaleAspectFit | |
imageView.clipsToBounds = true | |
return imageView | |
} | |
} | |
// Present the view controller in the Live View window | |
PlaygroundPage.current.liveView = ViewController() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment