Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-08-12 12:53:13 -05:00
parent 788b226104
commit d36aa00932
3 changed files with 43 additions and 13 deletions

View File

@ -47,7 +47,7 @@ class CheckboxViewController: UIViewController, StoryboardInitable {
disabledSwitch.isOn = model.selected
labelTextField.text = model.labelText
childTextField.text = model.childText
showErrorSwitch.isOn = model.showError
showErrorSwitch.isOn = model.hasError
errorTextField.text = model.errorText
checkbox = Checkbox(with: model)
@ -76,7 +76,7 @@ class CheckboxViewController: UIViewController, StoryboardInitable {
}
@IBAction func showErrorChanged(_ sender: UISwitch) {
checkbox.showError = sender.isOn
checkbox.hasError = sender.isOn
}
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {

View File

@ -13,11 +13,16 @@ struct MenuComponent {
var viewController: UIViewController.Type
}
protocol Initable {
init()
}
class MenuViewController: UITableViewController {
let items: [MenuComponent] = [
MenuComponent(title: "Toggle", viewController: ToggleViewController.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 {
@ -47,14 +52,23 @@ class MenuViewController: UITableViewController {
let viewController = type.instantiate()
viewController.title = item.title
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 {
if let type = item.viewController as? StoryboardInitable.Type {
let viewController = type.instantiate()
viewController.title = item.title
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)
}
}
}
}
}

View File

@ -31,15 +31,14 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
// var radioButton: RadioButton!
// var radioButton2: RadioButton!
var radioButtonGroup = RadioButtonGroup()
public var model = RadioButtonGroupModel()
public var cancellables = Set<AnyCancellable>()
@Published public var model = DefaultRadioButtonGroupModel()
public var subscribers = Set<AnyCancellable>()
override func viewDidLoad() {
super.viewDidLoad()
var model1 = DefaultRadioButtonModel()
model1.inputId = "model1"
model1.value = "model 1 Value"
model1.labelText = "Terms and conditions"
model1.childText = "I agree to Verizon's terms and conditions click here"
model1.childTextAttributes = [
@ -49,10 +48,9 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
LabelAttributeActionModel(location: 31, length: 10){ print("clicked on the word 'conditions'") },
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!)
]
model1.errorText = "Error Text"
var model2 = DefaultRadioButtonModel()
model2.inputId = "model2"
model2.value = "model 2 Value"
model2.childText = "Radio Sample 2"
@ -60,13 +58,30 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
disabledSwitch.isOn = model1.selected
labelTextField.text = model1.labelText
childTextField.text = model1.childText
showErrorSwitch.isOn = model1.showError
showErrorSwitch.isOn = model1.hasError
errorTextField.text = model1.errorText
model.selectors = [model1, model2]
radioButtonGroup.set(with: model)
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.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(_:))))
setupPicker()
}
var radioButton: RadioButton? {
radioButtonGroup.selectorViews.first
}
@ -94,7 +111,7 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
}
@IBAction func showErrorChanged(_ sender: UISwitch) {
radioButton?.showError = sender.isOn
radioButtonGroup.hasError = sender.isOn
}
@IBAction func onErrorTextDidEnd(_ sender: UITextField) {
@ -135,4 +152,3 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
}
}
}