added tooltip

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-04-14 15:48:57 -05:00
parent 63964b57e8
commit 68d2a5173e
5 changed files with 482 additions and 3 deletions

View File

@ -4,6 +4,182 @@
<FileRef <FileRef
location = "container:VDSSample.xcodeproj"> location = "container:VDSSample.xcodeproj">
</FileRef> </FileRef>
<Group
location = "group:VDSSample"
name = "VDSSample">
<Group
location = "group:VDSSample/Supporting Files"
name = "Supporting Files">
<Group
location = "group:VDSSample/Supporting Files/Artifactory"
name = "Artifactory">
<FileRef
location = "group:VDSSample/Supporting Files/Artifactory/ArtifactoryItems.txt">
</FileRef>
<FileRef
location = "group:VDSSample/Supporting Files/Artifactory/DownloadArtifactoryItems.sh">
</FileRef>
<FileRef
location = "group:VDSSample/Supporting Files/Artifactory/Artifactory.sh">
</FileRef>
</Group>
<Group
location = "group:VDSSample/Supporting Files/Resources"
name = "Resources">
<FileRef
location = "group:VDSSample/Supporting Files/Resources/Assets.xcassets">
</FileRef>
<Group
location = "group:VDSSample/Supporting Files/Resources"
name = "LaunchScreen.storyboard">
<FileRef
location = "group:VDSSample/Supporting Files/Resources/Base.lproj/LaunchScreen.storyboard">
</FileRef>
</Group>
<Group
location = "group:VDSSample/Supporting Files/Resources"
name = "Main.storyboard">
<FileRef
location = "group:VDSSample/Supporting Files/Resources/Base.lproj/Main.storyboard">
</FileRef>
</Group>
</Group>
</Group>
<Group
location = "group:VDSSample/Extensions"
name = "Extensions">
<FileRef
location = "group:VDSSample/Extensions/IconName.swift">
</FileRef>
</Group>
<Group
location = "group:VDSSample/Protocols"
name = "Protocols">
<FileRef
location = "group:VDSSample/Protocols/PickerBase.swift">
</FileRef>
<FileRef
location = "group:VDSSample/Protocols/StoryboardInitable.swift">
</FileRef>
</Group>
<Group
location = "group:VDSSample/Classes"
name = "Classes">
<FileRef
location = "group:VDSSample/Classes/TextField.swift">
</FileRef>
<FileRef
location = "group:VDSSample/Classes/Helper.swift">
</FileRef>
</Group>
<Group
location = "group:VDSSample/ViewControllers"
name = "ViewControllers">
<Group
location = "group:VDSSample/ViewControllers/ScrollViewController"
name = "ScrollViewController">
<FileRef
location = "group:VDSSample/ViewControllers/ScrollViewController/ScrollViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ScrollViewController/KeyboardFrameChangeListener.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ScrollViewController/ScrollViewKeyboardAvoiding.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ScrollViewController/KeyboardFrameChangeListening.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ScrollViewController/KeyboardFrameChange.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ScrollViewController/ScrollViewKeyboardAvoider.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ScrollViewController/ScrollWrapperView.swift">
</FileRef>
</Group>
<FileRef
location = "group:VDSSample/ViewControllers/MenuViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/BaseViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/BadgeViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ButtonGroupViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ButtonViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/CheckBoxGroupViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/CheckboxViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/IconViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/InputFieldViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/TextLinkViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/LabelViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/LineViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/NotificationViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/RadioBoxGroupViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/RadioButtonViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/RadioSwatchGroupViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/TextAreaViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/TextLinkCaretViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/TileContainerViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/TileletViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/TitleLockupViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/ToggleViewController.swift">
</FileRef>
<FileRef
location = "group:VDSSample/ViewControllers/TooltipViewController.swift">
</FileRef>
</Group>
<FileRef
location = "group:VDSSample/AppDelegate.swift">
</FileRef>
<FileRef
location = "group:VDSSample/SceneDelegate.swift">
</FileRef>
<FileRef
location = "group:VDSSample/Info.plist">
</FileRef>
</Group>
<FileRef <FileRef
location = "group:vds_ios/VDS.xcodeproj"> location = "group:vds_ios/VDS.xcodeproj">
</FileRef> </FileRef>

