updated logging
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
0e4bec4327
commit
45aa38b333
@ -38,6 +38,7 @@ class PickerBase<EnumType: RawRepresentable>: NSObject, PickerViewable, UIPicker
|
|||||||
}
|
}
|
||||||
|
|
||||||
func pickerView( _ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
func pickerView( _ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
|
||||||
|
guard row - 1 >= 0 else { return }
|
||||||
onPickerDidSelect?(items[row-1])
|
onPickerDidSelect?(items[row-1])
|
||||||
pickerView.isHidden = true
|
pickerView.isHidden = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,6 @@ import VDS
|
|||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CheckboxViewController: ModelViewController<DefaultCheckboxModel>, StoryboardInitable {
|
class CheckboxViewController: ModelViewController<DefaultCheckboxModel>, StoryboardInitable {
|
||||||
|
|
||||||
enum PickerType {
|
enum PickerType {
|
||||||
@ -42,25 +40,29 @@ class CheckboxViewController: ModelViewController<DefaultCheckboxModel>, Storyb
|
|||||||
checkbox.trailingAnchor.constraint(equalTo: checkboxContainerView.trailingAnchor, constant: 10).isActive = true
|
checkbox.trailingAnchor.constraint(equalTo: checkboxContainerView.trailingAnchor, constant: 10).isActive = true
|
||||||
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
|
||||||
setupPicker()
|
setupPicker()
|
||||||
createModel()
|
setupModel()
|
||||||
setupBinding()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createModel() {
|
func setupModel() {
|
||||||
var model = DefaultCheckboxModel()
|
var defaultModel = DefaultCheckboxModel()
|
||||||
model.labelText = "Terms and conditions"
|
defaultModel.labelText = "Terms and conditions"
|
||||||
model.childText = "I agree to Verizon's terms and conditions click here"
|
defaultModel.childText = "I agree to Verizon's terms and conditions click here"
|
||||||
model.childTextAttributes = [
|
defaultModel.childTextAttributes = [
|
||||||
LabelAttributeUnderline(location: 11, length: 10),
|
LabelAttributeUnderline(location: 11, length: 10),
|
||||||
LabelAttributeStrikeThrough(location: 22, length: 5),
|
LabelAttributeStrikeThrough(location: 22, length: 5),
|
||||||
LabelAttributeColor(location: 31, length: 10, color: UIColor.blue.hexString!),
|
LabelAttributeColor(location: 31, length: 10, color: UIColor.blue.hexString!),
|
||||||
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!)
|
||||||
]
|
]
|
||||||
model.errorText = "Error Text"
|
defaultModel.errorText = "Error Text"
|
||||||
|
model = defaultModel
|
||||||
checkbox.set(with: model)
|
|
||||||
|
|
||||||
|
checkbox
|
||||||
|
.handlerPublisher()
|
||||||
|
.sink { [weak self] viewModel in
|
||||||
|
self?.model = viewModel
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
//setup UI
|
//setup UI
|
||||||
surfaceLabel.text = model.surface.rawValue
|
surfaceLabel.text = model.surface.rawValue
|
||||||
disabledSwitch.isOn = model.selected
|
disabledSwitch.isOn = model.selected
|
||||||
@ -71,21 +73,9 @@ class CheckboxViewController: ModelViewController<DefaultCheckboxModel>, Storyb
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupBinding() {
|
override func updateView(viewModel: DefaultCheckboxModel) {
|
||||||
|
print("\(Self.self) updateView(viewModel)")
|
||||||
checkbox.createBinding(with: model, storeIn: &subscribers)
|
checkbox.set(with: viewModel)
|
||||||
|
|
||||||
//print out on subject changes
|
|
||||||
model
|
|
||||||
.debounce(for: .seconds(Constants.ModelStateDebounce), scheduler: RunLoop.main)
|
|
||||||
.sink { [weak self] updatedModel in
|
|
||||||
self?.showErrorSwitch.isOn = updatedModel.hasError
|
|
||||||
print("CheckboxViewController local hasError: \(self?.model.value.hasError)")
|
|
||||||
print("CheckboxViewController hasError: \(updatedModel.hasError)")
|
|
||||||
print("CheckboxViewController local selected: \(self?.model.value.selected)")
|
|
||||||
print("CheckboxViewController selected: \(updatedModel.selected)")
|
|
||||||
}
|
|
||||||
.store(in: &subscribers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@IBAction func disabledChanged(_ sender: UISwitch) {
|
@IBAction func disabledChanged(_ sender: UISwitch) {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ import UIKit
|
|||||||
import Combine
|
import Combine
|
||||||
import VDS
|
import VDS
|
||||||
|
|
||||||
public class ModelViewController<ModelType: Modelable>: UIViewController {
|
public class ModelViewController<ModelType: Modelable>: UIViewController, ModelHandlerable, Initable {
|
||||||
deinit {
|
deinit {
|
||||||
print("\(Self.self) deinit")
|
print("\(Self.self) deinit")
|
||||||
}
|
}
|
||||||
@ -18,7 +18,8 @@ public class ModelViewController<ModelType: Modelable>: UIViewController {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Combine Properties
|
// MARK: - Combine Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
public var model = CurrentValueSubject<ModelType, Never>(ModelType())
|
@Published public var model: ModelType = ModelType()
|
||||||
|
public var modelPublisher: Published<ModelType>.Publisher { $model }
|
||||||
public var subscribers = Set<AnyCancellable>()
|
public var subscribers = Set<AnyCancellable>()
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -26,10 +27,10 @@ public class ModelViewController<ModelType: Modelable>: UIViewController {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
@Proxy(\.model.value.surface)
|
@Proxy(\.model.surface)
|
||||||
open var surface: Surface
|
open var surface: Surface
|
||||||
|
|
||||||
@Proxy(\.model.value.disabled)
|
@Proxy(\.model.disabled)
|
||||||
open var disabled: Bool
|
open var disabled: Bool
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -63,17 +64,7 @@ public class ModelViewController<ModelType: Modelable>: UIViewController {
|
|||||||
public func initialSetup() {
|
public func initialSetup() {
|
||||||
if !initialSetupPerformed {
|
if !initialSetupPerformed {
|
||||||
initialSetupPerformed = true
|
initialSetupPerformed = true
|
||||||
model
|
setupUpdateView()
|
||||||
.filter { [weak self] viewModel in
|
|
||||||
return self?.shouldUpdateView(viewModel: viewModel) ?? false
|
|
||||||
|
|
||||||
}
|
|
||||||
.debounce(for: .seconds(Constants.ModelStateDebounce), scheduler: RunLoop.main)
|
|
||||||
.sink { [weak self] viewModel in
|
|
||||||
self?.updateView()
|
|
||||||
|
|
||||||
}
|
|
||||||
.store(in: &subscribers)
|
|
||||||
setup()
|
setup()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,12 +73,6 @@ public class ModelViewController<ModelType: Modelable>: UIViewController {
|
|||||||
|
|
||||||
open func shouldUpdateView(viewModel: ModelType) -> Bool { true }
|
open func shouldUpdateView(viewModel: ModelType) -> Bool { true }
|
||||||
|
|
||||||
open func updateView() {}
|
open func updateView(viewModel: ModelType) {}
|
||||||
|
|
||||||
open func set(with model: ModelType) {
|
|
||||||
if shouldUpdateView(viewModel: model){
|
|
||||||
self.model.send(model)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import VDS
|
|||||||
import VDSColorTokens
|
import VDSColorTokens
|
||||||
import Combine
|
import Combine
|
||||||
|
|
||||||
class RadioButtonViewController: UIViewController, StoryboardInitable {
|
class RadioButtonViewController: ModelViewController<DefaultRadioButtonGroupModel>, StoryboardInitable {
|
||||||
deinit {
|
deinit {
|
||||||
print("\(Self.self) deinit")
|
print("\(Self.self) deinit")
|
||||||
}
|
}
|
||||||
@ -32,8 +32,6 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
@IBOutlet weak var showErrorSwitch: UISwitch!
|
@IBOutlet weak var showErrorSwitch: UISwitch!
|
||||||
|
|
||||||
var radioButtonGroup = RadioButtonGroup()
|
var radioButtonGroup = RadioButtonGroup()
|
||||||
public var model = DefaultRadioButtonGroupModel()
|
|
||||||
public var subscribers = Set<AnyCancellable>()
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
override func viewDidLoad() {
|
||||||
super.viewDidLoad()
|
super.viewDidLoad()
|
||||||
@ -45,12 +43,11 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
radioButtonGroup.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
|
radioButtonGroup.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
|
||||||
radioButtonGroup.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
|
radioButtonGroup.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
|
||||||
setupPicker()
|
setupPicker()
|
||||||
|
setupModel()
|
||||||
createModel()
|
|
||||||
setupBinding()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createModel(){
|
func setupModel(){
|
||||||
|
var defaultModel = DefaultRadioButtonGroupModel()
|
||||||
var model1 = DefaultRadioButtonModel()
|
var model1 = DefaultRadioButtonModel()
|
||||||
model1.value = "model 1 Value"
|
model1.value = "model 1 Value"
|
||||||
model1.labelText = "Terms and conditions"
|
model1.labelText = "Terms and conditions"
|
||||||
@ -66,34 +63,32 @@ class RadioButtonViewController: UIViewController, StoryboardInitable {
|
|||||||
var model2 = DefaultRadioButtonModel()
|
var model2 = DefaultRadioButtonModel()
|
||||||
model2.value = "model 2 Value"
|
model2.value = "model 2 Value"
|
||||||
model2.childText = "Radio Sample 2"
|
model2.childText = "Radio Sample 2"
|
||||||
model.selectors = [model1, model2]
|
defaultModel.selectors = [model1, model2]
|
||||||
|
model = defaultModel
|
||||||
|
|
||||||
|
//update the model
|
||||||
|
radioButtonGroup
|
||||||
|
.handlerPublisher()
|
||||||
|
.sink { [weak self] updatedModel in
|
||||||
|
self?.model = updatedModel
|
||||||
|
self?.showErrorSwitch.isOn = updatedModel.hasError
|
||||||
|
self?.disabledSwitch.isOn = updatedModel.disabled
|
||||||
|
}
|
||||||
|
.store(in: &subscribers)
|
||||||
|
|
||||||
//set UI values
|
//set UI values
|
||||||
surfaceLabel.text = model.surface.rawValue
|
surfaceLabel.text = model.surface.rawValue
|
||||||
disabledSwitch.isOn = model.disabled
|
disabledSwitch.isOn = model.disabled
|
||||||
showErrorSwitch.isOn = model.hasError
|
showErrorSwitch.isOn = model.hasError
|
||||||
labelTextField.text = model1.labelText
|
labelTextField.text = model1.labelText
|
||||||
childTextField.text = model1.childText
|
childTextField.text = model1.childText
|
||||||
|
|
||||||
radioButtonGroup.set(with: model)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func setupBinding() {
|
override func updateView(viewModel: DefaultRadioButtonGroupModel) {
|
||||||
//update the model
|
print("\(Self.self) updateView(viewModel)")
|
||||||
//print out on subject changes
|
showErrorSwitch.isOn = viewModel.hasError
|
||||||
radioButtonGroup.handlerPublisher()
|
disabledSwitch.isOn = viewModel.disabled
|
||||||
.sink { [weak self] updatedModel in
|
radioButtonGroup.set(with: viewModel)
|
||||||
print("before RadioButtonViewController local selectedModel Id: \(self?.model.selectedModel?.id)")
|
|
||||||
self?.model = updatedModel
|
|
||||||
self?.showErrorSwitch.isOn = updatedModel.hasError
|
|
||||||
print("RadioButtonViewController hasError: \(updatedModel.hasError)")
|
|
||||||
|
|
||||||
if let selectedModel = updatedModel.selectedModel {
|
|
||||||
print("RadioButtonViewController selectedModel Id: \(selectedModel.id)")
|
|
||||||
print("after RadioButtonViewController local selectedModel Id: \(self?.model.selectedModel?.id)")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.store(in: &subscribers)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var radioButton: RadioButton? {
|
var radioButton: RadioButton? {
|
||||||
|
|||||||
@ -54,7 +54,7 @@ struct TestLayoutModel: Modelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TemplateViewController: ModelViewController<TestLayoutModel>, Initable {
|
class TemplateViewController: ModelViewController<TestLayoutModel> {
|
||||||
enum ModelHandlerError: Error {
|
enum ModelHandlerError: Error {
|
||||||
case cantFind
|
case cantFind
|
||||||
}
|
}
|
||||||
@ -76,48 +76,33 @@ class TemplateViewController: ModelViewController<TestLayoutModel>, Initable {
|
|||||||
stackView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20).isActive = true
|
stackView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor, constant: -20).isActive = true
|
||||||
stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true
|
stackView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 20).isActive = true
|
||||||
stackView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: 10).isActive = true
|
stackView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: 10).isActive = true
|
||||||
|
|
||||||
// //CurrentValueSubject
|
|
||||||
// let checkSubject = CurrentValueSubject<DefaultCheckboxModel, Never>(model.value.checkbox)
|
|
||||||
// checkbox.createBinding(with: checkSubject, storeIn: &subscribers)
|
|
||||||
// checkSubject.sink { [weak self] checkModel in
|
|
||||||
// self?.model.value.checkbox = checkModel
|
|
||||||
// }.store(in: &subscribers)
|
|
||||||
// stackView.addArrangedSubview(checkbox)
|
|
||||||
//
|
|
||||||
// let radioSubject = CurrentValueSubject<DefaultRadioButtonGroupModel, Never>(model.value.radioButtonGroup)
|
|
||||||
// radioButtonGroup.createBinding(with: radioSubject, storeIn: &subscribers)
|
|
||||||
// radioSubject.sink { [weak self] radioGroupModel in
|
|
||||||
// self?.model.value.radioButtonGroup = radioGroupModel
|
|
||||||
// }.store(in: &subscribers)
|
|
||||||
// stackView.addArrangedSubview(radioButtonGroup)
|
|
||||||
|
|
||||||
//Publisher way
|
//Publisher way
|
||||||
checkbox.handlerPublisher()
|
checkbox.handlerPublisher()
|
||||||
.sink { [weak self] checkModel in
|
.sink { [weak self] checkModel in
|
||||||
self?.model.value.checkbox = checkModel
|
self?.model.checkbox = checkModel
|
||||||
}
|
}
|
||||||
.store(in: &subscribers)
|
.store(in: &subscribers)
|
||||||
stackView.addArrangedSubview(checkbox)
|
stackView.addArrangedSubview(checkbox)
|
||||||
|
|
||||||
radioButtonGroup.handlerPublisher()
|
radioButtonGroup.handlerPublisher()
|
||||||
.sink { [weak self] radioGroupModel in
|
.sink { [weak self] radioGroupModel in
|
||||||
self?.model.value.radioButtonGroup = radioGroupModel
|
self?.model.radioButtonGroup = radioGroupModel
|
||||||
}
|
}
|
||||||
.store(in: &subscribers)
|
.store(in: &subscribers)
|
||||||
stackView.addArrangedSubview(radioButtonGroup)
|
stackView.addArrangedSubview(radioButtonGroup)
|
||||||
|
|
||||||
checkbox.set(with: model.value.checkbox)
|
checkbox.set(with: model.checkbox)
|
||||||
radioButtonGroup.set(with: model.value.radioButtonGroup)
|
radioButtonGroup.set(with: model.radioButtonGroup)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override func updateView() {
|
override func updateView(viewModel: ModelType) {
|
||||||
print("updateView Called")
|
print("\(Self.self) updateView(viewModel)")
|
||||||
checkbox.set(with: model.value.checkbox)
|
checkbox.set(with: model.checkbox)
|
||||||
radioButtonGroup.set(with: model.value.radioButtonGroup)
|
radioButtonGroup.set(with: model.radioButtonGroup)
|
||||||
|
|
||||||
print("radioButtonGroup selected: \(radioButtonGroup.selectedModel?.id)")
|
print("radioButtonGroup selected: \(radioButtonGroup.selectedModel?.id)")
|
||||||
print("model.value.radioButtonGroup selected: \(model.value.radioButtonGroup.selectedModel?.id)")
|
print("model.value.radioButtonGroup selected: \(model.radioButtonGroup.selectedModel?.id)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user