initial commit

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-08-02 09:16:07 -05:00
parent 1089246b90
commit e450f04629
8 changed files with 401 additions and 38 deletions

View File

@ -9,21 +9,56 @@
/* Begin PBXBuildFile section */
EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9C289966EF000CA526 /* AppDelegate.swift */; };
EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */; };
EA3C3BA1289966EF000CA526 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BA0289966EF000CA526 /* ViewController.swift */; };
EA3C3BA4289966EF000CA526 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EA3C3BA2289966EF000CA526 /* Main.storyboard */; };
EA3C3BA6289966F1000CA526 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EA3C3BA5289966F1000CA526 /* Assets.xcassets */; };
EA3C3BA9289966F1000CA526 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = EA3C3BA7289966F1000CA526 /* LaunchScreen.storyboard */; };
EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB028996775000CA526 /* PickerBase.swift */; };
EA3C3BB528996775000CA526 /* StoryboardInitable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB128996775000CA526 /* StoryboardInitable.swift */; };
EA3C3BB628996775000CA526 /* MenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB228996775000CA526 /* MenuViewController.swift */; };
EA3C3BB728996775000CA526 /* ToggleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3BB328996775000CA526 /* ToggleViewController.swift */; };
EA3C3BBC289968A0000CA526 /* VDSColorTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BB9289968A0000CA526 /* VDSColorTokens.xcframework */; };
EA3C3BBD289968A0000CA526 /* VDSColorTokens.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BB9289968A0000CA526 /* VDSColorTokens.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
EA3C3BBE289968A0000CA526 /* VDSTypographyTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BBA289968A0000CA526 /* VDSTypographyTokens.xcframework */; };
EA3C3BBF289968A0000CA526 /* VDSTypographyTokens.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BBA289968A0000CA526 /* VDSTypographyTokens.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
EA3C3BC0289968A0000CA526 /* VDSFormControlsTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BBB289968A0000CA526 /* VDSFormControlsTokens.xcframework */; };
EA3C3BC1289968A0000CA526 /* VDSFormControlsTokens.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BBB289968A0000CA526 /* VDSFormControlsTokens.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
EA3C3BC4289968B1000CA526 /* VDS.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BC3289968B1000CA526 /* VDS.framework */; };
EA3C3BC5289968B1000CA526 /* VDS.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EA3C3BC3289968B1000CA526 /* VDS.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
EA3C3BC2289968A0000CA526 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
EA3C3BC1289968A0000CA526 /* VDSFormControlsTokens.xcframework in Embed Frameworks */,
EA3C3BBF289968A0000CA526 /* VDSTypographyTokens.xcframework in Embed Frameworks */,
EA3C3BC5289968B1000CA526 /* VDS.framework in Embed Frameworks */,
EA3C3BBD289968A0000CA526 /* VDSColorTokens.xcframework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
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>"; };
EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
EA3C3BA0289966EF000CA526 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
EA3C3BA3289966EF000CA526 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
EA3C3BA5289966F1000CA526 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
EA3C3BA8289966F1000CA526 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
EA3C3BAA289966F1000CA526 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
EA3C3BB028996775000CA526 /* PickerBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PickerBase.swift; sourceTree = "<group>"; };
EA3C3BB128996775000CA526 /* StoryboardInitable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardInitable.swift; sourceTree = "<group>"; };
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>"; };
EA3C3BB9289968A0000CA526 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = ../SharedFrameworks/VDSColorTokens.xcframework; sourceTree = "<group>"; };
EA3C3BBA289968A0000CA526 /* VDSTypographyTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSTypographyTokens.xcframework; path = ../SharedFrameworks/VDSTypographyTokens.xcframework; sourceTree = "<group>"; };
EA3C3BBB289968A0000CA526 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = ../SharedFrameworks/VDSFormControlsTokens.xcframework; sourceTree = "<group>"; };
EA3C3BC3289968B1000CA526 /* VDS.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = VDS.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@ -31,6 +66,10 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
EA3C3BC0289968A0000CA526 /* VDSFormControlsTokens.xcframework in Frameworks */,
EA3C3BBE289968A0000CA526 /* VDSTypographyTokens.xcframework in Frameworks */,
EA3C3BC4289968B1000CA526 /* VDS.framework in Frameworks */,
EA3C3BBC289968A0000CA526 /* VDSColorTokens.xcframework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -42,6 +81,7 @@
children = (
EA3C3B9B289966EF000CA526 /* VDSSample */,
EA3C3B9A289966EF000CA526 /* Products */,
EA3C3BB8289968A0000CA526 /* Frameworks */,
);
sourceTree = "<group>";
};
@ -56,9 +96,12 @@
EA3C3B9B289966EF000CA526 /* VDSSample */ = {
isa = PBXGroup;
children = (
EA3C3BB228996775000CA526 /* MenuViewController.swift */,
EA3C3BB028996775000CA526 /* PickerBase.swift */,
EA3C3BB128996775000CA526 /* StoryboardInitable.swift */,
EA3C3BB328996775000CA526 /* ToggleViewController.swift */,
EA3C3B9C289966EF000CA526 /* AppDelegate.swift */,
EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */,
EA3C3BA0289966EF000CA526 /* ViewController.swift */,
EA3C3BA2289966EF000CA526 /* Main.storyboard */,
EA3C3BA5289966F1000CA526 /* Assets.xcassets */,
EA3C3BA7289966F1000CA526 /* LaunchScreen.storyboard */,
@ -67,6 +110,17 @@
path = VDSSample;
sourceTree = "<group>";
};
EA3C3BB8289968A0000CA526 /* Frameworks */ = {
isa = PBXGroup;
children = (
EA3C3BC3289968B1000CA526 /* VDS.framework */,
EA3C3BB9289968A0000CA526 /* VDSColorTokens.xcframework */,
EA3C3BBB289968A0000CA526 /* VDSFormControlsTokens.xcframework */,
EA3C3BBA289968A0000CA526 /* VDSTypographyTokens.xcframework */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -77,6 +131,7 @@
EA3C3B95289966EF000CA526 /* Sources */,
EA3C3B96289966EF000CA526 /* Frameworks */,
EA3C3B97289966EF000CA526 /* Resources */,
EA3C3BC2289968A0000CA526 /* Embed Frameworks */,
);
buildRules = (
);
@ -138,9 +193,12 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
EA3C3BA1289966EF000CA526 /* ViewController.swift in Sources */,
EA3C3BB728996775000CA526 /* ToggleViewController.swift in Sources */,
EA3C3BB528996775000CA526 /* StoryboardInitable.swift in Sources */,
EA3C3BB628996775000CA526 /* MenuViewController.swift in Sources */,
EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */,
EA3C3B9F289966EF000CA526 /* SceneDelegate.swift in Sources */,
EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@ -295,6 +353,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
@ -323,6 +382,7 @@
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",

View File

@ -7,7 +7,7 @@
<key>VDSSample.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>6</integer>
</dict>
</dict>
</dict>

View File

@ -1,24 +1,72 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="IOo-c1-iSM">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
<scene sceneID="tne-QT-ifu">
<!--Navigation Controller-->
<scene sceneID="qnv-IY-Oai">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
<navigationController automaticallyAdjustsScrollViewInsets="NO" id="IOo-c1-iSM" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="PHn-rK-60b">
<rect key="frame" x="0.0" y="44" width="414" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
<connections>
<segue destination="COS-ke-xox" kind="relationship" relationship="rootViewController" id="Kvv-gn-Wvl"/>
</connections>
</navigationController>
<placeholder placeholderIdentifier="IBFirstResponder" id="w2a-kW-azo" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-2357" y="-572"/>
</scene>
<!--VDS Controls-->
<scene sceneID="uJd-Mh-6d7">
<objects>
<tableViewController id="COS-ke-xox" customClass="MenuViewController" customModule="VDSSample" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="2Ci-pz-hlP">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" reuseIdentifier="cell" textLabel="IUG-CW-6ON" style="IBUITableViewCellStyleDefault" id="1RT-mx-PaP">
<rect key="frame" x="0.0" y="44.5" width="414" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="1RT-mx-PaP" id="jMm-oH-21o">
<rect key="frame" x="0.0" y="0.0" width="385.5" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="IUG-CW-6ON">
<rect key="frame" x="20" y="0.0" width="357.5" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="0.0"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
</subviews>
</tableViewCellContentView>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="COS-ke-xox" id="uRU-Qn-p3g"/>
<outlet property="delegate" destination="COS-ke-xox" id="Hfp-uJ-fdZ"/>
</connections>
</tableView>
<navigationItem key="navigationItem" title="VDS Controls" id="UYX-bh-22O"/>
</tableViewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="UYG-OL-LTY" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-1504" y="-728"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>

View File

@ -0,0 +1,56 @@
//
// MenuViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/1/22.
//
import Foundation
import UIKit
struct MenuComponent {
var title: String
var viewController: UIViewController.Type
}
class MenuViewController: UITableViewController {
let items: [MenuComponent] = [MenuComponent(title: "Toggle", viewController: ToggleViewController.self)]
override func numberOfSections(in tableView: UITableView) -> Int {
1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
items.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
guard items.count > indexPath.row else { return UITableViewCell() }
let item = items[indexPath.row]
cell.textLabel?.text = item.title
cell.accessoryType = .disclosureIndicator
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard items.count > indexPath.row else { return }
let item = items[indexPath.row]
if let split = splitViewController {
if let type = item.viewController as? StoryboardInitable.Type {
let viewController = type.instantiate()
viewController.title = item.title
split.showDetailViewController(viewController, sender: nil)
}
} else {
if let type = item.viewController as? StoryboardInitable.Type {
let viewController = type.instantiate()
viewController.title = item.title
self.navigationController?.pushViewController(viewController, animated: true)
}
}
}
}

View File

@ -0,0 +1,68 @@
//
// PickerBase.swift
// VDSSample
//
// Created by Matt Bruce on 8/1/22.
//
import Foundation
import UIKit
import VDS
protocol PickerViewable {
associatedtype EnumType: RawRepresentable
var items: [EnumType] { get set }
var onPickerDidSelect: ((EnumType) -> Void)? { get set }
}
class PickerBase<EnumType: RawRepresentable>: NSObject, PickerViewable, UIPickerViewDataSource, UIPickerViewDelegate {
var items: [EnumType]
var onPickerDidSelect: ((EnumType) -> Void)?
init(items: [EnumType]) {
self.items = items
super.init()
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
items.count + 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int ) -> String? {
guard row > 0, let item = items[row-1].rawValue as? String else { return "" }
return item
}
func pickerView( _ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
onPickerDidSelect?(items[row-1])
pickerView.isHidden = true
}
}
class SurfacePicker: PickerBase<Surface> {
init(){
super.init(items: [.light, .dark])
}
}
class TextPositionPicker: PickerBase<VDSTextPosition> {
init(){
super.init(items: [.left, .right])
}
}
class TextSizePicker: PickerBase<VDSFontSize> {
init(){
super.init(items: [.small, .large])
}
}
class FontWeightPicker: PickerBase<VDSFontWeight> {
init(){
super.init(items: [.regular, .bold])
}
}

View File

@ -0,0 +1,19 @@
//
// StoryboardInitable.swift
// VDSSample
//
// Created by Matt Bruce on 8/2/22.
//
import Foundation
import UIKit
protocol StoryboardInitable {
static var storyboardId: String { get }
}
extension StoryboardInitable {
static func instantiate() -> UIViewController {
return UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: Self.storyboardId)
}
}

View File

@ -0,0 +1,131 @@
//
// ToggleViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/1/22.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
class ToggleViewController: UIViewController, StoryboardInitable {
enum PickerType {
case surface, textSize, textPosition, fontWeight
}
static var storyboardId: String = "toggle"
@IBOutlet weak var toggleContainerView: UIView!
@IBOutlet weak var picker: UIPickerView!
@IBOutlet weak var surfaceLabel: UILabel!
@IBOutlet weak var textSizeLabel: UILabel!
@IBOutlet weak var textPositionLabel: UILabel!
@IBOutlet weak var fontWeightLabel: UILabel!
@IBOutlet weak var showTextStack: UIStackView!
var toggle: VDSToggle!
override func viewDidLoad() {
super.viewDidLoad()
toggle = VDSToggle()
toggle.translatesAutoresizingMaskIntoConstraints = false
toggleContainerView.addSubview(toggle)
toggle.leadingAnchor.constraint(equalTo: toggleContainerView.leadingAnchor, constant: 20).isActive = true
toggle.bottomAnchor.constraint(equalTo: toggleContainerView.bottomAnchor, constant: -20).isActive = true
toggle.topAnchor.constraint(equalTo: toggleContainerView.topAnchor, constant: 20).isActive = true
showTextStack.isHidden = true
view.addGestureRecognizer(UITapGestureRecognizer(target: self.view, action: #selector(UIView.endEditing(_:))))
setupPicker()
}
@IBAction func showTextChanged(_ sender: UISwitch) {
toggle.showText = sender.isOn
showTextStack.isHidden = !sender.isOn
}
@IBAction func disabledChanged(_ sender: UISwitch) {
toggle.disabled = sender.isOn
}
@IBAction func offTextDidEnd(_ sender: UITextField) {
toggle.offText = sender.text ?? "Off"
sender.resignFirstResponder()
}
@IBAction func onTextDidEnd(_ sender: UITextField) {
toggle.onText = sender.text ?? "On"
sender.resignFirstResponder()
}
@IBAction func surfaceClick(_ sender: Any) {
pickerType = .surface
}
@IBAction func textSizeClick(_ sender: Any) {
pickerType = .textSize
}
@IBAction func textPositionClick(_ sender: Any) {
pickerType = .textPosition
}
@IBAction func fontWeightClick(_ sender: Any) {
pickerType = .fontWeight
}
//Picker
var surfacePicker = SurfacePicker()
var textSizePicker = TextSizePicker()
var textPositionPicker = TextPositionPicker()
var fontWeightPicker = FontWeightPicker()
var pickerType: PickerType = .surface {
didSet {
func update(object: UIPickerViewDelegate & UIPickerViewDataSource){
picker.delegate = object
picker.dataSource = object
}
switch pickerType{
case .surface:
update(object: surfacePicker)
case .textSize:
update(object: textSizePicker)
case .textPosition:
update(object: textPositionPicker)
case .fontWeight:
update(object: fontWeightPicker)
}
picker.reloadAllComponents()
picker.selectRow(0, inComponent: 0, animated: false)
picker.isHidden = false
}
}
func setupPicker(){
picker.isHidden = true
surfacePicker.onPickerDidSelect = { item in
self.toggle.surface = item
self.toggleContainerView.backgroundColor = item.color
self.surfaceLabel.text = item.rawValue
}
fontWeightPicker.onPickerDidSelect = { item in
self.toggle.fontWeight = item
self.fontWeightLabel.text = item.rawValue
}
textSizePicker.onPickerDidSelect = { item in
self.toggle.fontSize = item
self.textSizeLabel.text = item.rawValue
}
textPositionPicker.onPickerDidSelect = { item in
self.toggle.textPosition = item
self.textPositionLabel.text = item.rawValue
}
}
}

View File

@ -1,19 +0,0 @@
//
// ViewController.swift
// VDSSample
//
// Created by Matt Bruce on 8/2/22.
//
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}