Compare commits

...

3 Commits

Author SHA1 Message Date
Matt Bruce
123831adf6 refactored tooltip away from contentText & contentView to child: Any? and children: View
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-07-25 10:13:16 -05:00
Matt Bruce
827269bb6d put into files
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-07-25 10:12:42 -05:00
Matt Bruce
b74a338b0f merged develop
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
2023-07-25 10:12:34 -05:00
10 changed files with 182 additions and 99 deletions

View File

@ -62,6 +62,8 @@
EA5F86C82A1BD99100BC83E4 /* TabModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86C72A1BD99100BC83E4 /* TabModel.swift */; };
EA5F86CC2A1D28B500BC83E4 /* ReleaseNotes.txt in Resources */ = {isa = PBXBuildFile; fileRef = EA5F86CB2A1D28B500BC83E4 /* ReleaseNotes.txt */; };
EA5F86D02A1F936100BC83E4 /* TabsContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86CF2A1F936100BC83E4 /* TabsContainer.swift */; };
EA7B311D2A7018B600329654 /* TooltipModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7B311C2A7018B600329654 /* TooltipModel.swift */; };
EA7B311F2A701AE400329654 /* Children.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7B311E2A701AE400329654 /* Children.swift */; };
EA81410B2A0E8E3C004F60D2 /* ButtonIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410A2A0E8E3C004F60D2 /* ButtonIcon.swift */; };
EA8141102A127066004F60D2 /* UIColor+VDSColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */; };
EA89200428AECF4B006B9984 /* UITextField+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA89200328AECF4B006B9984 /* UITextField+Publisher.swift */; };
@ -207,6 +209,8 @@
EA5F86C72A1BD99100BC83E4 /* TabModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabModel.swift; sourceTree = "<group>"; };
EA5F86CB2A1D28B500BC83E4 /* ReleaseNotes.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = ReleaseNotes.txt; sourceTree = "<group>"; };
EA5F86CF2A1F936100BC83E4 /* TabsContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabsContainer.swift; sourceTree = "<group>"; };
EA7B311C2A7018B600329654 /* TooltipModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipModel.swift; sourceTree = "<group>"; };
EA7B311E2A701AE400329654 /* Children.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Children.swift; sourceTree = "<group>"; };
EA81410A2A0E8E3C004F60D2 /* ButtonIcon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ButtonIcon.swift; sourceTree = "<group>"; };
EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+VDSColor.swift"; sourceTree = "<group>"; };
EA89200328AECF4B006B9984 /* UITextField+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Publisher.swift"; sourceTree = "<group>"; };
@ -503,6 +507,7 @@
isa = PBXGroup;
children = (
EA985C1C296CD13600F2FF2E /* BundleManager.swift */,
EA7B311E2A701AE400329654 /* Children.swift */,
EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */,
EA3361B5288B2A410071C351 /* Control.swift */,
EAF7F09F289AB7EC00B287F5 /* View.swift */,
@ -679,6 +684,7 @@
EAB2375C29E8789100AABE9A /* Tooltip.swift */,
EAB2376729E9992800AABE9A /* TooltipAlertViewController.swift */,
EAB2376929E9E59100AABE9A /* TooltipLaunchable.swift */,
EA7B311C2A7018B600329654 /* TooltipModel.swift */,
EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */,
);
path = Tooltip;
@ -923,6 +929,7 @@
EA5E305A29510F8B0082B959 /* EnumSubset.swift in Sources */,
EA985BF7296C665E00F2FF2E /* IconName.swift in Sources */,
EA8141102A127066004F60D2 /* UIColor+VDSColor.swift in Sources */,
EA7B311D2A7018B600329654 /* TooltipModel.swift in Sources */,
EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */,
EA0D1C412A6AD61C00E5C127 /* Typography+Additional.swift in Sources */,
EAC925842911C63100091998 /* Colorable.swift in Sources */,
@ -938,6 +945,7 @@
EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */,
EAF7F0952899861000B287F5 /* CheckboxItem.swift in Sources */,
EA985BE82968951C00F2FF2E /* TileletTitleModel.swift in Sources */,
EA7B311F2A701AE400329654 /* Children.swift in Sources */,
EA297A5529FB07760031ED56 /* TooltipLabelAttribute.swift in Sources */,
EA985BEA29689B6D00F2FF2E /* TileletSubTitleModel.swift in Sources */,
EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */,

106
VDS/Classes/Children.swift Normal file
View File

