Merge branch 'feature/TabsContainer' into 'develop'

adding Tabs

See merge request BPHV_MIPS/vds_ios_sample!41
This commit is contained in:
Bruce, Matt R 2023-05-25 19:35:33 +00:00
commit 42b346efad
8 changed files with 441 additions and 58 deletions

View File

@ -45,9 +45,11 @@
EA3C3BB628996775000CA526 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB228996775000CA526 /* MenuViewController.swift */; };
EA3C3BB728996775000CA526 /* ToggleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB328996775000CA526 /* ToggleViewController.swift */; };
EA4DB30428DCD25B00103EE3 /* BadgeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB30328DCD25B00103EE3 /* BadgeViewController.swift */; };
EA596ABA2A16B2ED00300C4B /* TabsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA596AB92A16B2ED00300C4B /* TabsViewController.swift */; };
EA5E3050294D11540082B959 /* TileContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5E304F294D11540082B959 /* TileContainerViewController.swift */; };
EA5E30552950EA6E0082B959 /* TitleLockupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */; };
EA5E305C295111050082B959 /* TileletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5E305B295111050082B959 /* TileletViewController.swift */; };
EA5F86CE2A1E863F00BC83E4 /* TabsContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86CD2A1E863F00BC83E4 /* TabsContainerViewController.swift */; };
EA81410E2A0ED8DC004F60D2 /* ButtonIconViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410D2A0ED8DC004F60D2 /* ButtonIconViewController.swift */; };
EA84F76228BE4AE500D67ABC /* RadioSwatchGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */; };
EA89201928B56DF5006B9984 /* RadioBoxGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */; };
@ -133,9 +135,11 @@
EA3C3BB228996775000CA526 /* MenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = "<group>"; };
EA3C3BB328996775000CA526 /* ToggleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToggleViewController.swift; sourceTree = "<group>"; };
EA4DB30328DCD25B00103EE3 /* BadgeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BadgeViewController.swift; sourceTree = "<group>"; };
EA596AB92A16B2ED00300C4B /* TabsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsViewController.swift; sourceTree = "<group>"; };
EA5E304F294D11540082B959 /* TileContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileContainerViewController.swift; sourceTree = "<group>"; };
EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleLockupViewController.swift; sourceTree = "<group>"; };
EA5E305B295111050082B959 /* TileletViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TileletViewController.swift; sourceTree = "<group>"; };
EA5F86CD2A1E863F00BC83E4 /* TabsContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsContainerViewController.swift; sourceTree = "<group>"; };
EA81410D2A0ED8DC004F60D2 /* ButtonIconViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonIconViewController.swift; sourceTree = "<group>"; };
EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioSwatchGroupViewController.swift; sourceTree = "<group>"; };
EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioBoxGroupViewController.swift; sourceTree = "<group>"; };
@ -303,9 +307,11 @@
EA89201828B56DF5006B9984 /* RadioBoxGroupViewController.swift */,
EAF7F11928A14A0E00B287F5 /* RadioButtonViewController.swift */,
EA84F76128BE4AE500D67ABC /* RadioSwatchGroupViewController.swift */,
EA5F86CD2A1E863F00BC83E4 /* TabsContainerViewController.swift */,
EA596AB92A16B2ED00300C4B /* TabsViewController.swift */,
EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */,
EA985C24296E06EA00F2FF2E /* TextAreaViewController.swift */,
EAC9257F29119FC400091998 /* TextLinkViewController.swift */,
EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */,
EA5E304F294D11540082B959 /* TileContainerViewController.swift */,
EA5E305B295111050082B959 /* TileletViewController.swift */,
EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */,
@ -485,12 +491,14 @@
EA89204828B66CE2006B9984 /* ScrollViewKeyboardAvoiding.swift in Sources */,
EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */,
EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */,
EA596ABA2A16B2ED00300C4B /* TabsViewController.swift in Sources */,
EA89204E28B67332006B9984 /* CheckBoxGroupViewController.swift in Sources */,
EAA5EEAD28EB6924003B3210 /* InputFieldViewController.swift in Sources */,
EA985C25296E06EA00F2FF2E /* TextAreaViewController.swift in Sources */,
EA81410E2A0ED8DC004F60D2 /* ButtonIconViewController.swift in Sources */,
EA985C20296DECF600F2FF2E /* IconName.swift in Sources */,
EA89204928B66CE2006B9984 /* KeyboardFrameChangeListening.swift in Sources */,
EA5F86CE2A1E863F00BC83E4 /* TabsContainerViewController.swift in Sources */,
EA985C01296CC21C00F2FF2E /* IconViewController.swift in Sources */,
EAC9258029119FC400091998 /* TextLinkViewController.swift in Sources */,
EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */,
@ -642,8 +650,8 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_TEAM = FCMA4QKS77;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_TEAM = 59V5935DHZ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VDSSample/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
@ -657,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;
@ -672,8 +680,8 @@
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 17;
DEVELOPMENT_TEAM = FCMA4QKS77;
CURRENT_PROJECT_VERSION = 18;
DEVELOPMENT_TEAM = 59V5935DHZ;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = VDSSample/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;

