moved picker to base scrollview

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-08-24 12:04:44 -05:00
parent d8eebd69c7
commit ae4a63bfcc
6 changed files with 221 additions and 35 deletions

View File

@ -248,10 +248,10 @@
children = (
EA89203E28B66CE2006B9984 /* ScrollViewController */,
EA3C3BB228996775000CA526 /* MenuViewController.swift */,
EAB1D2C828AAAA1D00DAE764 /* ModelViewController.swift */,
EA89204D28B67332006B9984 /* CheckBoxGroupViewController.swift */,
EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */,
EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */,
EAB1D2C828AAAA1D00DAE764 /* ModelViewController.swift */,
EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */,
EAF7F11928A14A0E00B287F5 /* RadioButtonViewController.swift */,
EAB1D2CA28AAB9E200DAE764 /* TemplateViewController.swift */,

View File

@ -17,7 +17,6 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
case surface
}
var picker = UIPickerView()
var surfacePickerSelectorView = PickerSelectorView(title: "light")
var disabledSwitch = UISwitch()
var labelTextField = TextField()
@ -132,8 +131,6 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
}
func setupPicker(){
contentStackView.addArrangedSubview(picker)
picker.isHidden = true
surfacePicker.onPickerDidSelect = { [weak self] item in
self?.checkboxGroup.surface = item
self?.contentTopView.backgroundColor = item.color

View File

@ -17,7 +17,6 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
case surface
}
var picker = UIPickerView()
var surfacePickerSelectorView = PickerSelectorView(title: "light")
var disabledSwitch = UISwitch()
var labelTextField = TextField()
@ -40,7 +39,7 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Label Text", view: labelTextField)
addFormRow(label: "Childe Text", view: childTextField)
addFormRow(label: "Child Text", view: childTextField)
addFormRow(label: "Error", view: showErrorSwitch)
addFormRow(label: "Error Text", view: errorTextField)
@ -136,8 +135,6 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
}
func setupPicker(){
contentStackView.addArrangedSubview(picker)
picker.isHidden = true
surfacePicker.onPickerDidSelect = { [weak self] item in
self?.checkbox.surface = item
self?.contentTopView.backgroundColor = item.color

View File

@ -18,7 +18,6 @@ class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
enum PickerType {
case surface, textSize, fontCategory
}
var picker = UIPickerView()
var surfacePickerSelectorView = PickerSelectorView(title: "")
var textSizePickerSelectorView = PickerSelectorView(title: "")
var fontCategoryPickerSelectorView = PickerSelectorView(title: "")
@ -167,8 +166,6 @@ class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
}
func setupPicker(){
contentStackView.addArrangedSubview(picker)
picker.isHidden = true
surfacePicker.onPickerDidSelect = { [weak self] item in
self?.label.surface = item
self?.contentTopView.backgroundColor = item.color

View File

@ -139,6 +139,8 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
}
}
public var picker = UIPickerView()
public var contentStackView: UIStackView = {
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
@ -184,8 +186,14 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
formStackView.topAnchor.constraint(equalTo: contentBottomView.topAnchor, constant: 16).isActive = true
formStackView.leadingAnchor.constraint(equalTo: contentBottomView.leadingAnchor, constant: 16).isActive = true
formStackView.trailingAnchor.constraint(equalTo: contentBottomView.trailingAnchor, constant: -16).isActive = true
formStackView.bottomAnchor.constraint(equalTo: contentBottomView.bottomAnchor, constant: -16).isActive = true
formStackView.bottomAnchor.constraint(equalTo: contentBottomView.bottomAnchor, constant: -150).isActive = true
view.addSubview(picker)
picker.translatesAutoresizingMaskIntoConstraints = false
picker.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor).isActive = true
picker.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor).isActive = true
picker.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true
picker.isHidden = true
}
private let scrollViewController = ScrollViewController()

View File

