From 26bd70c5e80e247b907e95d0451b8ae1b49d3b22 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 18 Nov 2022 14:26:15 -0600 Subject: [PATCH] fixed bug, refactored code Signed-off-by: Matt Bruce --- VDSSample.xcodeproj/project.pbxproj | 4 ++ VDSSample/Classes/Helper.swift | 72 +++++++++++++++++++ .../ViewControllers/BaseViewController.swift | 15 ---- .../ButtonGroupViewController.swift | 25 ++----- .../ButtonViewController.swift | 2 +- .../TextLinkCaretViewController.swift | 17 +---- .../TextLinkViewController.swift | 17 +---- 7 files changed, 88 insertions(+), 64 deletions(-) create mode 100644 VDSSample/Classes/Helper.swift diff --git a/VDSSample.xcodeproj/project.pbxproj b/VDSSample.xcodeproj/project.pbxproj index ffa5ef5..551c160 100644 --- a/VDSSample.xcodeproj/project.pbxproj +++ b/VDSSample.xcodeproj/project.pbxproj @@ -60,6 +60,7 @@ EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */; }; EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */; }; EAB5FEEF2927E28400998C17 /* ButtonGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */; }; + EAB5FEF32928153D00998C17 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF22928153D00998C17 /* Helper.swift */; }; EAC9258029119FC400091998 /* TextLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257F29119FC400091998 /* TextLinkViewController.swift */; }; EAF7F07D2899698800B287F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAF7F07B2899698800B287F5 /* Assets.xcassets */; }; EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */; }; @@ -122,6 +123,7 @@ EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = ""; }; EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelViewController.swift; sourceTree = ""; }; EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonGroupViewController.swift; sourceTree = ""; }; + EAB5FEF22928153D00998C17 /* Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helper.swift; sourceTree = ""; }; EAC9257F29119FC400091998 /* TextLinkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkViewController.swift; sourceTree = ""; }; EAF7F07B2899698800B287F5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxViewController.swift; sourceTree = ""; }; @@ -209,6 +211,7 @@ isa = PBXGroup; children = ( EA89205028B68307006B9984 /* TextField.swift */, + EAB5FEF22928153D00998C17 /* Helper.swift */, ); path = Classes; sourceTree = ""; @@ -409,6 +412,7 @@ EA89204A28B66CE2006B9984 /* KeyboardFrameChange.swift in Sources */, EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */, EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */, + EAB5FEF32928153D00998C17 /* Helper.swift in Sources */, EA89204728B66CE2006B9984 /* KeyboardFrameChangeListener.swift in Sources */, EA4DB30428DCD25B00103EE3 /* BadgeViewController.swift in Sources */, EA89204828B66CE2006B9984 /* ScrollViewKeyboardAvoiding.swift in Sources */, diff --git a/VDSSample/Classes/Helper.swift b/VDSSample/Classes/Helper.swift new file mode 100644 index 0000000..05ba8b0 --- /dev/null +++ b/VDSSample/Classes/Helper.swift @@ -0,0 +1,72 @@ +// +// Helper.swift +// VDSSample +// +// Created by Matt Bruce on 11/18/22. +// + +import Foundation +import VDS +import UIKit + +extension UIView { + public static func makeWrapper(for view: UIView) -> UIView { + let wrapper = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } + wrapper.addSubview(view) + view + .pinTop() + .pinBottom() + .pinLeading() + view.trailingAnchor.constraint(lessThanOrEqualTo: wrapper.trailingAnchor).isActive = true + return wrapper + } +} + +extension BaseViewController { + func makeButton(_ text: String) -> Button { + return Button().with{ + $0.text = text + $0.publisher(for: .touchUpInside) + .sink { [weak self] control in + let alertController:UIAlertController = UIAlertController(title: "Alert", + message: "\(control.text!) Clicked", + preferredStyle: UIAlertController.Style.alert) + alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) + self?.present(alertController, animated: true) + print("clicked me") + }.store(in: &subscribers) + } + } + + func makeTextLink(_ text: String) -> TextLink { + return TextLink().with{ + $0.text = text + $0.publisher(for: .touchUpInside) + .sink { [weak self] control in + let alertController:UIAlertController = UIAlertController(title: "Alert", + message: "\(control.text!) Clicked", + preferredStyle: UIAlertController.Style.alert) + alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) + self?.present(alertController, animated: true) + print("clicked me") + }.store(in: &subscribers) + } + } + + func makeTextLinkCaret(_ text: String) -> TextLinkCaret { + return TextLinkCaret().with{ + $0.text = text + $0.publisher(for: .touchUpInside) + .sink { [weak self] control in + let alertController:UIAlertController = UIAlertController(title: "Alert", + message: "\(control.text!) Clicked", + preferredStyle: UIAlertController.Style.alert) + alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) + self?.present(alertController, animated: true) + print("clicked me") + }.store(in: &subscribers) + } + } +} diff --git a/VDSSample/ViewControllers/BaseViewController.swift b/VDSSample/ViewControllers/BaseViewController.swift index 9e2a937..ea04a4e 100644 --- a/VDSSample/ViewControllers/BaseViewController.swift +++ b/VDSSample/ViewControllers/BaseViewController.swift @@ -10,21 +10,6 @@ import UIKit import Combine import VDS -extension UIView { - public static func makeWrapper(for view: UIView) -> UIView { - let wrapper = UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - wrapper.addSubview(view) - view - .pinTop() - .pinBottom() - .pinLeading() - view.trailingAnchor.constraint(lessThanOrEqualTo: wrapper.trailingAnchor).isActive = true - return wrapper - } -} - public class BaseViewController: UIViewController, Initable { deinit { print("\(Self.self) deinit") diff --git a/VDSSample/ViewControllers/ButtonGroupViewController.swift b/VDSSample/ViewControllers/ButtonGroupViewController.swift index a580d31..04ce51c 100644 --- a/VDSSample/ViewControllers/ButtonGroupViewController.swift +++ b/VDSSample/ViewControllers/ButtonGroupViewController.swift @@ -23,15 +23,14 @@ class ButtonGroupViewController: BaseViewController { var widthTextField = TextField() let buttonGroup = ButtonGroup() - let button = Button() override func viewDidLoad() { super.viewDidLoad() buttonGroup.buttons = [ - button, - Button().with{$0.text = "Wide Label Button"}, - TextLink().with{$0.text = "Text Link Button"}, - TextLinkCaret().with{$0.text = "Caret Button"} + makeButton("Button"), + makeButton("Widge Label Button"), + makeTextLink("Text Link Button"), + makeTextLinkCaret("Caret Button") ] addContentTopView(view: buttonGroup) @@ -64,22 +63,8 @@ class ButtonGroupViewController: BaseViewController { // }.store(in: &subscribers) } - + func setupModel() { - button.text = "Button" - - button - .publisher(for: .touchUpInside) - .sink { [weak self] control in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "\(control.text!) Clicked", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) - print("clicked me") - }.store(in: &subscribers) - - //setup UI surfacePickerSelectorView.text = buttonGroup.surface.rawValue buttonPositionSelectorView.text = buttonGroup.buttonPosition.rawValue diff --git a/VDSSample/ViewControllers/ButtonViewController.swift b/VDSSample/ViewControllers/ButtonViewController.swift index cccc306..4d02c49 100644 --- a/VDSSample/ViewControllers/ButtonViewController.swift +++ b/VDSSample/ViewControllers/ButtonViewController.swift @@ -24,7 +24,7 @@ class ButtonViewController: BaseViewController { items: ButtonSize.allCases) }() - var disabledSwitch = Toggle() + var disabledSwitch = UISwitch() var textField = TextField() var widthTextField = TextField() diff --git a/VDSSample/ViewControllers/TextLinkCaretViewController.swift b/VDSSample/ViewControllers/TextLinkCaretViewController.swift index a0af2ce..fc00b20 100644 --- a/VDSSample/ViewControllers/TextLinkCaretViewController.swift +++ b/VDSSample/ViewControllers/TextLinkCaretViewController.swift @@ -20,7 +20,9 @@ class TextLinkCaretViewController: BaseViewController { var disabledSwitch = UISwitch() var textField = TextField() - let textLinkCaret = TextLinkCaret() + lazy var textLinkCaret: TextLinkCaret = { + makeTextLinkCaret("Text Link Caret") + }() override func viewDidLoad() { super.viewDidLoad() @@ -51,19 +53,6 @@ class TextLinkCaretViewController: BaseViewController { } func setupModel() { - textLinkCaret.text = "Text Link" - - textLinkCaret - .publisher(for: .touchUpInside) - .sink { [weak self] control in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "\(control.text!) Clicked", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) - print("clicked me") - }.store(in: &subscribers) - //setup UI surfacePickerSelectorView.text = textLinkCaret.surface.rawValue diff --git a/VDSSample/ViewControllers/TextLinkViewController.swift b/VDSSample/ViewControllers/TextLinkViewController.swift index 3fefeb6..04c70d9 100644 --- a/VDSSample/ViewControllers/TextLinkViewController.swift +++ b/VDSSample/ViewControllers/TextLinkViewController.swift @@ -20,7 +20,9 @@ class TextLinkViewController: BaseViewController { var disabledSwitch = UISwitch() var textField = TextField() - let textLink = TextLink() + lazy var textLink: TextLink = { + makeTextLink("Text Link") + }() override func viewDidLoad() { super.viewDidLoad() @@ -52,19 +54,6 @@ class TextLinkViewController: BaseViewController { } func setupModel() { - textLink.text = "Text Link" - - textLink - .publisher(for: .touchUpInside) - .sink { [weak self] control in - let alertController:UIAlertController = UIAlertController(title: "Alert", - message: "\(control.text!) Clicked", - preferredStyle: UIAlertController.Style.alert) - alertController.addAction(UIAlertAction(title: "OK", style: UIAlertAction.Style.default, handler:nil)) - self?.present(alertController, animated: true) - print("clicked me") - }.store(in: &subscribers) - //setup UI surfacePickerSelectorView.text = textLink.surface.rawValue