View File

@ -10,7 +10,7 @@ import VDS
import UIKit
extension UIView {
public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0) -> UIView {
public static func makeWrapper(for view: UIView, edgeSpacing: CGFloat = 0.0, isTrailing: Bool = true) -> UIView {
let wrapper = UIView().with {
$0.translatesAutoresizingMaskIntoConstraints = false
}
@ -18,8 +18,14 @@ extension UIView {
view
.pinTop(edgeSpacing)
.pinBottom(edgeSpacing)
.pinLeading(edgeSpacing)
view.trailingAnchor.constraint(lessThanOrEqualTo: wrapper.trailingAnchor).isActive = true
if isTrailing {
view.pinLeading(edgeSpacing)
view.trailingAnchor.constraint(lessThanOrEqualTo: wrapper.trailingAnchor).isActive = true
} else {
view.leadingAnchor.constraint(greaterThanOrEqualTo: wrapper.leadingAnchor).isActive = true
view.pinTrailing(edgeSpacing)
}
return wrapper
}
}

View File

@ -60,6 +60,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
public var items: [EnumType] {
didSet { selectedIndex = 0 }
}
public var onClick: AnyCancellable?
public var onPickerDidSelect: ((EnumType) -> Void)?
public var scrollToBottom: (()->Void)?
public init(title: String, picker: UIPickerView? = nil, items: [EnumType]) {
@ -74,7 +75,7 @@ public class PickerSelectorView<EnumType: RawRepresentable>: UIStackView, Picker
label.text = title
updateSelectedIndex()
addArrangedSubview(label)
addArrangedSubview(button)
addArrangedSubview(.makeWrapper(for: button, isTrailing: false))
button.onClick = { [weak self] _ in
self?.picker?.delegate = self
self?.picker?.dataSource = self

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

@ -63,13 +63,19 @@ class MenuCell: UITableViewCell {
}
}
class MenuViewController: UITableViewController {
class MenuViewController: UITableViewController, TooltipLaunchable {
override func viewDidLoad() {
title = "VDS Sample: Build \(Bundle.main.build ?? "none")"
let tooltip = VDS.Tooltip()
let bundle = VDS.Bundle(for: VDS.Badge.self)
tooltip.title = "Release Notes: \(bundle.build ?? "")"
tooltip.content = bundle.contents("ReleaseNotes")
navigationItem.rightBarButtonItem = UIBarButtonItem(customView: tooltip) // UIBarButtonItem(barButtonSystemItem: .compose, target: self, action: #selector(buildInfoTapped))
super.viewDidLoad()
overrideUserInterfaceStyle = .light
tableView.register(MenuCell.self, forCellReuseIdentifier: "cell")
}
let items: [MenuComponent] = [
MenuComponent(title: "Badge", completed: true, viewController: BadgeViewController.self),
MenuComponent(title: "Button", completed: true, viewController: ButtonViewController.self),
@ -85,6 +91,8 @@ class MenuViewController: UITableViewController {
MenuComponent(title: "RadioBoxGroup", completed: true, viewController: RadioBoxGroupViewController.self),
MenuComponent(title: "RadioButtonGroup", completed: true, viewController: RadioButtonViewController.self),
MenuComponent(title: "RadioSwatchGroup", completed: true, viewController: RadioSwatchGroupViewController.self),
//MenuComponent(title: "TabsContainer", completed: false, viewController: TabsContainerViewController.self),
MenuComponent(title: "Tabs", completed: true, viewController: TabsViewController.self),
MenuComponent(title: "TextArea", completed: false, viewController: TextAreaViewController.self),
MenuComponent(title: "TextLink", completed: true, viewController: TextLinkViewController.self),
MenuComponent(title: "TextLinkCaret", completed: true, viewController: TextLinkCaretViewController.self),
@ -149,3 +157,27 @@ class MenuViewController: UITableViewController {
}
}
}
extension Bundle {
var versionNumber: String? {
infoDictionary?["CFBundleShortVersionString"] as? String
}
var buildNumber: String? {
infoDictionary?["CFBundleVersion"] as? String
}
var build: String? {
guard let versionNumber, let buildNumber else { return nil }
return "\(versionNumber).\(buildNumber)"
}
func contents(_ fileName: String, fileExtension: String = "txt" ) -> String {
guard let fileURL = url(forResource: fileName, withExtension: fileExtension) else { return "none" }
do {
return try String(contentsOf: fileURL)
} catch {
print("error reading releaseNotes")
return "none"
}
}
}

View File

@ -0,0 +1,187 @@
//
// TabViewContainerViewController.swift
// VDSSample
//
// Created by Matt Bruce on 5/24/23.
//
import Foundation
import UIKit
import VDS
import Combine
import VDSColorTokens
class TabsContainerViewController: BaseViewController<TabsContainer> {
var disabledSwitch = Toggle()
var borderlineSwitch = Toggle()
var fillContainerSwitch = Toggle()
var sampleSwitch = Toggle()
var widthValueTextField = NumericField()
var widthPercentageTextField = NumericField()
var verticalOrientationFormStackView = FormSection()
var horizontalOrientationFormStackView = FormSection()
override func allTextFields() -> [TextField]? { [widthValueTextField, widthPercentageTextField] }
lazy var orientationPickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.Orientation.allCases)
}()
lazy var indicatorPositionPickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.IndicatorPosition.allCases)
}()
lazy var sizePickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.Size.allCases)
}()
lazy var overflowPickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.Overflow.allCases)
}()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: component)
setupPicker()
setupModel()
}
override func setupForm(){
super.setupForm()
addFormRow(label: "Large Sample", view: .makeWrapper(for: sampleSwitch))
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
verticalOrientationFormStackView.addFormRow(label: "% Width (0.25 -> 1.0)", view: widthPercentageTextField)
verticalOrientationFormStackView.addFormRow(label: "# Width", view: widthValueTextField)
}
//only in horizontal mode
horizontalOrientationFormStackView.addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch))
horizontalOrientationFormStackView.addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView)
horizontalOrientationFormStackView.addFormRow(label: "Overflow", view: overflowPickerSelectorView)
append(section: verticalOrientationFormStackView)
append(section: horizontalOrientationFormStackView)
disabledSwitch.onChange = { [weak self] sender in
self?.component.disabled = sender.isOn
}
borderlineSwitch.onChange = { [weak self] sender in
self?.component.borderLine = sender.isOn
}
fillContainerSwitch.onChange = { [weak self] sender in
self?.component.fillContainer = sender.isOn
}
sampleSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.component.selectedIndex = 0
self.component.tabModels = sender.isOn ? self.getAllTabs() : self.getSomeTabs()
}
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)
}
func getTabs(texts:[String]) -> [TabsContainer.TabModel] {
texts.compactMap {
let label = Label()
label.text = "This is an example of the \($0) Tab. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
return TabsContainer.TabModel(model: .init(text: $0), view: label)
}
}
func getAllTabs() -> [TabsContainer.TabModel] {
getTabs(texts: ["Accessories", "Internet and TV", "Customer Service", "Contact Us"])
}
func getSomeTabs() -> [TabsContainer.TabModel] {
getTabs(texts: ["Accessories", "Internet and TV"])
}
func setupModel() {
//set to the large sample
component.tabModels = getAllTabs()
//setup UI
surfacePickerSelectorView.text = component.surface.rawValue
sizePickerSelectorView.text = component.size.rawValue
orientationPickerSelectorView.text = component.orientation.rawValue
indicatorPositionPickerSelectorView.text = component.indicatorPosition.rawValue
overflowPickerSelectorView.text = component.overflow.rawValue
disabledSwitch.isOn = component.disabled
borderlineSwitch.isOn = component.borderLine
fillContainerSwitch.isOn = component.fillContainer
sampleSwitch.isOn = true
updateWidth()
}
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.surface = item
self?.contentTopView.backgroundColor = item.color
}
sizePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.size = item
}
orientationPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.orientation = item
self?.verticalOrientationFormStackView.isHidden = item == .horizontal
self?.horizontalOrientationFormStackView.isHidden = item == .vertical
}
indicatorPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.indicatorPosition = item
}
overflowPickerSelectorView.onPickerDidSelect = { [weak self] item in
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

@ -0,0 +1,142 @@
//
// TabsViewController.swift
// VDSSample
//
// Created by Matt Bruce on 5/18/23.
//
import Foundation
import UIKit
import VDS
import Combine
import VDSColorTokens
class TabsViewController: BaseViewController<Tabs> {
var disabledSwitch = Toggle()
var borderlineSwitch = Toggle()
var fillContainerSwitch = Toggle()
var sampleSwitch = Toggle()
var horizontalOrientationFormStackView = FormSection()
lazy var orientationPickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.Orientation.allCases)
}()
lazy var indicatorPositionPickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.IndicatorPosition.allCases)
}()
lazy var sizePickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.Size.allCases)
}()
lazy var overflowPickerSelectorView = {
PickerSelectorView(title: "",
picker: self.picker,
items: Tabs.Overflow.allCases)
}()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: component)
setupPicker()
setupModel()
}
override func setupForm(){
super.setupForm()
addFormRow(label: "Large Sample", view: .makeWrapper(for: sampleSwitch))
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 horizontal mode
horizontalOrientationFormStackView.addFormRow(label: "Fill Container", view: .makeWrapper(for: fillContainerSwitch))
horizontalOrientationFormStackView.addFormRow(label: "Indicator Position", view: indicatorPositionPickerSelectorView)
horizontalOrientationFormStackView.addFormRow(label: "Overflow", view: overflowPickerSelectorView)
append(section: horizontalOrientationFormStackView)
disabledSwitch.onChange = { [weak self] sender in
self?.component.disabled = sender.isOn
}
borderlineSwitch.onChange = { [weak self] sender in
self?.component.borderLine = sender.isOn
}
fillContainerSwitch.onChange = { [weak self] sender in
self?.component.fillContainer = sender.isOn
}
sampleSwitch.onChange = { [weak self] sender in
guard let self else { return }
self.component.selectedIndex = 0
self.component.tabModels = sender.isOn ? self.allTabs : self.some
}
}
var allTabs: [Tabs.TabModel] = [
.init(text: "Accessories"),
.init(text: "Internet and TV"),
.init(text: "Customer Service"),
.init(text: "Contact Us")
]
var some: [Tabs.TabModel] = [
.init(text: "Accessories"),
.init(text: "Internet and TV")
]
func setupModel() {
//set to the large sample
component.tabModels = allTabs
//setup UI
surfacePickerSelectorView.text = component.surface.rawValue
sizePickerSelectorView.text = component.size.rawValue
orientationPickerSelectorView.text = component.orientation.rawValue
indicatorPositionPickerSelectorView.text = component.indicatorPosition.rawValue
overflowPickerSelectorView.text = component.overflow.rawValue
disabledSwitch.isOn = component.disabled
borderlineSwitch.isOn = component.borderLine
fillContainerSwitch.isOn = component.fillContainer
sampleSwitch.isOn = true
}
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.surface = item
self?.contentTopView.backgroundColor = item.color
}
sizePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.size = item
}
orientationPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.orientation = item
self?.horizontalOrientationFormStackView.isHidden = item == .vertical
}
indicatorPositionPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.indicatorPosition = item
}
overflowPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.component.overflow = item
}
}
}

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",