@ -11,7 +11,145 @@ import VDS
import VDSColorTokens
import Combine
class RadioBoxGroupViewController: ModelViewController<DefaultRadioBoxGroupModel>, StoryboardInitable {
//class RadioBoxGroupViewController: ModelViewController<DefaultRadioBoxGroupModel>, StoryboardInitable {
// deinit {
// print("\(Self.self) deinit")
// }
//
// enum PickerType {
// case surface
// }
// static var storyboardId: String = "radioBoxGroup"
// static var storyboardName: String = "Components"
//
// @IBOutlet weak var componentContainerView: UIView!
// @IBOutlet weak var disabledSwitch: UISwitch!
// @IBOutlet weak var picker: UIPickerView!
// @IBOutlet weak var surfaceLabel: UILabel!
// @IBOutlet weak var textField: UITextField!
// @IBOutlet weak var subTextField: UITextField!
// @IBOutlet weak var subTextRightField: UITextField!
// @IBOutlet weak var showErrorSwitch: UISwitch!
//
// var radioBoxGroup = RadioBoxGroup()
//
// override func viewDidLoad() {
// super.viewDidLoad()
// view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
//
// componentContainerView.addSubview(radioBoxGroup)
// radioBoxGroup.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
// radioBoxGroup.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
// radioBoxGroup.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
// radioBoxGroup.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
// setupPicker()
// setupModel()
// }
//
// func setupModel(){
// var defaultModel = DefaultRadioBoxGroupModel()
// var model1 = DefaultRadioBoxModel()
// model1.value = "model 1 Value"
// model1.text = "iPhone 11 Bundle 1"
// model1.subText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
// model1.subTextRight = "Right Text"
//
// var model2 = DefaultRadioBoxModel()
// model2.strikethrough = true
// model2.value = "model 2 Value"
// model2.text = "iPhone 11 Bundle 2"
// model2.subText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
//
// defaultModel.selectors = [model1, model2]
// set(with: defaultModel)
//
// //update the model
// radioBoxGroup
// .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
// surfaceLabel.text = model.surface.rawValue
// disabledSwitch.isOn = model.disabled
// showErrorSwitch.isOn = model.hasError
// textField.text = model1.text
// subTextField.text = model1.subText
// subTextRightField.text = model1.subTextRight
// }
//
// override func updateView(viewModel: ModelType) {
// print("\(Self.self) updateView(viewModel)")
// showErrorSwitch.isOn = viewModel.hasError
// disabledSwitch.isOn = viewModel.disabled
// radioBoxGroup.set(with: viewModel)
// }
//
// var radioBox: RadioBox? {
// radioBoxGroup.selectorViews.first
// }
// @IBAction func disabledChanged(_ sender: UISwitch) {
// radioBoxGroup.disabled = sender.isOn
// }
//
// @IBAction func onTextDidEnd(_ sender: UITextField) {
// radioBox?.text = sender.text ?? "No value entered"
// sender.resignFirstResponder()
// }
//
// @IBAction func onSubTextDidEnd(_ sender: UITextField) {
// radioBox?.subText = sender.text
// sender.resignFirstResponder()
// }
//
// @IBAction func onSubTextRightDidEnd(_ sender: UITextField) {
// radioBox?.subTextRight = sender.text
// sender.resignFirstResponder()
// }
//
// @IBAction func showErrorChanged(_ sender: UISwitch) {
// radioBoxGroup.hasError = sender.isOn
// }
//
// @IBAction func surfaceClick(_ sender: Any) {
// pickerType = .surface
// }
//
// //Picker
// var surfacePicker = SurfacePicker()
//
// var pickerType: PickerType = .surface {
// didSet {
// func update(object: UIPickerViewDelegate & UIPickerViewDataSource){
// picker.delegate = object
// picker.dataSource = object
// }
//
// switch pickerType{
// case .surface:
// update(object: surfacePicker)
// }
// picker.reloadAllComponents()
// picker.selectRow(0, inComponent: 0, animated: false)
// picker.isHidden = false
// }
// }
//
// func setupPicker(){
// picker.isHidden = true
// surfacePicker.onPickerDidSelect = { [weak self] item in
// self?.radioBoxGroup.surface = item
// self?.componentContainerView.backgroundColor = item.color
// self?.surfaceLabel.text = item.rawValue
// }
// }
//}
class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGroupModel> {
deinit {
print("\(Self.self) deinit")
}
@ -19,33 +157,84 @@ class RadioBoxGroupViewController: ModelViewController<DefaultRadioBoxGroupMode
enum PickerType {
case surface
}
static var storyboardId: String = "radioBoxGroup"
static var storyboardName: String = "Components"
@IBOutlet weak var componentContainerView: UIView!
@IBOutlet weak var disabledSwitch: UISwitch!
@IBOutlet weak var picker: UIPickerView!
@IBOutlet weak var surfaceLabel: UILabel!
@IBOutlet weak var textField: UITextField!
@IBOutlet weak var subTextField: UITextField!
@IBOutlet weak var subTextRightField: UITextField!
@IBOutlet weak var showErrorSwitch: UISwitch!
var disabledSwitch = UISwitch()
var strikeThroughSwitch = UISwitch()
var surfacePickerSelectorView = PickerSelectorView(title: "light")
var textField = TextField()
var subTextField = TextField()
var subTextRightField = TextField()
var showErrorSwitch = UISwitch()
var radioBoxGroup = RadioBoxGroup()
override func viewDidLoad() {
super.viewDidLoad()
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
componentContainerView.addSubview(radioBoxGroup)
radioBoxGroup.leadingAnchor.constraint(equalTo: componentContainerView.leadingAnchor, constant: 10).isActive = true
radioBoxGroup.topAnchor.constraint(equalTo: componentContainerView.topAnchor, constant: 20).isActive = true
radioBoxGroup.bottomAnchor.constraint(equalTo: componentContainerView.bottomAnchor, constant: -20).isActive = true
radioBoxGroup.trailingAnchor.constraint(equalTo: componentContainerView.trailingAnchor, constant: 10).isActive = true
addContentTopView(view: radioBoxGroup)
setupForm()
setupPicker()
setupModel()
}
func setupForm() {
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Error", view: showErrorSwitch)
addFormRow(label: "Strikethrough", view: strikeThroughSwitch)
addFormRow(label: "Text", view: textField)
addFormRow(label: "Sub Text", view: subTextField)
addFormRow(label: "Sub Text Right", view: subTextRightField)
radioBoxGroup
.handlerPublisher()
.sink { [weak self] viewModel in
self?.model = viewModel
}.store(in: &subscribers)
showErrorSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioBoxGroup.hasError = sender.isOn
}.store(in: &subscribers)
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioBoxGroup.disabled = sender.isOn
}.store(in: &subscribers)
strikeThroughSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioBox?.strikethrough = sender.isOn
}.store(in: &subscribers)
textField
.textPublisher
.sink { [weak self] text in
self?.radioBox?.text = text
}.store(in: &subscribers)
subTextField
.textPublisher
.sink { [weak self] text in
self?.radioBox?.subText = text
}.store(in: &subscribers)
subTextRightField
.textPublisher
.sink { [weak self] text in
self?.radioBox?.subTextRight = text
}.store(in: &subscribers)
surfacePickerSelectorView.button
.publisher(for: .touchUpInside)
.sink { [weak self] _ in
self?.pickerType = .surface
}.store(in: &subscribers)
}
func setupModel(){
var defaultModel = DefaultRadioBoxGroupModel()
var model1 = DefaultRadioBoxModel()
@ -55,7 +244,6 @@ class RadioBoxGroupViewController: ModelViewController<DefaultRadioBoxGroupMode
model1.subTextRight = "Right Text"
var model2 = DefaultRadioBoxModel()
model2.strikethrough = true
model2.value = "model 2 Value"
model2.text = "iPhone 11 Bundle 2"
model2.subText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
@ -74,7 +262,7 @@ class RadioBoxGroupViewController: ModelViewController<DefaultRadioBoxGroupMode
.store(in: &subscribers)
//set UI values
surfaceLabel.text = model.surface.rawValue
surfacePickerSelectorView.text = model.surface.rawValue
disabledSwitch.isOn = model.disabled
showErrorSwitch.isOn = model.hasError
textField.text = model1.text
@ -140,11 +328,10 @@ class RadioBoxGroupViewController: ModelViewController<DefaultRadioBoxGroupMode
}
func setupPicker(){
picker.isHidden = true
surfacePicker.onPickerDidSelect = { [weak self] item in
self?.radioBoxGroup.surface = item
self?.componentContainerView.backgroundColor = item.color
self?.surfaceLabel.text = item.rawValue
self?.contentTopView.backgroundColor = item.color
self?.surfacePickerSelectorView.text = item.rawValue
}
}
}