View File

@ -32,8 +32,8 @@
/* End PBXAggregateTarget section */ /* End PBXAggregateTarget section */
/* Begin PBXBuildFile section */ /* Begin PBXBuildFile section */
44604AD929CE1CF900E62B51 /* LineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD829CE1CF900E62B51 /* LineViewController.swift */; };
445BA07A29C088470036A7C5 /* NotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 445BA07929C088470036A7C5 /* NotificationViewController.swift */; }; 445BA07A29C088470036A7C5 /* NotificationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 445BA07929C088470036A7C5 /* NotificationViewController.swift */; };
44604AD929CE1CF900E62B51 /* LineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 44604AD829CE1CF900E62B51 /* LineViewController.swift */; };
5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */; }; 5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */; };
EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */; }; EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */; };
EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9C289966EF000CA526 /* AppDelegate.swift */; }; EA3C3B9D289966EF000CA526 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA3C3B9C289966EF000CA526 /* AppDelegate.swift */; };
@ -69,6 +69,8 @@
EAA5EEAD28EB6924003B3210 /* InputFieldViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEAC28EB6924003B3210 /* InputFieldViewController.swift */; }; EAA5EEAD28EB6924003B3210 /* InputFieldViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA5EEAC28EB6924003B3210 /* InputFieldViewController.swift */; };
EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */; }; EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */; };
EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */; }; EAB1D2D428AC409F00DAE764 /* LabelViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */; };
EAB2376029E88D5D00AABE9A /* TooltipViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */; };
EAB2376C29E9E74900AABE9A /* TrailingTooltipLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */; };
EAB5FEEF2927E28400998C17 /* ButtonGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */; }; EAB5FEEF2927E28400998C17 /* ButtonGroupViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */; };
EAB5FEF32928153D00998C17 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF22928153D00998C17 /* Helper.swift */; }; EAB5FEF32928153D00998C17 /* Helper.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB5FEF22928153D00998C17 /* Helper.swift */; };
EAC9258029119FC400091998 /* TextLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257F29119FC400091998 /* TextLinkViewController.swift */; }; EAC9258029119FC400091998 /* TextLinkViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAC9257F29119FC400091998 /* TextLinkViewController.swift */; };
@ -115,8 +117,8 @@
/* End PBXCopyFilesBuildPhase section */ /* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */ /* Begin PBXFileReference section */
44604AD829CE1CF900E62B51 /* LineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineViewController.swift; sourceTree = "<group>"; };
445BA07929C088470036A7C5 /* NotificationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewController.swift; sourceTree = "<group>"; }; 445BA07929C088470036A7C5 /* NotificationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationViewController.swift; sourceTree = "<group>"; };
44604AD829CE1CF900E62B51 /* LineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineViewController.swift; sourceTree = "<group>"; };
5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonViewController.swift; sourceTree = "<group>"; }; 5FC35BE828D5235A004EBEAC /* ButtonViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonViewController.swift; sourceTree = "<group>"; };
EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaretViewController.swift; sourceTree = "<group>"; }; EA0FC2C02912DC5500DF80B4 /* TextLinkCaretViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkCaretViewController.swift; sourceTree = "<group>"; };
EA3C3B99289966EF000CA526 /* VDSSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VDSSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; EA3C3B99289966EF000CA526 /* VDSSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = VDSSample.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -153,6 +155,8 @@
EAA5EEAC28EB6924003B3210 /* InputFieldViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputFieldViewController.swift; sourceTree = "<group>"; }; EAA5EEAC28EB6924003B3210 /* InputFieldViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InputFieldViewController.swift; sourceTree = "<group>"; };
EAB1D2C828AAAA1D00DAE764 /* BaseViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseViewController.swift; sourceTree = "<group>"; }; 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>"; }; EAB1D2D328AC409F00DAE764 /* LabelViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelViewController.swift; sourceTree = "<group>"; };
EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipViewController.swift; sourceTree = "<group>"; };
EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailingTooltipLabel.swift; sourceTree = "<group>"; };
EAB5FEEE2927E28400998C17 /* ButtonGroupViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonGroupViewController.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>"; }; 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>"; }; EAC9257F29119FC400091998 /* TextLinkViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextLinkViewController.swift; sourceTree = "<group>"; };
@ -303,6 +307,8 @@
EA5E305B295111050082B959 /* TileletViewController.swift */, EA5E305B295111050082B959 /* TileletViewController.swift */,
EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */, EA5E30542950EA6E0082B959 /* TitleLockupViewController.swift */,
EA3C3BB328996775000CA526 /* ToggleViewController.swift */, EA3C3BB328996775000CA526 /* ToggleViewController.swift */,
EAB2375F29E88D5D00AABE9A /* TooltipViewController.swift */,
EAB2376B29E9E74900AABE9A /* TrailingTooltipLabel.swift */,
); );
path = ViewControllers; path = ViewControllers;
sourceTree = "<group>"; sourceTree = "<group>";
@ -466,11 +472,13 @@
5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */, 5FC35BE928D5235A004EBEAC /* ButtonViewController.swift in Sources */,
EA89204A28B66CE2006B9984 /* KeyboardFrameChange.swift in Sources */, EA89204A28B66CE2006B9984 /* KeyboardFrameChange.swift in Sources */,
EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */, EA3C3BB428996775000CA526 /* PickerBase.swift in Sources */,
EAB2376C29E9E74900AABE9A /* TrailingTooltipLabel.swift in Sources */,
EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */, EAB1D2C928AAAA1D00DAE764 /* BaseViewController.swift in Sources */,
EA5E305C295111050082B959 /* TileletViewController.swift in Sources */, EA5E305C295111050082B959 /* TileletViewController.swift in Sources */,
EAB5FEF32928153D00998C17 /* Helper.swift in Sources */, EAB5FEF32928153D00998C17 /* Helper.swift in Sources */,
EA89204728B66CE2006B9984 /* KeyboardFrameChangeListener.swift in Sources */, EA89204728B66CE2006B9984 /* KeyboardFrameChangeListener.swift in Sources */,
EA4DB30428DCD25B00103EE3 /* BadgeViewController.swift in Sources */, EA4DB30428DCD25B00103EE3 /* BadgeViewController.swift in Sources */,
EAB2376029E88D5D00AABE9A /* TooltipViewController.swift in Sources */,
EA89204828B66CE2006B9984 /* ScrollViewKeyboardAvoiding.swift in Sources */, EA89204828B66CE2006B9984 /* ScrollViewKeyboardAvoiding.swift in Sources */,
EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */, EA0FC2C12912DC5500DF80B4 /* TextLinkCaretViewController.swift in Sources */,
EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */, EAF7F09C2899B92400B287F5 /* CheckboxViewController.swift in Sources */,