@ -0,0 +1,106 @@
//
// Children.swift
// VDS
//
// Created by Matt Bruce on 7/25/23.
//
import Foundation
import UIKit
open class Children: View {
public enum Mode {
case textOnly
case viewOnly
case textViewOnly
public var errorMessage: String {
switch self {
case .textOnly:
return "Invalid type passed. Expected String."
case .viewOnly:
return "Invalid type passed. Expected a UIView."
case .textViewOnly:
return "Invalid type passed. Expected a UIView or String."
}
}
}
open var mode: Mode = .textViewOnly
open var child: Any? {
didSet {
updateChildView()
}
}
open var textStyle: TextStyle? {
didSet {
updateChildView()
}
}
open lazy var label: Label = {
let lbl = Label()
lbl.lineBreakMode = .byWordWrapping
lbl.numberOfLines = 0
lbl.layer.masksToBounds = true
lbl.textAlignment = .left
return lbl
}()
open var customSubview: UIView?
private func updateChildView() {
// Remove previous views if any
label.removeFromSuperview()
customSubview?.removeFromSuperview()
guard let child else { return }
var view: UIView? = nil
switch mode {
case .textOnly:
if let string = child as? String {
label.text = string
if let textStyle = textStyle {
label.textStyle = textStyle
}
view = label
}
case .viewOnly:
if let customView = child as? View {
customSubview = customView
view = customView
}
case .textViewOnly:
if let customView = child as? View {
customSubview = customView
view = customView
} else if let string = child as? String {
label.text = string
if let textStyle = textStyle {
label.textStyle = textStyle
}
view = label
}
}
guard let unwrappedView = view else {
print(mode.errorMessage)
return
}
addSubview(unwrappedView)
unwrappedView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
unwrappedView.topAnchor.constraint(equalTo: self.topAnchor),
unwrappedView.bottomAnchor.constraint(equalTo: self.bottomAnchor),
unwrappedView.leadingAnchor.constraint(equalTo: self.leadingAnchor),
unwrappedView.trailingAnchor.constraint(equalTo: self.trailingAnchor)
])
}
}

View File

