added controller for swatch

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-08-30 14:36:38 -05:00
parent 5f61af5323
commit b2310997e4
3 changed files with 192 additions and 0 deletions

View File

@ -40,6 +40,7 @@
EA3C3BB528996775000CA526 /* StoryboardInitable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB128996775000CA526 /* StoryboardInitable.swift */; };
EA3C3BB628996775000CA526 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB228996775000CA526 /* MenuViewController.swift */; };
EA3C3BB728996775000CA526 /* ToggleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB328996775000CA526 /* ToggleViewController.swift */; };
EA84F76228BE4AE500D67ABC /* RadioSwatchGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */; };
EA89201928B56DF5006B9984 /* RadioBoxGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */; };
EA89204628B66CE2006B9984 /* ScrollViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89203F28B66CE2006B9984 /* ScrollViewController.swift */; };
EA89204728B66CE2006B9984 /* KeyboardFrameChangeListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89204028B66CE2006B9984 /* KeyboardFrameChangeListener.swift */; };
@ -100,6 +101,7 @@
EA3C3BBA289968A0000CA526 /* VDSTypographyTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSTypographyTokens.xcframework; path = ../SharedFrameworks/VDSTypographyTokens.xcframework; sourceTree = "<group>"; };
EA3C3BBB289968A0000CA526 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = ../SharedFrameworks/VDSFormControlsTokens.xcframework; sourceTree = "<group>"; };
EA3C3BC3289968B1000CA526 /* VDS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = VDS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatchGroupViewController.swift; sourceTree = "<group>"; };
EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBoxGroupViewController.swift; sourceTree = "<group>"; };
EA89203F28B66CE2006B9984 /* ScrollViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollViewController.swift; sourceTree = "<group>"; };
EA89204028B66CE2006B9984 /* KeyboardFrameChangeListener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KeyboardFrameChangeListener.swift; sourceTree = "<group>"; };
@ -247,6 +249,7 @@
EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */,
EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */,
EAF7F11928A14A0E00B287F5 /* RadioButtonViewController.swift */,
EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */,
EA3C3BB328996775000CA526 /* ToggleViewController.swift */,
);
path = ViewControllers;
@ -411,6 +414,7 @@
EA89204928B66CE2006B9984 /* KeyboardFrameChangeListening.swift in Sources */,
EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */,
EA89204B28B66CE2006B9984 /* ScrollViewKeyboardAvoider.swift in Sources */,
EA84F76228BE4AE500D67ABC /* RadioSwatchGroupViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -24,6 +24,7 @@ class MenuViewController: UITableViewController {
MenuComponent(title: "Label", viewController: LabelViewController.self),
MenuComponent(title: "RadioButton", viewController: RadioButtonViewController.self),
MenuComponent(title: "RadioBoxGroup", viewController: RadioBoxGroupViewController.self),
MenuComponent(title: "RadioSwatchGroup", viewController: RadioSwatchGroupViewController.self),
MenuComponent(title: "Toggle", viewController: ToggleViewController.self)
]

View File

@ -0,0 +1,187 @@
//
// RadioSwatchGroupViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/30/22.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
import Combine
class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwatchGroupModel> {
enum PickerType {
case surface
}
var disabledSwitch = UISwitch()
var strikeThroughSwitch = UISwitch()
var surfacePickerSelectorView = PickerSelectorView(title: "light")
var textField = TextField()
var subTextField = TextField()
var subTextRightField = TextField()
var showErrorSwitch = UISwitch()
var radioSwatchGroup = RadioSwatchGroup()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: radioSwatchGroup)
setupForm()
setupPicker()
setupModel()
}
func setupForm() {
addFormRow(label: "Disabled", view: disabledSwitch)
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Strikethrough", view: strikeThroughSwitch)
addFormRow(label: "Text", view: textField)
disabledSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.radioSwatchGroup.disabled = sender.isOn
}.store(in: &subscribers)
strikeThroughSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
let selectors = self?.model.selectors.compactMap { existing in
if existing.inputId == self?.model.selectors.first?.inputId {
return existing.copyWith {
$0.strikethrough = sender.isOn
}
} else {
return existing
}
}
if let selectors {
self?.model.selectors = selectors
}
}.store(in: &subscribers)
textField
.textPublisher
.sink { [weak self] text in
let selectors = self?.model.selectors.compactMap { existing in
if existing.inputId == self?.model.selectors.first?.inputId {
return existing.copyWith {
$0.text = text
}
} else {
return existing
}
}
if let selectors {
self?.model.selectors = selectors
}
}.store(in: &subscribers)
surfacePickerSelectorView.button
.publisher(for: .touchUpInside)
.sink { [weak self] _ in
self?.pickerType = .surface
}.store(in: &subscribers)
}
func setupModel(){
var defaultModel = DefaultRadioSwatchGroupModel()
var model1 = DefaultRadioSwatchModel()
model1.primaryColor = .red
model1.text = "Red"
model1.inputId = "radioSwatch1"
var model2 = DefaultRadioSwatchModel()
model2.primaryColor = .blue
model2.text = "Blue"
model2.inputId = "radioSwatch2"
var model3 = DefaultRadioSwatchModel()
model3.primaryColor = .green
model3.text = "Green"
model3.inputId = "radioSwatch3"
var model4 = DefaultRadioSwatchModel()
model4.primaryColor = .orange
model4.text = "Orange"
model4.inputId = "radioSwatch4"
var model5 = DefaultRadioSwatchModel()
model5.primaryColor = .brown
model5.text = "Brown"
model5.inputId = "radioSwatch5"
var model6 = DefaultRadioSwatchModel()
model6.primaryColor = .yellow
model6.text = "Yellow"
model6.inputId = "radioSwatch6"
var model7 = DefaultRadioSwatchModel()
model7.primaryColor = .purple
model7.text = "Puple"
model7.inputId = "radioSwatch7"
var model8 = DefaultRadioSwatchModel()
model8.primaryColor = .systemPink
model8.text = "Pink"
model8.inputId = "radioSwatch8"
defaultModel.selectors = [model1, model2, model3, model4, model5, model6, model7, model8]
set(with: defaultModel)
//update the model
radioSwatchGroup
.handlerPublisher()
.sink { [weak self] updatedModel in
self?.model = updatedModel
self?.disabledSwitch.isOn = updatedModel.disabled
}
.store(in: &subscribers)
//set UI values
surfacePickerSelectorView.text = model.surface.rawValue
disabledSwitch.isOn = model.disabled
textField.text = model1.text
}
override func updateView(viewModel: ModelType) {
print("\(Self.self) updateView(viewModel)")
disabledSwitch.isOn = viewModel.disabled
radioSwatchGroup.set(with: viewModel)
}
//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(){
surfacePicker.onPickerDidSelect = { [weak self] item in
self?.radioSwatchGroup.surface = item
self?.contentTopView.backgroundColor = item.color
self?.surfacePickerSelectorView.text = item.rawValue
}
}
}