View File

@ -90,7 +90,10 @@ class MenuViewController: UITableViewController {
MenuComponent(title: "TileContainer", completed: true, viewController: TileContainerViewController.self), MenuComponent(title: "TileContainer", completed: true, viewController: TileContainerViewController.self),
MenuComponent(title: "Tilelet", completed: false, viewController: TileletViewController.self), MenuComponent(title: "Tilelet", completed: false, viewController: TileletViewController.self),
MenuComponent(title: "TitleLockup", completed: true, viewController: TitleLockupViewController.self), MenuComponent(title: "TitleLockup", completed: true, viewController: TitleLockupViewController.self),
MenuComponent(title: "Toggle", completed: true, viewController: ToggleViewController.self) MenuComponent(title: "Toggle", completed: true, viewController: ToggleViewController.self),
MenuComponent(title: "Tooltip", completed: true, viewController: TooltipViewController.self),
MenuComponent(title: "TrailingTooltipLabel", completed: false, viewController: TrailingTooltipLabelViewController.self),
] ]
override func numberOfSections(in tableView: UITableView) -> Int { override func numberOfSections(in tableView: UITableView) -> Int {

View File

@ -0,0 +1,114 @@
//
// TooltipViewController.swift
// VDSSample
//
// Created by Matt Bruce on 4/13/23.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
import Combine
class TooltipViewController: BaseViewController {
var disabledSwitch = Toggle()
var titleTextField = TextField()
var contentTextField = TextField()
var closeButtonTextField = TextField()
lazy var sizePickerSelectorView = {
PickerSelectorView(title: Tooltip.Size.medium.rawValue,
picker: self.picker,
items: Tooltip.Size.allCases)
}()
lazy var fillColorPickerSelectorView = {
PickerSelectorView(title: Tooltip.FillColor.primary.rawValue,
picker: self.picker,
items: Tooltip.FillColor.allCases)
}()
var tooltip = Tooltip()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: .makeWrapper(for: tooltip))
setupForm()
setupPicker()
setupModel()
}
override func allTextFields() -> [TextField]? { [titleTextField, contentTextField, closeButtonTextField] }
func setupForm(){
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Size", view: sizePickerSelectorView)
addFormRow(label: "FillColor", view: fillColorPickerSelectorView)
addFormRow(label: "Title", view: titleTextField)
addFormRow(label: "Content", view: contentTextField)
addFormRow(label: "Close Button Text", view: closeButtonTextField)
disabledSwitch.onChange = { [weak self] sender in
self?.tooltip.disabled = sender.isOn
}
titleTextField
.textPublisher
.sink { [weak self] text in
self?.tooltip.title = text
}.store(in: &subscribers)
contentTextField
.textPublisher
.sink { [weak self] text in
self?.tooltip.content = text
}.store(in: &subscribers)
closeButtonTextField
.textPublisher
.sink { [weak self] text in
self?.tooltip.closeButtonText = text
}.store(in: &subscribers)
}
func setupModel() {
tooltip.title = "5G Ultra Wideband is available in your area."
tooltip.content = "$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in/promo credit applied over 36 mos.; promo credit ends if eligibility reqs are no longer met; 0% APR. Trade-in conditions apply.$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in."
//setup UI
surfacePickerSelectorView.text = tooltip.surface.rawValue
disabledSwitch.isOn = tooltip.disabled
titleTextField.text = tooltip.title
contentTextField.text = tooltip.content
closeButtonTextField.text = tooltip.closeButtonText
}
//Picker
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tooltip.surface = item
self?.contentTopView.backgroundColor = item.color
}
sizePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tooltip.size = item
}
fillColorPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tooltip.fillColor = item
}
}
}
class TooltipPopup: UIAlertController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
}

