starting of button
Signed-off-by: Jarrod Courtney <jarrod.courtney@gmail.com>
This commit is contained in:
parent
31fae5c21c
commit
50dcae0ddd
@ -32,6 +32,7 @@
|
|||||||
/* End PBXAggregateTarget section */
|
/* End PBXAggregateTarget section */
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* Begin PBXBuildFile section */
|
||||||
|
5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */; };
|
||||||
EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9C289966EF000CA526 /* AppDelegate.swift */; };
|
EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9C289966EF000CA526 /* AppDelegate.swift */; };
|
||||||
EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */; };
|
EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */; };
|
||||||
EA3C3BA4289966EF000CA526 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EA3C3BA2289966EF000CA526 /* Main.storyboard */; };
|
EA3C3BA4289966EF000CA526 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EA3C3BA2289966EF000CA526 /* Main.storyboard */; };
|
||||||
@ -87,6 +88,7 @@
|
|||||||
/* End PBXCopyFilesBuildPhase section */
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
|
5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonViewController.swift; sourceTree = "<group>"; };
|
||||||
EA3C3B99289966EF000CA526 /* VDSSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VDSSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
EA3C3B99289966EF000CA526 /* VDSSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VDSSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||||
EA3C3B9C289966EF000CA526 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
EA3C3B9C289966EF000CA526 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||||
EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
|
EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
|
||||||
@ -251,6 +253,7 @@
|
|||||||
EAF7F11928A14A0E00B287F5 /* RadioButtonViewController.swift */,
|
EAF7F11928A14A0E00B287F5 /* RadioButtonViewController.swift */,
|
||||||
EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */,
|
EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */,
|
||||||
EA3C3BB328996775000CA526 /* ToggleViewController.swift */,
|
EA3C3BB328996775000CA526 /* ToggleViewController.swift */,
|
||||||
|
5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */,
|
||||||
);
|
);
|
||||||
path = ViewControllers;
|
path = ViewControllers;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -404,6 +407,7 @@
|
|||||||
EAF7F11A28A14A0E00B287F5 /* RadioButtonViewController.swift in Sources */,
|
EAF7F11A28A14A0E00B287F5 /* RadioButtonViewController.swift in Sources */,
|
||||||
EA89204628B66CE2006B9984 /* ScrollViewController.swift in Sources */,
|
EA89204628B66CE2006B9984 /* ScrollViewController.swift in Sources */,
|
||||||
EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */,
|
EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */,
|
||||||
|
5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */,
|
||||||
EA89204A28B66CE2006B9984 /* KeyboardFrameChange.swift in Sources */,
|
EA89204A28B66CE2006B9984 /* KeyboardFrameChange.swift in Sources */,
|
||||||
EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */,
|
EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */,
|
||||||
EAB1D2C928AAAA1D00DAE764 /* ModelScrollViewController.swift in Sources */,
|
EAB1D2C928AAAA1D00DAE764 /* ModelScrollViewController.swift in Sources */,
|
||||||
|
|||||||
@ -95,3 +95,10 @@ class FontCategoryPicker: PickerBase<TypographicalStyle.FontCategory> {
|
|||||||
super.init(items: TypographicalStyle.FontCategory.allCases)
|
super.init(items: TypographicalStyle.FontCategory.allCases)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UsePicker: PickerBase<Use> {
|
||||||
|
init(){
|
||||||
|
super.init(items: [.primary, .secondary])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
139
VDSSample/ViewControllers/ButtonViewController.swift
Normal file
139
VDSSample/ViewControllers/ButtonViewController.swift
Normal file
@ -0,0 +1,139 @@
|
|||||||
|
//
|
||||||
|
// ButtonViewController.swift
|
||||||
|
// VDSSample
|
||||||
|
//
|
||||||
|
// Created by Jarrod Courtney on 9/16/22.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import UIKit
|
||||||
|
import VDS
|
||||||
|
import VDSColorTokens
|
||||||
|
|
||||||
|
class ButtonViewController: ModelScrollViewController<DefaultButtonModel> {
|
||||||
|
|
||||||
|
enum PickerType {
|
||||||
|
case surface, use
|
||||||
|
}
|
||||||
|
var surfacePickerSelectorView = PickerSelectorView(title: "")
|
||||||
|
var usePickerSelectorView = PickerSelectorView(title: "")
|
||||||
|
|
||||||
|
var disabledSwitch = UISwitch()
|
||||||
|
var textField = TextField()
|
||||||
|
var widthTextField = TextField()
|
||||||
|
|
||||||
|
let button = Button()
|
||||||
|
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
//addContentTopView(view: button)
|
||||||
|
contentTopView.addSubview(button)
|
||||||
|
|
||||||
|
setupForm()
|
||||||
|
setupPicker()
|
||||||
|
setupModel()
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupForm(){
|
||||||
|
addFormRow(label: "Surface", view: surfacePickerSelectorView)
|
||||||
|
addFormRow(label: "Use", view: usePickerSelectorView)
|
||||||
|
addFormRow(label: "Disabled", view: disabledSwitch)
|
||||||
|
addFormRow(label: "Label", view: textField)
|
||||||
|
addFormRow(label: "Width", view: widthTextField)
|
||||||
|
|
||||||
|
|
||||||
|
disabledSwitch
|
||||||
|
.publisher(for: .valueChanged)
|
||||||
|
.sink { [weak self] sender in
|
||||||
|
self?.button.disabled = sender.isOn
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
surfacePickerSelectorView.button
|
||||||
|
.publisher(for: .touchUpInside)
|
||||||
|
.sink { [weak self] _ in
|
||||||
|
self?.pickerType = .surface
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
usePickerSelectorView.button
|
||||||
|
.publisher(for: .touchUpInside)
|
||||||
|
.sink { [weak self] _ in
|
||||||
|
self?.pickerType = .use
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
textField
|
||||||
|
.textPublisher
|
||||||
|
.sink { [weak self] text in
|
||||||
|
self?.button.setTitle(text, for: .normal)
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
widthTextField
|
||||||
|
.textPublisher
|
||||||
|
.sink { [weak self] text in
|
||||||
|
if let n = NumberFormatter().number(from: text) {
|
||||||
|
self?.button.buttonWidth = CGFloat(truncating: n)
|
||||||
|
}
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupModel() {
|
||||||
|
var defaultModel = DefaultButtonModel()
|
||||||
|
defaultModel.text = "Button"
|
||||||
|
set(with: defaultModel)
|
||||||
|
|
||||||
|
button
|
||||||
|
.handlerPublisher()
|
||||||
|
.sink { [weak self] viewModel in
|
||||||
|
self?.model = viewModel
|
||||||
|
}.store(in: &subscribers)
|
||||||
|
|
||||||
|
//setup UI
|
||||||
|
surfacePickerSelectorView.text = model.surface.rawValue
|
||||||
|
disabledSwitch.isOn = model.disabled
|
||||||
|
textField.text = model.text
|
||||||
|
usePickerSelectorView.text = model.use.rawValue
|
||||||
|
widthTextField.text = "200"
|
||||||
|
}
|
||||||
|
|
||||||
|
override func updateView(viewModel: DefaultButtonModel) {
|
||||||
|
button.set(with: viewModel)
|
||||||
|
}
|
||||||
|
|
||||||
|
//Picker
|
||||||
|
var surfacePicker = SurfacePicker()
|
||||||
|
var usePicker = UsePicker()
|
||||||
|
var buttonSizePicker = TextSizePicker()
|
||||||
|
|
||||||
|
var pickerType: PickerType = .surface {
|
||||||
|
didSet {
|
||||||
|
func update(object: UIPickerViewDelegate & UIPickerViewDataSource){
|
||||||
|
picker.delegate = object
|
||||||
|
picker.dataSource = object
|
||||||
|
}
|
||||||
|
|
||||||
|
switch pickerType{
|
||||||
|
case .surface:
|
||||||
|
update(object: surfacePicker)
|
||||||
|
case .use:
|
||||||
|
update(object: usePicker)
|
||||||
|
}
|
||||||
|
picker.reloadAllComponents()
|
||||||
|
picker.selectRow(0, inComponent: 0, animated: false)
|
||||||
|
picker.isHidden = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupPicker(){
|
||||||
|
surfacePicker.onPickerDidSelect = { [weak self] item in
|
||||||
|
self?.button.surface = item
|
||||||
|
self?.contentTopView.backgroundColor = item.color
|
||||||
|
self?.surfacePickerSelectorView.text = item.rawValue
|
||||||
|
}
|
||||||
|
|
||||||
|
usePicker.onPickerDidSelect = { [weak self] item in
|
||||||
|
self?.button.use = item
|
||||||
|
self?.button.backgroundColor = item.color
|
||||||
|
self?.usePickerSelectorView.text = item.rawValue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,7 +25,9 @@ class MenuViewController: UITableViewController {
|
|||||||
MenuComponent(title: "RadioButtonGroup", viewController: RadioButtonViewController.self),
|
MenuComponent(title: "RadioButtonGroup", viewController: RadioButtonViewController.self),
|
||||||
MenuComponent(title: "RadioBoxGroup", viewController: RadioBoxGroupViewController.self),
|
MenuComponent(title: "RadioBoxGroup", viewController: RadioBoxGroupViewController.self),
|
||||||
MenuComponent(title: "RadioSwatchGroup", viewController: RadioSwatchGroupViewController.self),
|
MenuComponent(title: "RadioSwatchGroup", viewController: RadioSwatchGroupViewController.self),
|
||||||
MenuComponent(title: "Toggle", viewController: ToggleViewController.self)
|
MenuComponent(title: "Toggle", viewController: ToggleViewController.self),
|
||||||
|
MenuComponent(title: "Button", viewController: ButtonViewController.self)
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
override func numberOfSections(in tableView: UITableView) -> Int {
|
override func numberOfSections(in tableView: UITableView) -> Int {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user