@ -13,16 +13,19 @@ import VDSColorTokens
public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable {
public var id = UUID()
public var action = PassthroughSubject<Void, Never>()
private var subscriber: AnyCancellable?
private var size: Tooltip.Size = .small
private var tooltipModel: TooltipModel {
.init(surface: surface, closeButtonText: closeButtonText, title: title, child: child)
}
public var location: Int = 0
public var length: Int = 3
public var surface: Surface = .light
public var accessibleText: String? = "Tool Tip"
public var closeButtonText: String = "Close"
public var title: String?
public var content: String?
public var contentView: UIView?
public var child: Any?
public func setAttribute(on attributedString: NSMutableAttributedString) {
//update the location
@ -66,7 +69,7 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
addHandler(on: attributedString)
}
public init(id: UUID = UUID(), action: PassthroughSubject<Void, Never> = PassthroughSubject<Void, Never>(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String = "Close", title: String? = nil, content: String? = nil, contentView: UIView? = nil) {
public init(id: UUID = UUID(), action: PassthroughSubject<Void, Never> = PassthroughSubject<Void, Never>(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String = "Close", title: String? = nil, child: Any? = nil) {
self.id = id
self.action = action
self.subscriber = subscriber
@ -74,16 +77,11 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
self.accessibleText = accessibleText
self.closeButtonText = closeButtonText
self.title = title
self.content = content
self.contentView = contentView
self.child = child
//create the tooltip click event
self.subscriber = action.sink { [weak self] in
guard let self else { return }
self.presentTooltip(surface: self.surface,
title: self.title,
content: self.content,
contentView: contentView,
closeButtonText: self.closeButtonText)
self.presentTooltip(tooltip: tooltipModel)
}
}

View File

@ -85,7 +85,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
super.init(coder: coder)
initialSetup()
}
//--------------------------------------------------
// MARK: - Public Functions
//--------------------------------------------------

View File

@ -149,10 +149,8 @@ open class EntryField: Control, Changeable {
open var tooltipTitle: String? { didSet { setNeedsUpdate() }}
open var tooltipContent: String? { didSet { setNeedsUpdate() }}
open var tooltipContentView: UIView? { didSet { setNeedsUpdate() }}
open var tooltipChild: Any? { didSet { setNeedsUpdate() }}
open var transparentBackground: Bool = false { didSet { setNeedsUpdate() }}
open var width: CGFloat? { didSet { setNeedsUpdate() }}
@ -246,7 +244,7 @@ open class EntryField: Control, Changeable {
showError = false
errorText = nil
tooltipTitle = nil
tooltipContent = nil
tooltipChild = nil
transparentBackground = false
width = nil
maxLength = nil
@ -293,9 +291,7 @@ open class EntryField: Control, Changeable {
updatedLabelText = "\(oldText) Optional"
}
if let tooltipTitle, let tooltipContent {
attributes.append(TooltipLabelAttribute(surface: surface, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView))
}
attributes.append(TooltipLabelAttribute(surface: surface, title: tooltipTitle, child: tooltipChild))
//set the titleLabel
titleLabel.text = updatedLabelText

View File

@ -34,7 +34,10 @@ open class Tooltip: Control, TooltipLaunchable {
private var widthConstraint: NSLayoutConstraint?
private var heightConstraint: NSLayoutConstraint?
private var infoImage = UIImage()
private var tooltipModel: TooltipModel {
.init(surface: surface, closeButtonText: closeButtonText, title: title, child: child)
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
@ -52,10 +55,8 @@ open class Tooltip: Control, TooltipLaunchable {
open var title: String? { didSet { setNeedsUpdate() }}
open var content: String? { didSet { setNeedsUpdate() }}
open var contentView: UIView? { didSet { setNeedsUpdate() }}
open var child: Any? { didSet { setNeedsUpdate() }}
//--------------------------------------------------
// MARK: - Configuration
//--------------------------------------------------
@ -131,24 +132,17 @@ open class Tooltip: Control, TooltipLaunchable {
onClickSubscriber = publisher(for: .touchUpInside)
.sink(receiveValue: { [weak self] tooltip in
guard let self else { return}
self.presentTooltip(surface: tooltip.surface,
title: tooltip.title,
content: tooltip.content,
contentView: tooltip.contentView,
closeButtonText: tooltip.closeButtonText)
self.presentTooltip(tooltip: tooltipModel)
})
}
open override func reset() {
super.reset()
shouldUpdateView = false
size = .medium
title = ""
content = ""
fillColor = .primary
closeButtonText = "Close"
imageView.image = nil
shouldUpdateView = true
setNeedsUpdate()
}
@ -173,7 +167,7 @@ open class Tooltip: Control, TooltipLaunchable {
}
var label = title
if label == nil {
label = content
label = child as? String
}
if let label {
accessibilityLabel = "Tooltip: \(label)"

View File

@ -33,8 +33,7 @@ open class TooltipAlertViewController: UIViewController, Surfaceable {
//--------------------------------------------------
open var surface: Surface = .light { didSet { updateView() }}
open var titleText: String? { didSet { updateView() }}
open var contentText: String? { didSet { updateView() }}
open var contentView: UIView? { didSet { updateView() }}
open var child: Any? { didSet { updateView() }}
open var closeButtonText: String = "Close" { didSet { updateView() }}
//--------------------------------------------------
@ -91,8 +90,7 @@ open class TooltipAlertViewController: UIViewController, Surfaceable {
view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.3)
tooltipDialog.surface = surface
tooltipDialog.titleText = titleText
tooltipDialog.contentText = contentText
tooltipDialog.contentView = contentView
tooltipDialog.child = children
}
}
@ -121,13 +119,9 @@ open class TooltipDialog: View, UIScrollViewDelegate {
open var titleLabel = Label().with { label in
label.textStyle = .boldTitleMedium
}
open var child: Any? { didSet { setNeedsUpdate() }}
open var contentText: String? { didSet { setNeedsUpdate() }}
open var contentLabel = Label().with { label in
label.textStyle = .bodyLarge
}
open var contentView: UIView? = nil
private var childrenView = Children().with { $0.textStyle = .bodyLarge; $0.mode = .textViewOnly }
open var closeButtonText: String = "Close" { didSet { setNeedsUpdate() }}
@ -164,7 +158,7 @@ open class TooltipDialog: View, UIScrollViewDelegate {
layer.cornerRadius = 8
contentStackView.addArrangedSubview(titleLabel)
contentStackView.addArrangedSubview(contentLabel)
contentStackView.addArrangedSubview(childrenView)
scrollView.addSubview(contentStackView)
addSubview(scrollView)
addSubview(line)
@ -209,43 +203,29 @@ open class TooltipDialog: View, UIScrollViewDelegate {
scrollView.indicatorStyle = surface == .light ? .black : .white
titleLabel.removeFromSuperview()
contentLabel.removeFromSuperview()
contentView?.removeFromSuperview()
childrenView.removeFromSuperview()
titleLabel.surface = surface
contentLabel.surface = surface
childrenView.surface = surface
line.surface = surface
titleLabel.text = titleText
contentLabel.text = contentText
titleLabel.sizeToFit()
contentLabel.sizeToFit()
var addedTitle = false
childrenView.child = child
if let titleText, !titleText.isEmpty {
contentStackView.addArrangedSubview(titleLabel)
addedTitle = true
}
var addedContent = false
if let contentText, !contentText.isEmpty {
contentStackView.addArrangedSubview(contentLabel)
addedContent = true
} else if let contentView {
contentView.translatesAutoresizingMaskIntoConstraints = false
if var surfaceable = contentView as? Surfaceable {
if let child {
if var surfaceable = child as? Surfaceable {
surfaceable.surface = surface
}
let wrapper = View()
wrapper.addSubview(contentView)
contentView.pinTop()
contentView.pinLeading()
contentView.pinBottom()
contentView.pinTrailingLessThanOrEqualTo()
contentView.setNeedsLayout()
contentStackView.addArrangedSubview(wrapper)
contentStackView.addArrangedSubview(childrenView)
addedContent = true
}

View File

@ -9,18 +9,17 @@ import Foundation
import UIKit
public protocol TooltipLaunchable {
func presentTooltip(surface: Surface, title: String?, content: String?, contentView: UIView?, closeButtonText: String)
func presentTooltip(tooltip: TooltipModel)
}
extension TooltipLaunchable {
public func presentTooltip(surface: Surface, title: String?, content: String?, contentView: UIView? = nil, closeButtonText: String = "Close") {
public func presentTooltip(tooltip: TooltipModel) {
if let presenting = UIApplication.topViewController() {
let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with {
$0.surface = surface
$0.titleText = title
$0.contentText = content
$0.contentView = contentView
$0.closeButtonText = closeButtonText
$0.surface = tooltip.surface
$0.titleText = tooltip.title
$0.child = tooltip.child
$0.closeButtonText = tooltip.closeButtonText
$0.modalPresentationStyle = .overCurrentContext
$0.modalTransitionStyle = .crossDissolve
}

View File

@ -0,0 +1,21 @@
//
// TooltipModel.swift
// VDS
//
// Created by Matt Bruce on 7/25/23.
//
import Foundation
public struct TooltipModel {
public var surface: Surface
public var closeButtonText: String
public var title: String?
public var child: Any?
public init(surface: Surface = .light, closeButtonText: String = "Close", title: String?, child: Any? = nil) {
self.surface = surface
self.closeButtonText = closeButtonText
self.title = title
self.child = child
}
}

View File

@ -16,7 +16,9 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
// MARK: - Private Properties
//--------------------------------------------------
private let tooltipAction = PassthroughSubject<Void, Never>()
private var tooltipModel: TooltipModel {
.init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, child: tooltipChild)
}
//--------------------------------------------------
// MARK: - Public Properties
//--------------------------------------------------
@ -38,9 +40,8 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
open var tooltipTitle: String? { didSet { setNeedsUpdate() } }
open var tooltipContent: String? { didSet { setNeedsUpdate() } }
open var tooltipChild: Any? { didSet { setNeedsUpdate() } }
open var tooltipContentView: UIView? { didSet { setNeedsUpdate() } }
//--------------------------------------------------
// MARK: - Overrides
@ -54,10 +55,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
//create the tooltip click event
tooltipAction.sink { [weak self] in
guard let self else { return }
self.presentTooltip(surface: self.surface,
title: self.tooltipTitle,
content: self.tooltipContent,
closeButtonText: self.tooltipCloseButtonText)
self.presentTooltip(tooltip: tooltipModel)
}.store(in: &subscribers)
}
@ -72,9 +70,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
label.disabled = disabled
//add tooltip
if let labelText, !labelText.isEmpty {
label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView))
}
label.addTooltip(model: tooltipModel)
}
open override func reset() {
@ -86,7 +82,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
labelTextPosition = .left
tooltipCloseButtonText = "Close"
tooltipTitle = ""
tooltipContent = ""
tooltipChild = nil
shouldUpdateView = true
setNeedsUpdate()
}
@ -94,20 +90,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
extension Label {
public struct TooltipModel {
public var surface: Surface
public var closeButtonText: String
public var title: String?
public var content: String?
public var contentView: UIView?
public init(surface: Surface = .light, closeButtonText: String = "Close", title: String?, content: String?, contentView: UIView?) {
self.surface = surface
self.closeButtonText = closeButtonText
self.title = title
self.content = content
self.contentView = contentView
}
}
public func addTooltip(model: TooltipModel) {
@ -124,8 +106,7 @@ extension Label {
let tooltip = TooltipLabelAttribute(surface: surface,
closeButtonText: model.closeButtonText,
title: model.title,
content: model.content,
contentView: model.contentView)
child: model.child)
newAttributes.append(tooltip)
}