View File

@ -0,0 +1,178 @@
//
// TrailingTooltipLabel.swift
// VDSSample
//
// Created by Matt Bruce on 4/14/23.
//
import Foundation
import UIKit
import VDS
import VDSColorTokens
class TrailingTooltipLabelViewController: BaseViewController {
lazy var textSizePickerSelectorView = {
TextSizePickerSelectorView(title: "",
picker: self.picker)
}()
lazy var fontCategoryPickerSelectorView = {
FontCategoryPickerSelectorView(title: "",
picker: self.picker)
}()
lazy var sizePickerSelectorView = {
PickerSelectorView(title: Tooltip.Size.medium.rawValue,
picker: self.picker,
items: Tooltip.Size.allCases)
}()
var boldSwitch = Toggle()
var disabledSwitch = Toggle()
var textField = TextField()
var titleTextField = TextField()
var contentTextField = TextField()
var closeButtonTextField = TextField()
private var isBold: Bool = false
var tooltipLabel = TrailingTooltipLabel()
override func viewDidLoad() {
super.viewDidLoad()
addContentTopView(view: tooltipLabel)
setupForm()
setupPicker()
setupModel()
}
override func allTextFields() -> [TextField]? { [textField, titleTextField, contentTextField, closeButtonTextField] }
func setupForm(){
addFormRow(label: "Disabled", view: .makeWrapper(for: disabledSwitch))
addFormRow(label: "Bold", view: .makeWrapper(for: boldSwitch))
addFormRow(label: "Surface", view: surfacePickerSelectorView)
addFormRow(label: "Font Category", view: fontCategoryPickerSelectorView)
addFormRow(label: "Text Size", view: textSizePickerSelectorView)
addFormRow(label: "Text", view: textField)
addFormRow(label: "Tooltip Size", view: sizePickerSelectorView)
addFormRow(label: "Tooltip Title", view: titleTextField)
addFormRow(label: "Tooltip Content", view: contentTextField)
addFormRow(label: "Tooltip Close Button Text", view: closeButtonTextField)
disabledSwitch.onChange = { [weak self] sender in
self?.tooltipLabel.disabled = sender.isOn
}
boldSwitch
.publisher(for: .valueChanged)
.sink { [weak self] sender in
self?.isBold = sender.isOn
self?.updateLabelStyle()
}.store(in: &subscribers)
textField
.textPublisher
.sink { [weak self] text in
self?.tooltipLabel.labelText = text
}.store(in: &subscribers)
titleTextField
.textPublisher
.sink { [weak self] text in
self?.tooltipLabel.tooltipTitle = text
}.store(in: &subscribers)
contentTextField
.textPublisher
.sink { [weak self] text in
self?.tooltipLabel.tooltipContent = text
}.store(in: &subscribers)
closeButtonTextField
.textPublisher
.sink { [weak self] text in
self?.tooltipLabel.tooltipCloseButtonText = text
}.store(in: &subscribers)
}
func setupModel() {
tooltipLabel.labelText = "Label Component"
tooltipLabel.labelTextStyle = .featureSmall
tooltipLabel.tooltipTitle = "5G Ultra Wideband is available in your area."
tooltipLabel.tooltipContent = "$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in/promo credit applied over 36 mos.; promo credit ends if eligibility reqs are no longer met; 0% APR. Trade-in conditions apply.$799.99 (128 GB only) device payment purchase w/new or upgrade smartphone line on postpaid 5G Unlimited plans only req'd. Less up to $800 trade-in."
//setup UI
surfacePickerSelectorView.text = tooltipLabel.surface.rawValue
disabledSwitch.isOn = tooltipLabel.disabled
boldSwitch.isOn = isBold
textField.text = tooltipLabel.labelText
//set the font
fontCategory = .feature
fontCategoryPickerSelectorView.text = "Feature"
textSize = .small
textSizePickerSelectorView.text = "Small"
//setup UI
surfacePickerSelectorView.text = tooltipLabel.surface.rawValue
disabledSwitch.isOn = tooltipLabel.disabled
titleTextField.text = tooltipLabel.tooltipTitle
contentTextField.text = tooltipLabel.tooltipContent
closeButtonTextField.text = tooltipLabel.tooltipCloseButtonText
}
//Picker
private var fontCategory: TextStyle.FontCategory = .feature {
didSet {
fontCategoryPickerSelectorView.text = fontCategory.rawValue
textSizePickerSelectorView.items = fontCategory.sizes
if textSizePickerSelectorView.items.count > 0 {
textSize = textSizePickerSelectorView.items[0]
} else {
textSize = nil
}
updateLabelStyle()
}
}
private var textSize: TextStyle.FontSize? = .large {
didSet {
textSizePickerSelectorView.text = textSize?.rawValue ?? ""
updateLabelStyle()
}
}
func updateLabelStyle(){
if let style = fontCategory.style(for: textSize, isBold: isBold) {
tooltipLabel.labelTextStyle = style
}
}
func setupPicker(){
surfacePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tooltipLabel.surface = item
self?.contentTopView.backgroundColor = item.color
}
textSizePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.textSize = item
}
fontCategoryPickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.fontCategory = item
}
sizePickerSelectorView.onPickerDidSelect = { [weak self] item in
self?.tooltipLabel.tooltipSize = item
}
}
}