updated
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
788b226104
commit
d36aa00932
@ -47,7 +47,7 @@ class CheckboxViewController: UIViewController, StoryboardInitable {
|
|||||||
disabledSwitch.isOn = model.selected
|
disabledSwitch.isOn = model.selected
|
||||||
labelTextField.text = model.labelText
|
labelTextField.text = model.labelText
|
||||||
childTextField.text = model.childText
|
childTextField.text = model.childText
|
||||||
showErrorSwitch.isOn = model.showError
|
showErrorSwitch.isOn = model.hasError
|
||||||
errorTextField.text = model.errorText
|
errorTextField.text = model.errorText
|
||||||
|
|
||||||
checkbox = Checkbox(with: model)
|
checkbox = Checkbox(with: model)
|
||||||
@ -76,7 +76,7 @@ class CheckboxViewController: UIViewController, StoryboardInitable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func showErrorChanged(_ sender: UISwitch) {
|
@IBAction func showErrorChanged(_ sender: UISwitch) {
|
||||||
checkbox.showError = sender.isOn
|
checkbox.hasError = sender.isOn
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
|
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
|
||||||
|
|||||||
@ -13,11 +13,16 @@ struct MenuComponent {
|
|||||||
var viewController: UIViewController.Type
|
var viewController: UIViewController.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protocol Initable {
|
||||||
|
init()
|
||||||
|
}
|
||||||
|
|
||||||
class MenuViewController: UITableViewController {
|
class MenuViewController: UITableViewController {
|
||||||
let items: [MenuComponent] = [
|
let items: [MenuComponent] = [
|
||||||
MenuComponent(title: "Toggle", viewController: ToggleViewController.self),
|
MenuComponent(title: "Toggle", viewController: ToggleViewController.self),
|
||||||
MenuComponent(title: "Checkbox", viewController: CheckboxViewController.self),
|
MenuComponent(title: "Checkbox", viewController: CheckboxViewController.self),
|
||||||
MenuComponent(title: "RadioButton", viewController: RadioButtonViewController.self)
|
MenuComponent(title: "RadioButton", viewController: RadioButtonViewController.self),
|
||||||
|
MenuComponent(title: "Test", viewController: TestViewController.self)
|
||||||
]
|
]
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
@ -47,14 +52,23 @@ class MenuViewController: UITableViewController {
|
|||||||
let viewController = type.instantiate()
|
let viewController = type.instantiate()
|
||||||
viewController.title = item.title
|
viewController.title = item.title
|
||||||
split.showDetailViewController(viewController, sender: nil)
|
split.showDetailViewController(viewController, sender: nil)
|
||||||
|
} else if let type = item.viewController as? Initable.Type {
|
||||||
|
if let viewController = type.init() as? UIViewController {
|
||||||
|
viewController.title = item.title
|
||||||
|
split.showDetailViewController(viewController, sender: nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if let type = item.viewController as? StoryboardInitable.Type {
|
if let type = item.viewController as? StoryboardInitable.Type {
|
||||||
let viewController = type.instantiate()
|
let viewController = type.instantiate()
|
||||||
viewController.title = item.title
|
viewController.title = item.title
|
||||||
self.navigationController?.pushViewController(viewController, animated: true)
|
self.navigationController?.pushViewController(viewController, animated: true)
|
||||||
|
} else if let type = item.viewController as? Initable.Type {
|
||||||
|
if let viewController = type.init() as? UIViewController {
|
||||||
|
viewController.title = item.title
|
||||||
|
self.navigationController?.pushViewController(viewController, animated: true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,15 +31,14 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
// var radioButton: RadioButton!
|
// var radioButton: RadioButton!
|
||||||
// var radioButton2: RadioButton!
|
// var radioButton2: RadioButton!
|
||||||
var radioButtonGroup = RadioButtonGroup()
|
var radioButtonGroup = RadioButtonGroup()
|
||||||
|
@Published public var model = DefaultRadioButtonGroupModel()
|
||||||
public var model = RadioButtonGroupModel()
|
public var subscribers = Set<AnyCancellable>()
|
||||||
public var cancellables = Set<AnyCancellable>()
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
|
|
||||||
var model1 = DefaultRadioButtonModel()
|
var model1 = DefaultRadioButtonModel()
|
||||||
model1.inputId = "model1"
|
model1.value = "model 1 Value"
|
||||||
model1.labelText = "Terms and conditions"
|
model1.labelText = "Terms and conditions"
|
||||||
model1.childText = "I agree to Verizon's terms and conditions click here"
|
model1.childText = "I agree to Verizon's terms and conditions click here"
|
||||||
model1.childTextAttributes = [
|
model1.childTextAttributes = [
|
||||||
@ -49,10 +48,9 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
LabelAttributeActionModel(location: 31, length: 10){ print("clicked on the word 'conditions'") },
|
LabelAttributeActionModel(location: 31, length: 10){ print("clicked on the word 'conditions'") },
|
||||||
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!)
|
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!)
|
||||||
]
|
]
|
||||||
model1.errorText = "Error Text"
|
|
||||||
|
|
||||||
var model2 = DefaultRadioButtonModel()
|
var model2 = DefaultRadioButtonModel()
|
||||||
model2.inputId = "model2"
|
model2.value = "model 2 Value"
|
||||||
model2.childText = "Radio Sample 2"
|
model2.childText = "Radio Sample 2"
|
||||||
|
|
||||||
|
|
||||||
@ -60,13 +58,30 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
disabledSwitch.isOn = model1.selected
|
disabledSwitch.isOn = model1.selected
|
||||||
labelTextField.text = model1.labelText
|
labelTextField.text = model1.labelText
|
||||||
childTextField.text = model1.childText
|
childTextField.text = model1.childText
|
||||||
showErrorSwitch.isOn = model1.showError
|
showErrorSwitch.isOn = model1.hasError
|
||||||
errorTextField.text = model1.errorText
|
errorTextField.text = model1.errorText
|
||||||
|
|
||||||
model.selectors = [model1, model2]
|
model.selectors = [model1, model2]
|
||||||
|
|
||||||
radioButtonGroup.set(with: model)
|
radioButtonGroup.set(with: model)
|
||||||
|
|
||||||
componentContainerView.addSubview(radioButtonGroup)
|
componentContainerView.addSubview(radioButtonGroup)
|
||||||
|
|
||||||
|
$model.debounce(for: .seconds(Constants.ModelStateDebounce), scheduler: RunLoop.main).sink { viewModel in
|
||||||
|
guard let selectedModel = viewModel.selectedModel else { return }
|
||||||
|
print("RadioButtonViewController selectedModel Id: \(selectedModel.id)")
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
radioButtonGroup.modelPublisher.debounce(for: .seconds(Constants.ModelStateDebounce), scheduler: RunLoop.main).sink { viewModel in
|
||||||
|
guard let selectedModel = viewModel.selectedModel else { return }
|
||||||
|
print("radioButtonGroup.modelPublisher selectedModel Id: \(selectedModel.id)")
|
||||||
|
print("RadioButtonViewController selectedModel Id: \(self.model.selectedModel?.id)")
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
// radioButtonGroup.modelSubject.sink { [weak self] model in
|
||||||
|
// print("RadioButtonViewController model: \(model.selectedModel?.id)")
|
||||||
|
// print("RadioButtonViewController local.model: \(self?.model.selectedModel?.id)")
|
||||||
|
// }.store(in: &subscribers)
|
||||||
|
|
||||||
radioButtonGroup.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
|
radioButtonGroup.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
|
||||||
radioButtonGroup.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
|
radioButtonGroup.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
|
||||||
@ -76,6 +91,8 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
||||||
setupPicker()
|
setupPicker()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var radioButton: RadioButton? {
|
var radioButton: RadioButton? {
|
||||||
radioButtonGroup.selectorViews.first
|
radioButtonGroup.selectorViews.first
|
||||||
}
|
}
|
||||||
@ -94,7 +111,7 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func showErrorChanged(_ sender: UISwitch) {
|
@IBAction func showErrorChanged(_ sender: UISwitch) {
|
||||||
radioButton?.showError = sender.isOn
|
radioButtonGroup.hasError = sender.isOn
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
|
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
|
||||||
@ -135,4 +152,3 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user