115 lines
4.3 KiB
Swift
115 lines
4.3 KiB
Swift
//
|
|
// TemplateViewController.swift
|
|
// VDSSample
|
|
//
|
|
// Created by Matt Bruce on 8/15/22.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
import VDS
|
|
import VDSColorTokens
|
|
import Combine
|
|
|
|
struct TestLayoutModel: Modelable {
|
|
var surface: VDS.Surface = .light
|
|
var disabled: Bool = false
|
|
// var molecules : [any Modelable] = []
|
|
var checkbox: DefaultCheckboxModel
|
|
var radioButtonGroup: DefaultRadioButtonGroupModel
|
|
var subscribers = Set<AnyCancellable>()
|
|
init(){
|
|
let labelAction = LabelAttributeActionModel(location: 31, length: 10)
|
|
labelAction.action.sink {
|
|
print("clicked on the word 'conditions'")
|
|
}.store(in: &subscribers)
|
|
|
|
//add the checkbox
|
|
checkbox = DefaultCheckboxModel()
|
|
checkbox.labelText = "Terms and conditions"
|
|
checkbox.childText = "I agree to Verizon's terms and conditions click here"
|
|
checkbox.childTextAttributes = [
|
|
LabelAttributeUnderline(location: 11, length: 10),
|
|
LabelAttributeStrikeThrough(location: 22, length: 5),
|
|
LabelAttributeColor(location: 31, length: 10, color: UIColor.blue.hexString!),
|
|
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!),
|
|
labelAction
|
|
|
|
]
|
|
checkbox.errorText = "Error Text"
|
|
|
|
//add the radio
|
|
radioButtonGroup = DefaultRadioButtonGroupModel()
|
|
var radio1 = DefaultRadioButtonModel()
|
|
radio1.value = "model 1 Value"
|
|
radio1.labelText = "Terms and conditions"
|
|
radio1.childText = "I agree to Verizon's terms and conditions click here"
|
|
radio1.childTextAttributes = [
|
|
LabelAttributeUnderline(location: 11, length: 10),
|
|
LabelAttributeStrikeThrough(location: 22, length: 5),
|
|
LabelAttributeColor(location: 31, length: 10, color: UIColor.blue.hexString!),
|
|
LabelAttributeFont(location: 2, length: 5, style: .BoldTitleLarge, color: UIColor.red.hexString!),
|
|
labelAction
|
|
]
|
|
|
|
var radio2 = DefaultRadioButtonModel()
|
|
radio2.value = "model 2 Value"
|
|
radio2.childText = "Radio Sample 2"
|
|
radioButtonGroup.selectors = [radio1, radio2]
|
|
|
|
}
|
|
}
|
|
|
|
class TemplateViewController: ModelViewController<TestLayoutModel> {
|
|
enum ModelHandlerError: Error {
|
|
case cantFind
|
|
}
|
|
|
|
var stackView = UIStackView()
|
|
var radioButtonGroup = RadioButtonGroup()
|
|
var checkbox = Checkbox()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
view.backgroundColor = .white
|
|
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
stackView.spacing = 10
|
|
stackView.axis = .vertical
|
|
stackView.alignment = .top
|
|
|
|
view.addSubview(stackView)
|
|
stackView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor, constant: 10).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.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: 10).isActive = true
|
|
|
|
//Publisher way
|
|
checkbox.handlerPublisher()
|
|
.sink { [weak self] checkModel in
|
|
self?.model.checkbox = checkModel
|
|
}
|
|
.store(in: &subscribers)
|
|
stackView.addArrangedSubview(checkbox)
|
|
|
|
radioButtonGroup.handlerPublisher()
|
|
.sink { [weak self] radioGroupModel in
|
|
self?.model.radioButtonGroup = radioGroupModel
|
|
}
|
|
.store(in: &subscribers)
|
|
stackView.addArrangedSubview(radioButtonGroup)
|
|
|
|
checkbox.set(with: model.checkbox)
|
|
radioButtonGroup.set(with: model.radioButtonGroup)
|
|
|
|
}
|
|
|
|
override func updateView(viewModel: ModelType) {
|
|
print("\(Self.self) updateView(viewModel)")
|
|
checkbox.set(with: model.checkbox)
|
|
radioButtonGroup.set(with: model.radioButtonGroup)
|
|
|
|
print("radioButtonGroup selected: \(radioButtonGroup.selectedModel?.id)")
|
|
print("model.value.radioButtonGroup selected: \(model.radioButtonGroup.selectedModel?.id)")
|
|
}
|
|
}
|