fixed bug, refactored code

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2022-11-18 14:26:15 -06:00
parent 4269ded448
commit 26bd70c5e8
7 changed files with 88 additions and 64 deletions

View File

@ -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 = "<group>"; };
EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelViewController.swift; sourceTree = "<group>"; };
EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonGroupViewController.swift; sourceTree = "<group>"; };
EAB5FEF22928153D00998C17 /* Helper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helper.swift; sourceTree = "<group>"; };
EAC9257F29119FC400091998 /* TextLinkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkViewController.swift; sourceTree = "<group>"; };
EAF7F07B2899698800B287F5 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
EAF7F09B2899B92400B287F5 /* CheckboxViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckboxViewController.swift; sourceTree = "<group>"; };
@ -209,6 +211,7 @@
isa = PBXGroup;
children = (
EA89205028B68307006B9984 /* TextField.swift */,
EAB5FEF22928153D00998C17 /* Helper.swift */,
);
path = Classes;
sourceTree = "<group>";
@ -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 */,

View File

@ -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)
}
}
}

View File

@ -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")

View File

@ -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

View File

@ -24,7 +24,7 @@ class ButtonViewController: BaseViewController {
items: ButtonSize.allCases)
}()
var disabledSwitch = Toggle()
var disabledSwitch = UISwitch()
var textField = TextField()
var widthTextField = TextField()

View File

@ -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

View File

@ -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