vds_ios_sample/VDSSample/ViewControllers/TileletGroupViewController.swift
Matt Bruce be7d68636a updated samples
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2024-10-09 16:30:26 -05:00

123 lines
3.6 KiB
Swift

//
// TileletGroupViewController.swift
// VDSSample
//
// Created by Matt Bruce on 10/8/24.
//
import Foundation
import UIKit
import VDS
import VDSCoreTokens
class TileletGroupViewController: BaseViewController<TileletGroup> {
var collectionView: UICollectionView!
public enum RowQuantity: String, CaseIterable {
case one, two, three, four
init(quantity: Int){
if quantity == 1 {
self = .one
} else if quantity == 2 {
self = .two
} else if quantity == 3 {
self = .three
} else {
self = .four
}
}
var intValue: Int {
switch self {
case .one:
return 1
case .two:
return 2
case .three:
return 3
case .four:
return 4
}
}
}
lazy var rowQuantitySelectorView = {
PickerSelectorView<RowQuantity>(title: "",
picker: self.picker,
items: RowQuantity.allCases)
}()
var disabledSwitch = Toggle()
var widthTextField = NumericField()
override func viewDidLoad() {
super.viewDidLoad()
resetTilets()
addContentTopView(view: component)
setupPicker()
setupModel()
debugViewSwitch.onChange = { [weak self] sender in
self?.component.debugBorder(show: sender.isOn, color: .blue)
}
}
func resetTilets() {
component.tilelets = [
makeTilelet(badge: "Here's the badge", title: "Title goes here"),
makeTilelet(title: "Title goes here"),
makeTilelet(subTitle: "Here's the subTitle"),
makeTilelet(eyebrow: "Here's the eyebrow", subTitle: "Here's the subTitle")
]
}
override func setupForm(){
super.setupForm()
addActionRow()
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Disabled", view: disabledSwitch, pinTrailing: false)
addFormRow(label: "Width", view: widthTextField)
addFormRow(label: "Row Quantity", view: rowQuantitySelectorView)
disabledSwitch.onChange = { [weak self] sender in
self?.component.isEnabled = !sender.isOn
}
// widthTextField
// .numberPublisher
// .sink { [weak self] number in
// if let number {
// // self?.component.childWidth = .value(number.cgFloatValue)
// }
// }.store(in: &subscribers)
}
func setupModel() {
//setup UI
surfacePickerSelectorView.text = component.surface.rawValue
disabledSwitch.isOn = !component.isEnabled
rowQuantitySelectorView.text = RowQuantity(quantity: component.rowQuantity).rawValue
widthTextField.text = ""
}
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.surface = item
self?.contentTopView.backgroundColor = item.color
}
rowQuantitySelectorView.onPickerDidSelect = { [weak self] item in
self?.widthTextField.isEnabled = item.intValue == 0
if UIDevice.isIPad {
self?.component.rowQuantityTablet = item.intValue
} else {
self?.component.rowQuantityPhone = item.intValue
}
self?.resetTilets()
}
}
}