refactored
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
b485bbf47b
commit
8242cbd9de
@ -11,7 +11,7 @@ import VDS
|
||||
import VDSColorTokens
|
||||
import Combine
|
||||
|
||||
class BadgeViewController: ModelScrollViewController<DefaultBadgeModel> {
|
||||
class BadgeViewController: ModelScrollViewController {
|
||||
|
||||
enum NumberOfLines: String, CaseIterable {
|
||||
case unlimited
|
||||
@ -93,28 +93,13 @@ class BadgeViewController: ModelScrollViewController<DefaultBadgeModel> {
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
var defaultModel = DefaultBadgeModel()
|
||||
defaultModel.fillColor = .red
|
||||
defaultModel.text = "Terms and conditions"
|
||||
defaultModel.numberOfLines = 1
|
||||
|
||||
set(with: defaultModel)
|
||||
|
||||
badge
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] viewModel in
|
||||
self?.model = viewModel
|
||||
}.store(in: &subscribers)
|
||||
|
||||
badge.fillColor = .red
|
||||
badge.text = "Terms and conditions"
|
||||
badge.numberOfLines = 1
|
||||
|
||||
//setup UI
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
textField.text = model.text
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultBadgeModel) {
|
||||
print("\(Self.self) updateView(viewModel)")
|
||||
badge.set(with: viewModel)
|
||||
surfacePickerSelectorView.text = badge.surface.rawValue
|
||||
textField.text = badge.text
|
||||
}
|
||||
|
||||
func setupPicker(){
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
import VDS
|
||||
import VDSColorTokens
|
||||
|
||||
class ButtonViewController: ModelScrollViewController<DefaultButtonModel> {
|
||||
class ButtonViewController: ModelScrollViewController {
|
||||
|
||||
lazy var usePickerSelectorView = {
|
||||
PickerSelectorView<Use>(title: "",
|
||||
@ -77,16 +77,8 @@ class ButtonViewController: ModelScrollViewController<DefaultButtonModel> {
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
var defaultModel = DefaultButtonModel()
|
||||
defaultModel.text = "Button"
|
||||
set(with: defaultModel)
|
||||
button.text = "Button"
|
||||
|
||||
button
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] viewModel in
|
||||
self?.model = viewModel
|
||||
}.store(in: &subscribers)
|
||||
|
||||
button
|
||||
.publisher(for: .touchUpInside)
|
||||
.sink { control in
|
||||
@ -95,17 +87,13 @@ class ButtonViewController: ModelScrollViewController<DefaultButtonModel> {
|
||||
|
||||
|
||||
//setup UI
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.disabled
|
||||
textField.text = model.text
|
||||
usePickerSelectorView.text = model.use.rawValue
|
||||
surfacePickerSelectorView.text = button.surface.rawValue
|
||||
disabledSwitch.isOn = button.disabled
|
||||
textField.text = button.text
|
||||
usePickerSelectorView.text = button.use.rawValue
|
||||
widthTextField.text = ""
|
||||
buttonSizePickerSelectorView.text = ButtonSize.large.rawValue
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultButtonModel) {
|
||||
button.set(with: viewModel)
|
||||
}
|
||||
|
||||
func setupPicker(){
|
||||
|
||||
|
||||
@ -11,14 +11,13 @@ import VDS
|
||||
import VDSColorTokens
|
||||
import Combine
|
||||
|
||||
class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGroupModel> {
|
||||
class CheckboxGroupViewController: ModelScrollViewController {
|
||||
|
||||
var disabledSwitch = UISwitch()
|
||||
var labelTextField = TextField()
|
||||
var childTextField = TextField()
|
||||
var showErrorSwitch = UISwitch()
|
||||
|
||||
|
||||
var checkboxGroup = CheckboxGroup()
|
||||
|
||||
override func viewDidLoad() {
|
||||
@ -63,27 +62,20 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
var defaultModel = DefaultCheckboxGroupModel()
|
||||
var model1 = DefaultCheckboxModel()
|
||||
model1.inputId = "model1"
|
||||
model1.value = "model 1 Value"
|
||||
model1.labelText = "iPhone 11 Bundle 1"
|
||||
model1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
|
||||
var checkbox1 = Checkbox()
|
||||
checkbox1.inputId = "model1"
|
||||
checkbox1.value = "model 1 Value"
|
||||
checkbox1.labelText = "iPhone 11 Bundle 1"
|
||||
checkbox1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
|
||||
|
||||
var model2 = DefaultCheckboxModel()
|
||||
model2.inputId = "model2"
|
||||
model2.value = "model 2 Value"
|
||||
model2.labelText = "iPhone 11 Bundle 2"
|
||||
model2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
||||
defaultModel.selectors = [model1, model2]
|
||||
set(with: defaultModel)
|
||||
var checkbox2 = Checkbox()
|
||||
checkbox2.inputId = "model2"
|
||||
checkbox2.value = "model 2 Value"
|
||||
checkbox2.labelText = "iPhone 11 Bundle 2"
|
||||
checkbox2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
||||
|
||||
checkboxGroup.selectorViews = [checkbox1, checkbox2]
|
||||
|
||||
checkboxGroup
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] viewModel in
|
||||
self?.model = viewModel
|
||||
}.store(in: &subscribers)
|
||||
|
||||
checkboxGroup
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { group in
|
||||
@ -95,21 +87,14 @@ class CheckboxGroupViewController: ModelScrollViewController<DefaultCheckboxGro
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//setup UI
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.disabled
|
||||
labelTextField.text = model2.labelText
|
||||
childTextField.text = model1.childText
|
||||
showErrorSwitch.isOn = model.showError
|
||||
surfacePickerSelectorView.text = checkboxGroup.surface.rawValue
|
||||
disabledSwitch.isOn = checkboxGroup.disabled
|
||||
labelTextField.text = checkbox1.labelText
|
||||
childTextField.text = checkbox1.childText
|
||||
showErrorSwitch.isOn = checkboxGroup.showError
|
||||
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultCheckboxGroupModel) {
|
||||
print("\(Self.self) updateView(viewModel)")
|
||||
showErrorSwitch.isOn = viewModel.showError
|
||||
disabledSwitch.isOn = viewModel.disabled
|
||||
checkboxGroup.set(with: viewModel)
|
||||
}
|
||||
|
||||
|
||||
var checkbox: Checkbox? {
|
||||
checkboxGroup.selectorViews.first
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import VDS
|
||||
import VDSColorTokens
|
||||
import Combine
|
||||
|
||||
class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
||||
class CheckboxViewController: ModelScrollViewController {
|
||||
|
||||
var disabledSwitch = UISwitch()
|
||||
var labelTextField = TextField()
|
||||
@ -38,12 +38,6 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
||||
addFormRow(label: "Error", view: showErrorSwitch)
|
||||
addFormRow(label: "Error Text", view: errorTextField)
|
||||
|
||||
checkbox
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] viewModel in
|
||||
self?.model = viewModel
|
||||
}.store(in: &subscribers)
|
||||
|
||||
showErrorSwitch
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
@ -76,18 +70,10 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
var defaultModel = DefaultCheckboxModel()
|
||||
defaultModel.labelText = "Terms and conditions"
|
||||
defaultModel.childText = "I agree to Verizon's terms and conditions click here"
|
||||
defaultModel.errorText = "Error Text"
|
||||
set(with: defaultModel)
|
||||
checkbox.labelText = "Terms and conditions"
|
||||
checkbox.childText = "I agree to Verizon's terms and conditions click here"
|
||||
checkbox.errorText = "Error Text"
|
||||
|
||||
checkbox
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] viewModel in
|
||||
self?.model = viewModel
|
||||
}.store(in: &subscribers)
|
||||
|
||||
checkbox
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { checkbox in
|
||||
@ -95,22 +81,15 @@ class CheckboxViewController: ModelScrollViewController<DefaultCheckboxModel> {
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//setup UI
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.selected
|
||||
labelTextField.text = model.labelText
|
||||
childTextField.text = model.childText
|
||||
showErrorSwitch.isOn = model.showError
|
||||
errorTextField.text = model.errorText
|
||||
surfacePickerSelectorView.text = checkbox.surface.rawValue
|
||||
disabledSwitch.isOn = checkbox.disabled
|
||||
labelTextField.text = checkbox.labelText
|
||||
childTextField.text = checkbox.childText
|
||||
showErrorSwitch.isOn = checkbox.showError
|
||||
errorTextField.text = checkbox.errorText
|
||||
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultCheckboxModel) {
|
||||
print("\(Self.self) updateView(viewModel)")
|
||||
showErrorSwitch.isOn = viewModel.showError
|
||||
disabledSwitch.isOn = viewModel.disabled
|
||||
checkbox.set(with: viewModel)
|
||||
}
|
||||
|
||||
|
||||
//Picker
|
||||
func setupPicker(){
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
import VDS
|
||||
import VDSColorTokens
|
||||
|
||||
class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
||||
class LabelViewController: ModelScrollViewController {
|
||||
|
||||
lazy var textSizePickerSelectorView = {
|
||||
TextSizePickerSelectorView(title: "",
|
||||
@ -67,22 +67,14 @@ class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
||||
}
|
||||
|
||||
func setupModel() {
|
||||
var defaultModel = DefaultLabelModel()
|
||||
defaultModel.text = "Label Component"
|
||||
defaultModel.typograpicalStyle = .FeatureSmall
|
||||
set(with: defaultModel)
|
||||
|
||||
label
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] viewModel in
|
||||
self?.model = viewModel
|
||||
}.store(in: &subscribers)
|
||||
label.text = "Label Component"
|
||||
label.typograpicalStyle = .FeatureSmall
|
||||
|
||||
//setup UI
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.disabled
|
||||
surfacePickerSelectorView.text = label.surface.rawValue
|
||||
disabledSwitch.isOn = label.disabled
|
||||
boldSwitch.isOn = isBold
|
||||
textField.text = model.text
|
||||
textField.text = label.text
|
||||
|
||||
//set the font
|
||||
fontCategory = .feature
|
||||
@ -91,10 +83,6 @@ class LabelViewController: ModelScrollViewController<DefaultLabelModel> {
|
||||
textSizePickerSelectorView.text = "Small"
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultLabelModel) {
|
||||
label.set(with: viewModel)
|
||||
}
|
||||
|
||||
//Picker
|
||||
private var fontCategory: TypographicalStyle.FontCategory = .feature {
|
||||
didSet {
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
import Combine
|
||||
import VDS
|
||||
|
||||
public class ModelScrollViewController<ModelType: Modelable>: UIViewController, ModelHandlerable, Initable {
|
||||
public class ModelScrollViewController: UIViewController, ModelHandlerable, Initable {
|
||||
deinit {
|
||||
print("\(Self.self) deinit")
|
||||
}
|
||||
@ -21,8 +21,7 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
//--------------------------------------------------
|
||||
// MARK: - Combine Properties
|
||||
//--------------------------------------------------
|
||||
@Published public var model: ModelType = ModelType()
|
||||
public var modelPublisher: Published<ModelType>.Publisher { $model }
|
||||
public var subject = PassthroughSubject<Void, Never>()
|
||||
public var subscribers = Set<AnyCancellable>()
|
||||
public var firstRender: Bool = false
|
||||
|
||||
@ -31,11 +30,9 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
//--------------------------------------------------
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
@Proxy(\.model.surface)
|
||||
open var surface: Surface
|
||||
open var surface: Surface = .light { didSet { subject.send() }}
|
||||
|
||||
@Proxy(\.model.disabled)
|
||||
open var disabled: Bool
|
||||
open var disabled: Bool = false { didSet { subject.send() }}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initializers
|
||||
@ -43,15 +40,8 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
required public init() {
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
initialSetup()
|
||||
set(with: model)
|
||||
}
|
||||
|
||||
public required init(with model: ModelType) {
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
initialSetup()
|
||||
set(with: model)
|
||||
}
|
||||
|
||||
|
||||
public override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
initialSetup()
|
||||
@ -206,6 +196,8 @@ public class ModelScrollViewController<ModelType: Modelable>: UIViewController,
|
||||
|
||||
open func setup() {}
|
||||
|
||||
open func updateView(viewModel: ModelType) {}
|
||||
|
||||
open func updateView() {
|
||||
print("\(Self.self) updateView()")
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import VDS
|
||||
import VDSColorTokens
|
||||
import Combine
|
||||
|
||||
class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGroupModel> {
|
||||
class RadioBoxGroupViewController: ModelScrollViewController {
|
||||
|
||||
var disabledSwitch = UISwitch()
|
||||
var strikeThroughSwitch = UISwitch()
|
||||
@ -71,33 +71,22 @@ class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGro
|
||||
}
|
||||
|
||||
func setupModel(){
|
||||
var defaultModel = DefaultRadioBoxGroupModel()
|
||||
var model1 = DefaultRadioBoxModel()
|
||||
model1.inputId = "model1"
|
||||
model1.selected = true
|
||||
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.inputId = "model2"
|
||||
model2.value = "model 2 Value"
|
||||
model2.text = "iPhone 11 Bundle 2"
|
||||
model2.subText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
||||
var radioBox1 = RadioBox()
|
||||
radioBox1.inputId = "model1"
|
||||
radioBox1.isSelected = true
|
||||
radioBox1.value = "model 1 Value"
|
||||
radioBox1.text = "iPhone 11 Bundle 1"
|
||||
radioBox1.subText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
|
||||
radioBox1.subTextRight = "Right Text"
|
||||
|
||||
defaultModel.selectors = [model1, model2]
|
||||
set(with: defaultModel)
|
||||
var radioBox2 = RadioBox()
|
||||
radioBox2.inputId = "model2"
|
||||
radioBox2.value = "model 2 Value"
|
||||
radioBox2.text = "iPhone 11 Bundle 2"
|
||||
radioBox2.subText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
||||
|
||||
//update the model
|
||||
radioBoxGroup
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] updatedModel in
|
||||
self?.model = updatedModel
|
||||
self?.showErrorSwitch.isOn = updatedModel.showError
|
||||
self?.disabledSwitch.isOn = updatedModel.disabled
|
||||
}
|
||||
.store(in: &subscribers)
|
||||
radioBoxGroup.selectorViews = [radioBox1, radioBox2]
|
||||
|
||||
radioBoxGroup
|
||||
.publisher(for: .valueChanged)
|
||||
@ -106,20 +95,13 @@ class RadioBoxGroupViewController: ModelScrollViewController<DefaultRadioBoxGro
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//set UI values
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.disabled
|
||||
textField.text = model1.text
|
||||
subTextField.text = model1.subText
|
||||
subTextRightField.text = model1.subTextRight
|
||||
surfacePickerSelectorView.text = radioBoxGroup.surface.rawValue
|
||||
disabledSwitch.isOn = radioBoxGroup.disabled
|
||||
textField.text = radioBox1.text
|
||||
subTextField.text = radioBox1.subText
|
||||
subTextRightField.text = radioBox1.subTextRight
|
||||
}
|
||||
|
||||
override func updateView(viewModel: ModelType) {
|
||||
print("\(Self.self) updateView(viewModel)")
|
||||
showErrorSwitch.isOn = viewModel.showError
|
||||
disabledSwitch.isOn = viewModel.disabled
|
||||
radioBoxGroup.set(with: viewModel)
|
||||
}
|
||||
|
||||
|
||||
var radioBox: RadioBox? {
|
||||
radioBoxGroup.selectorViews.first
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ import VDS
|
||||
import VDSColorTokens
|
||||
import Combine
|
||||
|
||||
class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGroupModel> {
|
||||
class RadioButtonViewController: ModelScrollViewController {
|
||||
|
||||
var disabledSwitch = UISwitch()
|
||||
var labelTextField = TextField()
|
||||
@ -63,36 +63,25 @@ class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGr
|
||||
}
|
||||
|
||||
func setupModel(){
|
||||
var defaultModel = DefaultRadioButtonGroupModel()
|
||||
var model1 = DefaultRadioButtonModel()
|
||||
model1.inputId = "model1"
|
||||
model1.value = "model 1 Value"
|
||||
model1.labelText = "iPhone 11 Bundle 1"
|
||||
model1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
|
||||
let radioButton1 = RadioButton()
|
||||
radioButton1.inputId = "model1"
|
||||
radioButton1.value = "model 1 Value"
|
||||
radioButton1.labelText = "iPhone 11 Bundle 1"
|
||||
radioButton1.childText = "Apple iPhone 11 - 64 GB\nOtterbox Case Red\nScreen Protector"
|
||||
|
||||
var model2 = DefaultRadioButtonModel()
|
||||
model2.inputId = "model2"
|
||||
model2.value = "model 2 Value"
|
||||
model2.labelText = "iPhone 11 Bundle 2"
|
||||
model2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
||||
let radioButton2 = RadioButton()
|
||||
radioButton2.inputId = "model2"
|
||||
radioButton2.value = "model 2 Value"
|
||||
radioButton2.labelText = "iPhone 11 Bundle 2"
|
||||
radioButton2.childText = "Apple iPhone 11 - 128 GB\nOtterbox Case Black\nScreen Protector"
|
||||
|
||||
var model3 = DefaultRadioButtonModel()
|
||||
model3.inputId = "model3"
|
||||
model3.value = "model 3 Value"
|
||||
model3.labelText = "iPhone 11 Bundle 3"
|
||||
model3.childText = "Apple iPhone 11 - 256 GB\nOtterbox Case Black\nScreen Protector"
|
||||
defaultModel.selectors = [model1, model2, model3]
|
||||
set(with: defaultModel)
|
||||
|
||||
//update the model
|
||||
radioButtonGroup
|
||||
.handlerPublisher()
|
||||
.sink { [weak self] updatedModel in
|
||||
self?.model = updatedModel
|
||||
self?.showErrorSwitch.isOn = updatedModel.showError
|
||||
self?.disabledSwitch.isOn = updatedModel.disabled
|
||||
}
|
||||
.store(in: &subscribers)
|
||||
let radioButton3 = RadioButton()
|
||||
radioButton3.inputId = "model3"
|
||||
radioButton3.value = "model 3 Value"
|
||||
radioButton3.labelText = "iPhone 11 Bundle 3"
|
||||
radioButton3.childText = "Apple iPhone 11 - 256 GB\nOtterbox Case Black\nScreen Protector"
|
||||
|
||||
radioButtonGroup.selectorViews = [radioButton1, radioButton2, radioButton3]
|
||||
|
||||
radioButtonGroup
|
||||
.publisher(for: .valueChanged)
|
||||
@ -101,18 +90,11 @@ class RadioButtonViewController: ModelScrollViewController<DefaultRadioButtonGr
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//set UI values
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.disabled
|
||||
showErrorSwitch.isOn = model.showError
|
||||
labelTextField.text = model1.labelText
|
||||
childTextField.text = model1.childText
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultRadioButtonGroupModel) {
|
||||
print("\(Self.self) updateView(viewModel)")
|
||||
showErrorSwitch.isOn = viewModel.showError
|
||||
disabledSwitch.isOn = viewModel.disabled
|
||||
radioButtonGroup.set(with: viewModel)
|
||||
surfacePickerSelectorView.text = radioButtonGroup.surface.rawValue
|
||||
disabledSwitch.isOn = radioButtonGroup.disabled
|
||||
showErrorSwitch.isOn = radioButtonGroup.showError
|
||||
labelTextField.text = radioButton1.labelText
|
||||
childTextField.text = radioButton1.childText
|
||||
}
|
||||
|
||||
var radioButton: RadioButton? {
|
||||
|
||||
@ -11,7 +11,7 @@ import VDS
|
||||
import VDSColorTokens
|
||||
import Combine
|
||||
|
||||
class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwatchGroupModel> {
|
||||
class RadioSwatchGroupViewController: ModelScrollViewController {
|
||||
|
||||
var disabledSwitch = UISwitch()
|
||||
var strikeThroughSwitch = UISwitch()
|
||||
@ -39,93 +39,64 @@ class RadioSwatchGroupViewController: ModelScrollViewController<DefaultRadioSwa
|
||||
strikeThroughSwitch
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { [weak self] sender in
|
||||
let selectors = self?.model.selectors.compactMap { existing in
|
||||
if existing.id == self?.model.selectors.first?.id {
|
||||
return existing.copyWith {
|
||||
$0.strikethrough = sender.isOn
|
||||
}
|
||||
} else {
|
||||
return existing
|
||||
}
|
||||
}
|
||||
if let selectors {
|
||||
self?.model.selectors = selectors
|
||||
}
|
||||
self?.radioSwatchGroup.selectorViews.first?.strikethrough = sender.isOn
|
||||
}.store(in: &subscribers)
|
||||
}
|
||||
|
||||
func setupModel(){
|
||||
var defaultModel = DefaultRadioSwatchGroupModel()
|
||||
|
||||
var model1 = DefaultRadioSwatchModel()
|
||||
model1.fillImage = UIImage(named: "imageSwatch")
|
||||
model1.text = "Image"
|
||||
model1.inputId = "radioSwatch1"
|
||||
let radioSwatch1 = RadioSwatch()
|
||||
radioSwatch1.fillImage = UIImage(named: "imageSwatch")
|
||||
radioSwatch1.text = "Image"
|
||||
radioSwatch1.inputId = "radioSwatch1"
|
||||
|
||||
var model2 = DefaultRadioSwatchModel()
|
||||
model2.primaryColor = .red
|
||||
model2.secondaryColor = .blue
|
||||
model2.text = "Red/Blue"
|
||||
model2.inputId = "radioSwatch2"
|
||||
let radioSwatch2 = RadioSwatch()
|
||||
radioSwatch2.primaryColor = .red
|
||||
radioSwatch2.secondaryColor = .blue
|
||||
radioSwatch2.text = "Red/Blue"
|
||||
radioSwatch2.inputId = "radioSwatch2"
|
||||
|
||||
var model3 = DefaultRadioSwatchModel()
|
||||
model3.primaryColor = .green
|
||||
model3.text = "Green"
|
||||
model3.inputId = "radioSwatch3"
|
||||
let radioSwatch3 = RadioSwatch()
|
||||
radioSwatch3.primaryColor = .green
|
||||
radioSwatch3.text = "Green"
|
||||
radioSwatch3.inputId = "radioSwatch3"
|
||||
|
||||
var model4 = DefaultRadioSwatchModel()
|
||||
model4.primaryColor = .orange
|
||||
model4.text = "Orange"
|
||||
model4.inputId = "radioSwatch4"
|
||||
let radioSwatch4 = RadioSwatch()
|
||||
radioSwatch4.primaryColor = .orange
|
||||
radioSwatch4.text = "Orange"
|
||||
radioSwatch4.inputId = "radioSwatch4"
|
||||
|
||||
var model5 = DefaultRadioSwatchModel()
|
||||
model5.primaryColor = .brown
|
||||
model5.text = "Brown"
|
||||
model5.inputId = "radioSwatch5"
|
||||
let radioSwatch5 = RadioSwatch()
|
||||
radioSwatch5.primaryColor = .brown
|
||||
radioSwatch5.text = "Brown"
|
||||
radioSwatch5.inputId = "radioSwatch5"
|
||||
|
||||
var model6 = DefaultRadioSwatchModel()
|
||||
model6.primaryColor = .yellow
|
||||
model6.text = "Yellow"
|
||||
model6.inputId = "radioSwatch6"
|
||||
let radioSwatch6 = RadioSwatch()
|
||||
radioSwatch6.primaryColor = .yellow
|
||||
radioSwatch6.text = "Yellow"
|
||||
radioSwatch6.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"
|
||||
let radioSwatch7 = RadioSwatch()
|
||||
radioSwatch7.primaryColor = .purple
|
||||
radioSwatch7.text = "Puple"
|
||||
radioSwatch7.inputId = "radioSwatch7"
|
||||
|
||||
let radioSwatch8 = RadioSwatch()
|
||||
radioSwatch8.primaryColor = .systemPink
|
||||
radioSwatch8.text = "Pink"
|
||||
radioSwatch8.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)
|
||||
radioSwatchGroup.selectorViews = [radioSwatch1, radioSwatch2, radioSwatch3, radioSwatch4, radioSwatch5, radioSwatch6, radioSwatch7, radioSwatch8]
|
||||
|
||||
radioSwatchGroup
|
||||
.publisher(for: .valueChanged)
|
||||
.sink { group in
|
||||
print("Selected: \(group.selectedModelHandler?.text ?? "none")")
|
||||
print("Selected: \(group.selectedHandler?.text ?? "none")")
|
||||
}.store(in: &subscribers)
|
||||
|
||||
//set UI values
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
disabledSwitch.isOn = model.disabled
|
||||
}
|
||||
|
||||
override func updateView(viewModel: ModelType) {
|
||||
print("\(Self.self) updateView(viewModel)")
|
||||
disabledSwitch.isOn = viewModel.disabled
|
||||
radioSwatchGroup.set(with: viewModel)
|
||||
surfacePickerSelectorView.text = radioSwatchGroup.surface.rawValue
|
||||
disabledSwitch.isOn = radioSwatchGroup.disabled
|
||||
}
|
||||
|
||||
//Picker
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
import VDS
|
||||
import VDSColorTokens
|
||||
|
||||
class ToggleViewController: ModelScrollViewController<DefaultToggleModel> {
|
||||
class ToggleViewController: ModelScrollViewController {
|
||||
|
||||
lazy var textSizePickerSelectorView = {
|
||||
PickerSelectorView(title: "",
|
||||
@ -105,20 +105,14 @@ class ToggleViewController: ModelScrollViewController<DefaultToggleModel> {
|
||||
textFormStackView.isHidden = true
|
||||
|
||||
//setup UI
|
||||
surfacePickerSelectorView.text = model.surface.rawValue
|
||||
textSizePickerSelectorView.text = model.textSize.rawValue
|
||||
textPositionPickerSelectorView.text = model.textPosition.rawValue
|
||||
onTextField.text = model.onText
|
||||
offTextField.text = model.offText
|
||||
surfacePickerSelectorView.text = toggle.surface.rawValue
|
||||
textSizePickerSelectorView.text = toggle.textSize.rawValue
|
||||
textPositionPickerSelectorView.text = toggle.textPosition.rawValue
|
||||
onTextField.text = toggle.onText
|
||||
offTextField.text = toggle.offText
|
||||
}
|
||||
|
||||
override func updateView(viewModel: DefaultToggleModel) {
|
||||
print("\(Self.self) updateView(viewModel)")
|
||||
toggle.set(with: viewModel)
|
||||
}
|
||||
|
||||
//Picker
|
||||
|
||||
//Picker
|
||||
func setupPicker(){
|
||||
|
||||
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
|
||||
|
||||
Loading…
Reference in New Issue
Block a user