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

View File

@ -10,6 +10,45 @@ import UIKit
import Combine
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 {
deinit {
print("\(Self.self) deinit")
@ -85,15 +124,7 @@ public class BaseViewController<Component: UIView>: UIViewController, Initable {
}
}()
public var formStackView: UIStackView = {
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fill
$0.axis = .vertical
$0.spacing = 10
}
}()
public var formStackView = FormSection()
public var contentTopView: UIView = {
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))
}
open func addFormRow(label: String, view: UIView, stackView: UIStackView? = nil) {
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)
if let stackView {
stackView.addArrangedSubview(formRow)
} else {
formStackView.addArrangedSubview(formRow)
}
open func append(section: FormSection) {
formStackView.addArrangedSubview(section)
}
open func addFormRow(label: String, view: UIView) {
formStackView.addFormRow(label: label, view: view)
if let pickerViewable = view as? any PickerViewable {
pickerViewable.scrollToBottom = { [weak self] in self?.scrollToBottom() }
}

View File

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

View File

@ -17,31 +17,8 @@ class TabsViewController: BaseViewController<Tabs> {
var borderlineSwitch = Toggle()
var fillContainerSwitch = Toggle()
var sampleSwitch = Toggle()
var widthValueTextField = NumericField()
var widthPercentageTextField = NumericField()
var verticalOrientationFormStackView: UIStackView = {
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] }
var horizontalOrientationFormStackView = FormSection()
lazy var orientationPickerSelectorView = {
PickerSelectorView(title: "",
@ -77,25 +54,20 @@ class TabsViewController: BaseViewController<Tabs> {
override func setupForm(){
super.setupForm()
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: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Size", view: sizePickerSelectorView)
if UIDevice.isIPad {
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
addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch), stackView: horizontalOrientationFormStackView)
addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView, stackView: horizontalOrientationFormStackView)
addFormRow(label: "Overflow", view: overflowPickerSelectorView, stackView: horizontalOrientationFormStackView)
horizontalOrientationFormStackView.addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch))
horizontalOrientationFormStackView.addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView)
horizontalOrientationFormStackView.addFormRow(label: "Overflow", view: overflowPickerSelectorView)
// formStackView.addArrangedSubview(verticalOrientationFormStackView)
formStackView.addArrangedSubview(horizontalOrientationFormStackView)
append(section: horizontalOrientationFormStackView)
disabledSwitch.onChange = { [weak self] sender in
self?.component.disabled = sender.isOn
@ -114,22 +86,6 @@ class TabsViewController: BaseViewController<Tabs> {
self.component.selectedIndex = 0
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] = [
@ -158,7 +114,6 @@ class TabsViewController: BaseViewController<Tabs> {
borderlineSwitch.isOn = component.borderLine
fillContainerSwitch.isOn = component.fillContainer
sampleSwitch.isOn = true
// updateWidth()
}
func setupPicker(){
@ -173,7 +128,6 @@ class TabsViewController: BaseViewController<Tabs> {
orientationPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.orientation = item
self?.verticalOrientationFormStackView.isHidden = item == .horizontal
self?.horizontalOrientationFormStackView.isHidden = item == .vertical
}
@ -185,16 +139,4 @@ class TabsViewController: BaseViewController<Tabs> {
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 showTextSwitch = Toggle()
var textFormStackView: UIStackView = {
return UIStackView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.alignment = .fill
$0.distribution = .fillProportionally
$0.axis = .vertical
$0.spacing = 10
}
}()
var textFormStackView = FormSection()
var boldSwitch = Toggle()
var onTextField = TextField()
@ -59,13 +51,14 @@ class ToggleViewController: BaseViewController<Toggle> {
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
//add the hidden elements to textFormStackView
addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch), stackView: textFormStackView)
addFormRow(label: "Text Size", view: textSizePickerSelectorView, stackView: textFormStackView)
addFormRow(label: "Text Position", view: textPositionPickerSelectorView, stackView: textFormStackView)
addFormRow(label: "On Text", view: onTextField, stackView: textFormStackView)
addFormRow(label: "Off Text", view: offTextField, stackView: textFormStackView)
textFormStackView.addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch))
textFormStackView.addFormRow(label: "Text Size", view: textSizePickerSelectorView)
textFormStackView.addFormRow(label: "Text Position", view: textPositionPickerSelectorView)
textFormStackView.addFormRow(label: "On Text", view: onTextField)
textFormStackView.addFormRow(label: "Off Text", view: offTextField)
//add textFormStackView to main form
formStackView.addArrangedSubview(textFormStackView)
append(section: textFormStackView)
component.onChange = { [weak self] toggle in
let alertController:UIAlertController = UIAlertController(title: "Alert",