Created
February 6, 2018 22:23
-
-
Save alanf/3d08c6a42ae1fb33470adf879956299d to your computer and use it in GitHub Desktop.
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 Foundation | |
import ReactiveKit | |
import Bond | |
import UIKit | |
protocol SimpleAlertDelegate: class { | |
func didTapSecondaryButton(alertViewController: SimpleAlertViewController) | |
func didTapPrimaryButton(alertViewController: SimpleAlertViewController) | |
} | |
class SimpleAlertViewController: UIViewController { | |
@IBOutlet weak var titleLabel: UILabel! | |
@IBOutlet weak var messageTextView: UITextView! | |
@IBOutlet weak var secondaryButton: UIButton! | |
@IBOutlet weak var primaryButton: UIButton! | |
struct ViewModel { | |
let title = Property<String?>(nil) | |
let message = Property<String?>(nil) | |
let primaryButtonTitle = Property<String?>(nil) | |
let secondaryButtonTitle = Property<String?>(nil) | |
} | |
private weak var delegate: SimpleAlertDelegate? | |
private var viewModel: ViewModel? | |
func configure(viewModel: ViewModel, delegate: SimpleAlertDelegate) { | |
self.delegate = delegate | |
self.viewModel = viewModel | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
guard let viewModel = viewModel else { fatalError() } | |
viewModel.title.bind(to: titleLabel).dispose(in: bag) | |
viewModel.message.bind(to: messageTextView).dispose(in: bag) | |
viewModel.primaryButtonTitle.bind(to: primaryButton.reactive.title).dispose(in: bag) | |
viewModel.secondaryButtonTitle.bind(to: secondaryButton.reactive.title).dispose(in: bag) | |
} | |
@IBAction func didTapSecondaryButton(_ sender: Any) { | |
delegate?.didTapSecondaryButton(alertViewController: self) | |
} | |
@IBAction func didTapPrimaryButton(_ sender: Any) { | |
delegate?.didTapPrimaryButton(alertViewController: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment