diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index a9a5e91..6817376 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -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 = ""; }; EA3C3B9E289966EF000CA526 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; - EA3C3BA0289966EF000CA526 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; EA3C3BA3289966EF000CA526 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; EA3C3BA5289966F1000CA526 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; EA3C3BA8289966F1000CA526 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; EA3C3BAA289966F1000CA526 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + EA3C3BB028996775000CA526 /* PickerBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PickerBase.swift; sourceTree = ""; }; + EA3C3BB128996775000CA526 /* StoryboardInitable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StoryboardInitable.swift; sourceTree = ""; }; + EA3C3BB228996775000CA526 /* MenuViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MenuViewController.swift; sourceTree = ""; }; + EA3C3BB328996775000CA526 /* ToggleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToggleViewController.swift; sourceTree = ""; }; + EA3C3BB9289968A0000CA526 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = ../SharedFrameworks/VDSColorTokens.xcframework; sourceTree = ""; }; + EA3C3BBA289968A0000CA526 /* VDSTypographyTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSTypographyTokens.xcframework; path = ../SharedFrameworks/VDSTypographyTokens.xcframework; sourceTree = ""; }; + EA3C3BBB289968A0000CA526 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = ../SharedFrameworks/VDSFormControlsTokens.xcframework; sourceTree = ""; }; + 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 = ""; }; @@ -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 = ""; }; + EA3C3BB8289968A0000CA526 /* Frameworks */ = { + isa = PBXGroup; + children = ( + EA3C3BC3289968B1000CA526 /* VDS.framework */, + EA3C3BB9289968A0000CA526 /* VDSColorTokens.xcframework */, + EA3C3BBB289968A0000CA526 /* VDSFormControlsTokens.xcframework */, + EA3C3BBA289968A0000CA526 /* VDSTypographyTokens.xcframework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* 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", diff --git a/VDSSample.xcodeproj/xcuserdata/mattbruce.xcuserdatad/xcschemes/xcschememanagement.plist b/VDSSample.xcodeproj/xcuserdata/mattbruce.xcuserdatad/xcschemes/xcschememanagement.plist index 688b086..7d6fb99 100644 --- a/VDSSample.xcodeproj/xcuserdata/mattbruce.xcuserdatad/xcschemes/xcschememanagement.plist +++ b/VDSSample.xcodeproj/xcuserdata/mattbruce.xcuserdatad/xcschemes/xcschememanagement.plist @@ -7,7 +7,7 @@ VDSSample.xcscheme_^#shared#^_ orderHint - 0 + 6 diff --git a/VDSSample/Base.lproj/Main.storyboard b/VDSSample/Base.lproj/Main.storyboard index 25a7638..556b010 100644 --- a/VDSSample/Base.lproj/Main.storyboard +++ b/VDSSample/Base.lproj/Main.storyboard @@ -1,24 +1,72 @@ - + + - - + + - - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/VDSSample/MenuViewController.swift b/VDSSample/MenuViewController.swift new file mode 100644 index 0000000..e7a2253 --- /dev/null +++ b/VDSSample/MenuViewController.swift @@ -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) + } + + } + } +} diff --git a/VDSSample/PickerBase.swift b/VDSSample/PickerBase.swift new file mode 100644 index 0000000..e92ee64 --- /dev/null +++ b/VDSSample/PickerBase.swift @@ -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: 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 { + init(){ + super.init(items: [.light, .dark]) + } +} + +class TextPositionPicker: PickerBase { + init(){ + super.init(items: [.left, .right]) + } +} + +class TextSizePicker: PickerBase { + init(){ + super.init(items: [.small, .large]) + } +} + +class FontWeightPicker: PickerBase { + init(){ + super.init(items: [.regular, .bold]) + } +} diff --git a/VDSSample/StoryboardInitable.swift b/VDSSample/StoryboardInitable.swift new file mode 100644 index 0000000..0d1468f --- /dev/null +++ b/VDSSample/StoryboardInitable.swift @@ -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) + } +} diff --git a/VDSSample/ToggleViewController.swift b/VDSSample/ToggleViewController.swift new file mode 100644 index 0000000..cb6849f --- /dev/null +++ b/VDSSample/ToggleViewController.swift @@ -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 + } + } +} diff --git a/VDSSample/ViewController.swift b/VDSSample/ViewController.swift deleted file mode 100644 index 0b5cf89..0000000 --- a/VDSSample/ViewController.swift +++ /dev/null @@ -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. - } - - -} -