udpated base viewcontroller to fix bug in form creation

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-05-25 11:51:57 -05:00
parent 089020c64b
commit 38e7c6b8de
5 changed files with 76 additions and 144 deletions

View File

@ -651,7 +651,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 17; CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_TEAM = FCMA4QKS77; DEVELOPMENT_TEAM = 59V5935DHZ;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VDSSample/Info.plist; INFOPLIST_FILE = VDSSample/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@ -665,7 +665,7 @@
"@executable_path/Frameworks", "@executable_path/Frameworks",
); );
MARKETING_VERSION = 1.0; MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.vzw.VDSSample; PRODUCT_BUNDLE_IDENTIFIER = com.vzw.enterprise.VDSSample;
PRODUCT_NAME = "$(TARGET_NAME)"; PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES; SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0; SWIFT_VERSION = 5.0;
@ -681,7 +681,7 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO; ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 17; CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_TEAM = FCMA4QKS77; DEVELOPMENT_TEAM = 59V5935DHZ;
GENERATE_INFOPLIST_FILE = YES; GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VDSSample/Info.plist; INFOPLIST_FILE = VDSSample/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;

View File

@ -10,6 +10,45 @@ import UIKit
import Combine import Combine
import VDS import VDS
public class FormSection: UIStackView {
public override init(frame: CGRect) {
super.init(frame: frame)
translatesAutoresizingMaskIntoConstraints = false
alignment = .fill
distribution = .fill
axis = .vertical
spacing = 10
}
public convenience init() {
self.init(frame: .zero)
}
required init(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
open func addFormRow(label: String, view: UIView) {
let formRow = UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fillEqually
$0.axis = .horizontal
$0.spacing = 5
}
let label = Label().with {
$0.text = label
$0.textStyle = .bodyLarge
}
formRow.addArrangedSubview(label)
formRow.addArrangedSubview(view)
addArrangedSubview(formRow)
}
}
public class BaseViewController<Component: UIView>: UIViewController, Initable { public class BaseViewController<Component: UIView>: UIViewController, Initable {
deinit { deinit {
print("\(Self.self) deinit") print("\(Self.self) deinit")
@ -85,15 +124,7 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
} }
}() }()
public var formStackView: UIStackView = { public var formStackView = FormSection()
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fill
$0.axis = .vertical
$0.spacing = 10
}
}()
public var contentTopView: UIView = { public var contentTopView: UIView = {
return UIView().with { return UIView().with {
@ -173,29 +204,12 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
view.pinToSuperView(.init(top: edgeSpacing, left: edgeSpacing, bottom: edgeSpacing, right: edgeSpacing)) view.pinToSuperView(.init(top: edgeSpacing, left: edgeSpacing, bottom: edgeSpacing, right: edgeSpacing))
} }
open func addFormRow(label: String, view: UIView, stackView: UIStackView? = nil) { open func append(section: FormSection) {
let formRow = UIStackView().with { formStackView.addArrangedSubview(section)
$0.translatesAutoresizingMaskIntoConstraints = false }
$0.alignment = .fill
$0.distribution = .fillEqually
$0.axis = .horizontal
$0.spacing = 5
}
let label = Label().with {
$0.text = label
$0.textStyle = .bodyLarge
}
formRow.addArrangedSubview(label)
formRow.addArrangedSubview(view)
if let stackView {
stackView.addArrangedSubview(formRow)
} else {
formStackView.addArrangedSubview(formRow)
}
open func addFormRow(label: String, view: UIView) {
formStackView.addFormRow(label: label, view: view)
if let pickerViewable = view as? any PickerViewable { if let pickerViewable = view as? any PickerViewable {
pickerViewable.scrollToBottom = { [weak self] in self?.scrollToBottom() } pickerViewable.scrollToBottom = { [weak self] in self?.scrollToBottom() }
} }

View File

@ -11,8 +11,10 @@ import VDS
import Combine import Combine
import VDSColorTokens import VDSColorTokens
class TabsContainerViewController: BaseViewController<TabsContainer> { class TabsContainerViewController: BaseViewController<TabsContainer> {
var disabledSwitch = Toggle() var disabledSwitch = Toggle()
var borderlineSwitch = Toggle() var borderlineSwitch = Toggle()
var fillContainerSwitch = Toggle() var fillContainerSwitch = Toggle()
@ -20,26 +22,8 @@ class TabsContainerViewController: BaseViewController<TabsContainer> {
var widthValueTextField = NumericField() var widthValueTextField = NumericField()
var widthPercentageTextField = NumericField() var widthPercentageTextField = NumericField()
var verticalOrientationFormStackView: UIStackView = { var verticalOrientationFormStackView = FormSection()
return UIStackView().with { var horizontalOrientationFormStackView = FormSection()
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fill
$0.axis = .vertical
$0.spacing = 10
$0.isHidden = true
}
}()
var horizontalOrientationFormStackView: UIStackView = {
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fill
$0.axis = .vertical
$0.spacing = 10
}
}()
override func allTextFields() -> [TextField]? { [widthValueTextField, widthPercentageTextField] } override func allTextFields() -> [TextField]? { [widthValueTextField, widthPercentageTextField] }
@ -77,7 +61,6 @@ class TabsContainerViewController: BaseViewController<TabsContainer> {
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Large Sample", view: .makeWrapper(for: sampleSwitch)) addFormRow(label: "Large Sample", view: .makeWrapper(for: sampleSwitch))
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Show Borderline", view: .makeWrapper(for: borderlineSwitch)) addFormRow(label: "Show Borderline", view: .makeWrapper(for: borderlineSwitch))
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Size", view: sizePickerSelectorView) addFormRow(label: "Size", view: sizePickerSelectorView)
@ -85,17 +68,17 @@ class TabsContainerViewController: BaseViewController<TabsContainer> {
if UIDevice.isIPad { if UIDevice.isIPad {
addFormRow(label: "Orientation", view: orientationPickerSelectorView) addFormRow(label: "Orientation", view: orientationPickerSelectorView)
//only in vertical mode //only in vertical mode
addFormRow(label: "% Width (0.25 -> 1.0)", view: widthPercentageTextField, stackView: verticalOrientationFormStackView) verticalOrientationFormStackView.addFormRow(label: "% Width (0.25 -> 1.0)", view: widthPercentageTextField)
addFormRow(label: "# Width", view: widthValueTextField, stackView: verticalOrientationFormStackView) verticalOrientationFormStackView.addFormRow(label: "# Width", view: widthValueTextField)
} }
//only in horizontal mode //only in horizontal mode
addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch), stackView: horizontalOrientationFormStackView) horizontalOrientationFormStackView.addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch))
addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView, stackView: horizontalOrientationFormStackView) horizontalOrientationFormStackView.addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView)
addFormRow(label: "Overflow", view: overflowPickerSelectorView, stackView: horizontalOrientationFormStackView) horizontalOrientationFormStackView.addFormRow(label: "Overflow", view: overflowPickerSelectorView)
formStackView.addArrangedSubview(verticalOrientationFormStackView) append(section: verticalOrientationFormStackView)
formStackView.addArrangedSubview(horizontalOrientationFormStackView) append(section: horizontalOrientationFormStackView)
disabledSwitch.onChange = { [weak self] sender in disabledSwitch.onChange = { [weak self] sender in
self?.component.disabled = sender.isOn self?.component.disabled = sender.isOn
@ -151,7 +134,7 @@ class TabsContainerViewController: BaseViewController<TabsContainer> {
func setupModel() { func setupModel() {
//set to the large sample //set to the large sample
component.tabModels = getAllTabs() component.tabModels = getAllTabs()
//setup UI //setup UI
surfacePickerSelectorView.text = component.surface.rawValue surfacePickerSelectorView.text = component.surface.rawValue
sizePickerSelectorView.text = component.size.rawValue sizePickerSelectorView.text = component.size.rawValue

View File

@ -17,31 +17,8 @@ class TabsViewController: BaseViewController<Tabs> {
var borderlineSwitch = Toggle() var borderlineSwitch = Toggle()
var fillContainerSwitch = Toggle() var fillContainerSwitch = Toggle()
var sampleSwitch = Toggle() var sampleSwitch = Toggle()
var widthValueTextField = NumericField()
var widthPercentageTextField = NumericField()
var verticalOrientationFormStackView: UIStackView = { var horizontalOrientationFormStackView = FormSection()
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fillProportionally
$0.axis = .vertical
$0.spacing = 10
$0.isHidden = true
}
}()
var horizontalOrientationFormStackView: UIStackView = {
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fillProportionally
$0.axis = .vertical
$0.spacing = 10
}
}()
override func allTextFields() -> [TextField]? { [widthValueTextField, widthPercentageTextField] }
lazy var orientationPickerSelectorView = { lazy var orientationPickerSelectorView = {
PickerSelectorView(title: "", PickerSelectorView(title: "",
@ -77,25 +54,20 @@ class TabsViewController: BaseViewController<Tabs> {
override func setupForm(){ override func setupForm(){
super.setupForm() super.setupForm()
addFormRow(label: "Large Sample", view: .makeWrapper(for: sampleSwitch)) addFormRow(label: "Large Sample", view: .makeWrapper(for: sampleSwitch))
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Show Borderline", view: .makeWrapper(for: borderlineSwitch)) addFormRow(label: "Show Borderline", view: .makeWrapper(for: borderlineSwitch))
addFormRow(label: "Surface", view: surfacePickerSelectorView) addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Size", view: sizePickerSelectorView) addFormRow(label: "Size", view: sizePickerSelectorView)
if UIDevice.isIPad { if UIDevice.isIPad {
addFormRow(label: "Orientation", view: orientationPickerSelectorView) addFormRow(label: "Orientation", view: orientationPickerSelectorView)
// //only in vertical mode
// addFormRow(label: "% Width (0.25 -> 1.0)", view: widthPercentageTextField, stackView: verticalOrientationFormStackView)
// addFormRow(label: "# Width", view: widthValueTextField, stackView: verticalOrientationFormStackView)
} }
//only in horizontal mode //only in horizontal mode
addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch), stackView: horizontalOrientationFormStackView) horizontalOrientationFormStackView.addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch))
addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView, stackView: horizontalOrientationFormStackView) horizontalOrientationFormStackView.addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView)
addFormRow(label: "Overflow", view: overflowPickerSelectorView, stackView: horizontalOrientationFormStackView) horizontalOrientationFormStackView.addFormRow(label: "Overflow", view: overflowPickerSelectorView)
// formStackView.addArrangedSubview(verticalOrientationFormStackView) append(section: horizontalOrientationFormStackView)
formStackView.addArrangedSubview(horizontalOrientationFormStackView)
disabledSwitch.onChange = { [weak self] sender in disabledSwitch.onChange = { [weak self] sender in
self?.component.disabled = sender.isOn self?.component.disabled = sender.isOn
@ -114,22 +86,6 @@ class TabsViewController: BaseViewController<Tabs> {
self.component.selectedIndex = 0 self.component.selectedIndex = 0
self.component.tabModels = sender.isOn ? self.allTabs : self.some self.component.tabModels = sender.isOn ? self.allTabs : self.some
} }
// widthValueTextField.textPublisher.sink { [weak self] text in
// if let value = Double(text) {
// self?.component.width = .value(value)
// self?.widthPercentageTextField.text = ""
//
// }
// }.store(in: &subscribers)
//
// widthPercentageTextField.textPublisher.sink { [weak self] text in
// if let value = Double(text) {
// self?.component.width = .percentage(value)
// self?.widthValueTextField.text = ""
// }
// }.store(in: &subscribers)
} }
var allTabs: [Tabs.TabModel] = [ var allTabs: [Tabs.TabModel] = [
@ -158,7 +114,6 @@ class TabsViewController: BaseViewController<Tabs> {
borderlineSwitch.isOn = component.borderLine borderlineSwitch.isOn = component.borderLine
fillContainerSwitch.isOn = component.fillContainer fillContainerSwitch.isOn = component.fillContainer
sampleSwitch.isOn = true sampleSwitch.isOn = true
// updateWidth()
} }
func setupPicker(){ func setupPicker(){
@ -173,7 +128,6 @@ class TabsViewController: BaseViewController<Tabs> {
orientationPickerSelectorView.onPickerDidSelect = { [weak self] item in orientationPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.orientation = item self?.component.orientation = item
self?.verticalOrientationFormStackView.isHidden = item == .horizontal
self?.horizontalOrientationFormStackView.isHidden = item == .vertical self?.horizontalOrientationFormStackView.isHidden = item == .vertical
} }
@ -185,16 +139,4 @@ class TabsViewController: BaseViewController<Tabs> {
self?.component.overflow = item self?.component.overflow = item
} }
} }
// func updateWidth() {
// switch component.width {
// case .percentage(let percentage):
// widthPercentageTextField.text = "\(percentage)"
// case .value(let value):
// widthValueTextField.text = "\(value)"
// widthPercentageTextField.text = ""
// @unknown default:
// print("")
// }
// }
} }

View File

@ -28,15 +28,7 @@ class ToggleViewController: BaseViewController<Toggle> {
var disabledSwitch = Toggle() var disabledSwitch = Toggle()
var showTextSwitch = Toggle() var showTextSwitch = Toggle()
var textFormStackView: UIStackView = { var textFormStackView = FormSection()
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fillProportionally
$0.axis = .vertical
$0.spacing = 10
}
}()
var boldSwitch = Toggle() var boldSwitch = Toggle()
var onTextField = TextField() var onTextField = TextField()
@ -59,13 +51,14 @@ class ToggleViewController: BaseViewController<Toggle> {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch)) addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
//add the hidden elements to textFormStackView //add the hidden elements to textFormStackView
addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch), stackView: textFormStackView) textFormStackView.addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch))
addFormRow(label: "Text Size", view: textSizePickerSelectorView, stackView: textFormStackView) textFormStackView.addFormRow(label: "Text Size", view: textSizePickerSelectorView)
addFormRow(label: "Text Position", view: textPositionPickerSelectorView, stackView: textFormStackView) textFormStackView.addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
addFormRow(label: "On Text", view: onTextField, stackView: textFormStackView) textFormStackView.addFormRow(label: "On Text", view: onTextField)
addFormRow(label: "Off Text", view: offTextField, stackView: textFormStackView) textFormStackView.addFormRow(label: "Off Text", view: offTextField)
//add textFormStackView to main form //add textFormStackView to main form
formStackView.addArrangedSubview(textFormStackView) append(section: textFormStackView)
component.onChange = { [weak self] toggle in component.onChange = { [weak self] toggle in
let alertController:UIAlertController = UIAlertController(title: "Alert", let alertController:UIAlertController = UIAlertController(title: "Alert",