Compare commits
3 Commits
develop
...
refactor/t
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
123831adf6 | ||
|
|
827269bb6d | ||
|
|
b74a338b0f |
@ -62,6 +62,8 @@
|
|||||||
EA5F86C82A1BD99100BC83E4 /* TabModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86C72A1BD99100BC83E4 /* TabModel.swift */; };
|
EA5F86C82A1BD99100BC83E4 /* TabModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86C72A1BD99100BC83E4 /* TabModel.swift */; };
|
||||||
EA5F86CC2A1D28B500BC83E4 /* ReleaseNotes.txt in Resources */ = {isa = PBXBuildFile; fileRef = EA5F86CB2A1D28B500BC83E4 /* ReleaseNotes.txt */; };
|
EA5F86CC2A1D28B500BC83E4 /* ReleaseNotes.txt in Resources */ = {isa = PBXBuildFile; fileRef = EA5F86CB2A1D28B500BC83E4 /* ReleaseNotes.txt */; };
|
||||||
EA5F86D02A1F936100BC83E4 /* TabsContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA5F86CF2A1F936100BC83E4 /* TabsContainer.swift */; };
|
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 */; };
|
EA81410B2A0E8E3C004F60D2 /* ButtonIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410A2A0E8E3C004F60D2 /* ButtonIcon.swift */; };
|
||||||
EA8141102A127066004F60D2 /* UIColor+VDSColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA81410F2A127066004F60D2 /* UIColor+VDSColor.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 */; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
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>"; };
|
EA89200328AECF4B006B9984 /* UITextField+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UITextField+Publisher.swift"; sourceTree = "<group>"; };
|
||||||
@ -503,6 +507,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
EA985C1C296CD13600F2FF2E /* BundleManager.swift */,
|
EA985C1C296CD13600F2FF2E /* BundleManager.swift */,
|
||||||
|
EA7B311E2A701AE400329654 /* Children.swift */,
|
||||||
EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */,
|
EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */,
|
||||||
EA3361B5288B2A410071C351 /* Control.swift */,
|
EA3361B5288B2A410071C351 /* Control.swift */,
|
||||||
EAF7F09F289AB7EC00B287F5 /* View.swift */,
|
EAF7F09F289AB7EC00B287F5 /* View.swift */,
|
||||||
@ -679,6 +684,7 @@
|
|||||||
EAB2375C29E8789100AABE9A /* Tooltip.swift */,
|
EAB2375C29E8789100AABE9A /* Tooltip.swift */,
|
||||||
EAB2376729E9992800AABE9A /* TooltipAlertViewController.swift */,
|
EAB2376729E9992800AABE9A /* TooltipAlertViewController.swift */,
|
||||||
EAB2376929E9E59100AABE9A /* TooltipLaunchable.swift */,
|
EAB2376929E9E59100AABE9A /* TooltipLaunchable.swift */,
|
||||||
|
EA7B311C2A7018B600329654 /* TooltipModel.swift */,
|
||||||
EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */,
|
EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */,
|
||||||
);
|
);
|
||||||
path = Tooltip;
|
path = Tooltip;
|
||||||
@ -923,6 +929,7 @@
|
|||||||
EA5E305A29510F8B0082B959 /* EnumSubset.swift in Sources */,
|
EA5E305A29510F8B0082B959 /* EnumSubset.swift in Sources */,
|
||||||
EA985BF7296C665E00F2FF2E /* IconName.swift in Sources */,
|
EA985BF7296C665E00F2FF2E /* IconName.swift in Sources */,
|
||||||
EA8141102A127066004F60D2 /* UIColor+VDSColor.swift in Sources */,
|
EA8141102A127066004F60D2 /* UIColor+VDSColor.swift in Sources */,
|
||||||
|
EA7B311D2A7018B600329654 /* TooltipModel.swift in Sources */,
|
||||||
EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */,
|
EAF7F0AF289B144C00B287F5 /* UnderlineLabelAttribute.swift in Sources */,
|
||||||
EA0D1C412A6AD61C00E5C127 /* Typography+Additional.swift in Sources */,
|
EA0D1C412A6AD61C00E5C127 /* Typography+Additional.swift in Sources */,
|
||||||
EAC925842911C63100091998 /* Colorable.swift in Sources */,
|
EAC925842911C63100091998 /* Colorable.swift in Sources */,
|
||||||
@ -938,6 +945,7 @@
|
|||||||
EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */,
|
EAC846F3294B95CE00F685BA /* ButtonGroupCollectionViewCell.swift in Sources */,
|
||||||
EAF7F0952899861000B287F5 /* CheckboxItem.swift in Sources */,
|
EAF7F0952899861000B287F5 /* CheckboxItem.swift in Sources */,
|
||||||
EA985BE82968951C00F2FF2E /* TileletTitleModel.swift in Sources */,
|
EA985BE82968951C00F2FF2E /* TileletTitleModel.swift in Sources */,
|
||||||
|
EA7B311F2A701AE400329654 /* Children.swift in Sources */,
|
||||||
EA297A5529FB07760031ED56 /* TooltipLabelAttribute.swift in Sources */,
|
EA297A5529FB07760031ED56 /* TooltipLabelAttribute.swift in Sources */,
|
||||||
EA985BEA29689B6D00F2FF2E /* TileletSubTitleModel.swift in Sources */,
|
EA985BEA29689B6D00F2FF2E /* TileletSubTitleModel.swift in Sources */,
|
||||||
EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */,
|
EA3361C9289054C50071C351 /* Surfaceable.swift in Sources */,
|
||||||
|
|||||||
106
VDS/Classes/Children.swift
Normal file
106
VDS/Classes/Children.swift
Normal 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)
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,16 +13,19 @@ import VDSColorTokens
|
|||||||
public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable {
|
public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable {
|
||||||
public var id = UUID()
|
public var id = UUID()
|
||||||
public var action = PassthroughSubject<Void, Never>()
|
public var action = PassthroughSubject<Void, Never>()
|
||||||
|
|
||||||
private var subscriber: AnyCancellable?
|
private var subscriber: AnyCancellable?
|
||||||
private var size: Tooltip.Size = .small
|
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 location: Int = 0
|
||||||
public var length: Int = 3
|
public var length: Int = 3
|
||||||
public var surface: Surface = .light
|
public var surface: Surface = .light
|
||||||
public var accessibleText: String? = "Tool Tip"
|
public var accessibleText: String? = "Tool Tip"
|
||||||
public var closeButtonText: String = "Close"
|
public var closeButtonText: String = "Close"
|
||||||
public var title: String?
|
public var title: String?
|
||||||
public var content: String?
|
public var child: Any?
|
||||||
public var contentView: UIView?
|
|
||||||
|
|
||||||
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
public func setAttribute(on attributedString: NSMutableAttributedString) {
|
||||||
//update the location
|
//update the location
|
||||||
@ -66,7 +69,7 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
|
|||||||
addHandler(on: attributedString)
|
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.id = id
|
||||||
self.action = action
|
self.action = action
|
||||||
self.subscriber = subscriber
|
self.subscriber = subscriber
|
||||||
@ -74,16 +77,11 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable
|
|||||||
self.accessibleText = accessibleText
|
self.accessibleText = accessibleText
|
||||||
self.closeButtonText = closeButtonText
|
self.closeButtonText = closeButtonText
|
||||||
self.title = title
|
self.title = title
|
||||||
self.content = content
|
self.child = child
|
||||||
self.contentView = contentView
|
|
||||||
//create the tooltip click event
|
//create the tooltip click event
|
||||||
self.subscriber = action.sink { [weak self] in
|
self.subscriber = action.sink { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
self.presentTooltip(surface: self.surface,
|
self.presentTooltip(tooltip: tooltipModel)
|
||||||
title: self.title,
|
|
||||||
content: self.content,
|
|
||||||
contentView: contentView,
|
|
||||||
closeButtonText: self.closeButtonText)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -85,7 +85,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable {
|
|||||||
super.init(coder: coder)
|
super.init(coder: coder)
|
||||||
initialSetup()
|
initialSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Functions
|
// MARK: - Public Functions
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -149,10 +149,8 @@ open class EntryField: Control, Changeable {
|
|||||||
|
|
||||||
open var tooltipTitle: String? { didSet { setNeedsUpdate() }}
|
open var tooltipTitle: String? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
open var tooltipContent: String? { didSet { setNeedsUpdate() }}
|
open var tooltipChild: Any? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
open var tooltipContentView: UIView? { didSet { setNeedsUpdate() }}
|
|
||||||
|
|
||||||
open var transparentBackground: Bool = false { didSet { setNeedsUpdate() }}
|
open var transparentBackground: Bool = false { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
open var width: CGFloat? { didSet { setNeedsUpdate() }}
|
open var width: CGFloat? { didSet { setNeedsUpdate() }}
|
||||||
@ -246,7 +244,7 @@ open class EntryField: Control, Changeable {
|
|||||||
showError = false
|
showError = false
|
||||||
errorText = nil
|
errorText = nil
|
||||||
tooltipTitle = nil
|
tooltipTitle = nil
|
||||||
tooltipContent = nil
|
tooltipChild = nil
|
||||||
transparentBackground = false
|
transparentBackground = false
|
||||||
width = nil
|
width = nil
|
||||||
maxLength = nil
|
maxLength = nil
|
||||||
@ -293,9 +291,7 @@ open class EntryField: Control, Changeable {
|
|||||||
updatedLabelText = "\(oldText) Optional"
|
updatedLabelText = "\(oldText) Optional"
|
||||||
}
|
}
|
||||||
|
|
||||||
if let tooltipTitle, let tooltipContent {
|
attributes.append(TooltipLabelAttribute(surface: surface, title: tooltipTitle, child: tooltipChild))
|
||||||
attributes.append(TooltipLabelAttribute(surface: surface, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView))
|
|
||||||
}
|
|
||||||
|
|
||||||
//set the titleLabel
|
//set the titleLabel
|
||||||
titleLabel.text = updatedLabelText
|
titleLabel.text = updatedLabelText
|
||||||
|
|||||||
@ -34,7 +34,10 @@ open class Tooltip: Control, TooltipLaunchable {
|
|||||||
private var widthConstraint: NSLayoutConstraint?
|
private var widthConstraint: NSLayoutConstraint?
|
||||||
private var heightConstraint: NSLayoutConstraint?
|
private var heightConstraint: NSLayoutConstraint?
|
||||||
private var infoImage = UIImage()
|
private var infoImage = UIImage()
|
||||||
|
private var tooltipModel: TooltipModel {
|
||||||
|
.init(surface: surface, closeButtonText: closeButtonText, title: title, child: child)
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -52,10 +55,8 @@ open class Tooltip: Control, TooltipLaunchable {
|
|||||||
|
|
||||||
open var title: String? { didSet { setNeedsUpdate() }}
|
open var title: String? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
open var content: String? { didSet { setNeedsUpdate() }}
|
open var child: Any? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
open var contentView: UIView? { didSet { setNeedsUpdate() }}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration
|
// MARK: - Configuration
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -131,24 +132,17 @@ open class Tooltip: Control, TooltipLaunchable {
|
|||||||
onClickSubscriber = publisher(for: .touchUpInside)
|
onClickSubscriber = publisher(for: .touchUpInside)
|
||||||
.sink(receiveValue: { [weak self] tooltip in
|
.sink(receiveValue: { [weak self] tooltip in
|
||||||
guard let self else { return}
|
guard let self else { return}
|
||||||
self.presentTooltip(surface: tooltip.surface,
|
self.presentTooltip(tooltip: tooltipModel)
|
||||||
title: tooltip.title,
|
|
||||||
content: tooltip.content,
|
|
||||||
contentView: tooltip.contentView,
|
|
||||||
closeButtonText: tooltip.closeButtonText)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
shouldUpdateView = false
|
|
||||||
size = .medium
|
size = .medium
|
||||||
title = ""
|
title = ""
|
||||||
content = ""
|
|
||||||
fillColor = .primary
|
fillColor = .primary
|
||||||
closeButtonText = "Close"
|
closeButtonText = "Close"
|
||||||
imageView.image = nil
|
imageView.image = nil
|
||||||
shouldUpdateView = true
|
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,7 +167,7 @@ open class Tooltip: Control, TooltipLaunchable {
|
|||||||
}
|
}
|
||||||
var label = title
|
var label = title
|
||||||
if label == nil {
|
if label == nil {
|
||||||
label = content
|
label = child as? String
|
||||||
}
|
}
|
||||||
if let label {
|
if let label {
|
||||||
accessibilityLabel = "Tooltip: \(label)"
|
accessibilityLabel = "Tooltip: \(label)"
|
||||||
|
|||||||
@ -33,8 +33,7 @@ open class TooltipAlertViewController: UIViewController, Surfaceable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
open var surface: Surface = .light { didSet { updateView() }}
|
open var surface: Surface = .light { didSet { updateView() }}
|
||||||
open var titleText: String? { didSet { updateView() }}
|
open var titleText: String? { didSet { updateView() }}
|
||||||
open var contentText: String? { didSet { updateView() }}
|
open var child: Any? { didSet { updateView() }}
|
||||||
open var contentView: UIView? { didSet { updateView() }}
|
|
||||||
open var closeButtonText: String = "Close" { 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)
|
view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.3)
|
||||||
tooltipDialog.surface = surface
|
tooltipDialog.surface = surface
|
||||||
tooltipDialog.titleText = titleText
|
tooltipDialog.titleText = titleText
|
||||||
tooltipDialog.contentText = contentText
|
tooltipDialog.child = children
|
||||||
tooltipDialog.contentView = contentView
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,13 +119,9 @@ open class TooltipDialog: View, UIScrollViewDelegate {
|
|||||||
open var titleLabel = Label().with { label in
|
open var titleLabel = Label().with { label in
|
||||||
label.textStyle = .boldTitleMedium
|
label.textStyle = .boldTitleMedium
|
||||||
}
|
}
|
||||||
|
open var child: Any? { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
open var contentText: String? { didSet { setNeedsUpdate() }}
|
private var childrenView = Children().with { $0.textStyle = .bodyLarge; $0.mode = .textViewOnly }
|
||||||
open var contentLabel = Label().with { label in
|
|
||||||
label.textStyle = .bodyLarge
|
|
||||||
}
|
|
||||||
|
|
||||||
open var contentView: UIView? = nil
|
|
||||||
|
|
||||||
open var closeButtonText: String = "Close" { didSet { setNeedsUpdate() }}
|
open var closeButtonText: String = "Close" { didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
@ -164,7 +158,7 @@ open class TooltipDialog: View, UIScrollViewDelegate {
|
|||||||
layer.cornerRadius = 8
|
layer.cornerRadius = 8
|
||||||
|
|
||||||
contentStackView.addArrangedSubview(titleLabel)
|
contentStackView.addArrangedSubview(titleLabel)
|
||||||
contentStackView.addArrangedSubview(contentLabel)
|
contentStackView.addArrangedSubview(childrenView)
|
||||||
scrollView.addSubview(contentStackView)
|
scrollView.addSubview(contentStackView)
|
||||||
addSubview(scrollView)
|
addSubview(scrollView)
|
||||||
addSubview(line)
|
addSubview(line)
|
||||||
@ -209,43 +203,29 @@ open class TooltipDialog: View, UIScrollViewDelegate {
|
|||||||
scrollView.indicatorStyle = surface == .light ? .black : .white
|
scrollView.indicatorStyle = surface == .light ? .black : .white
|
||||||
|
|
||||||
titleLabel.removeFromSuperview()
|
titleLabel.removeFromSuperview()
|
||||||
contentLabel.removeFromSuperview()
|
childrenView.removeFromSuperview()
|
||||||
contentView?.removeFromSuperview()
|
|
||||||
|
|
||||||
titleLabel.surface = surface
|
titleLabel.surface = surface
|
||||||
contentLabel.surface = surface
|
childrenView.surface = surface
|
||||||
line.surface = surface
|
line.surface = surface
|
||||||
|
|
||||||
titleLabel.text = titleText
|
titleLabel.text = titleText
|
||||||
contentLabel.text = contentText
|
|
||||||
|
|
||||||
titleLabel.sizeToFit()
|
titleLabel.sizeToFit()
|
||||||
contentLabel.sizeToFit()
|
|
||||||
|
|
||||||
var addedTitle = false
|
var addedTitle = false
|
||||||
|
childrenView.child = child
|
||||||
|
|
||||||
if let titleText, !titleText.isEmpty {
|
if let titleText, !titleText.isEmpty {
|
||||||
contentStackView.addArrangedSubview(titleLabel)
|
contentStackView.addArrangedSubview(titleLabel)
|
||||||
addedTitle = true
|
addedTitle = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var addedContent = false
|
var addedContent = false
|
||||||
if let contentText, !contentText.isEmpty {
|
if let child {
|
||||||
contentStackView.addArrangedSubview(contentLabel)
|
if var surfaceable = child as? Surfaceable {
|
||||||
addedContent = true
|
|
||||||
} else if let contentView {
|
|
||||||
contentView.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
if var surfaceable = contentView as? Surfaceable {
|
|
||||||
surfaceable.surface = surface
|
surfaceable.surface = surface
|
||||||
}
|
}
|
||||||
let wrapper = View()
|
contentStackView.addArrangedSubview(childrenView)
|
||||||
wrapper.addSubview(contentView)
|
|
||||||
contentView.pinTop()
|
|
||||||
contentView.pinLeading()
|
|
||||||
contentView.pinBottom()
|
|
||||||
contentView.pinTrailingLessThanOrEqualTo()
|
|
||||||
contentView.setNeedsLayout()
|
|
||||||
contentStackView.addArrangedSubview(wrapper)
|
|
||||||
addedContent = true
|
addedContent = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -9,18 +9,17 @@ import Foundation
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
public protocol TooltipLaunchable {
|
public protocol TooltipLaunchable {
|
||||||
func presentTooltip(surface: Surface, title: String?, content: String?, contentView: UIView?, closeButtonText: String)
|
func presentTooltip(tooltip: TooltipModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension TooltipLaunchable {
|
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() {
|
if let presenting = UIApplication.topViewController() {
|
||||||
let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with {
|
let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with {
|
||||||
$0.surface = surface
|
$0.surface = tooltip.surface
|
||||||
$0.titleText = title
|
$0.titleText = tooltip.title
|
||||||
$0.contentText = content
|
$0.child = tooltip.child
|
||||||
$0.contentView = contentView
|
$0.closeButtonText = tooltip.closeButtonText
|
||||||
$0.closeButtonText = closeButtonText
|
|
||||||
$0.modalPresentationStyle = .overCurrentContext
|
$0.modalPresentationStyle = .overCurrentContext
|
||||||
$0.modalTransitionStyle = .crossDissolve
|
$0.modalTransitionStyle = .crossDissolve
|
||||||
}
|
}
|
||||||
|
|||||||
21
VDS/Components/Tooltip/TooltipModel.swift
Normal file
21
VDS/Components/Tooltip/TooltipModel.swift
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,7 +16,9 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
|
|||||||
// MARK: - Private Properties
|
// MARK: - Private Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private let tooltipAction = PassthroughSubject<Void, Never>()
|
private let tooltipAction = PassthroughSubject<Void, Never>()
|
||||||
|
private var tooltipModel: TooltipModel {
|
||||||
|
.init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, child: tooltipChild)
|
||||||
|
}
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Public Properties
|
// MARK: - Public Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -38,9 +40,8 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
|
|||||||
|
|
||||||
open var tooltipTitle: String? { didSet { setNeedsUpdate() } }
|
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
|
// MARK: - Overrides
|
||||||
@ -54,10 +55,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
|
|||||||
//create the tooltip click event
|
//create the tooltip click event
|
||||||
tooltipAction.sink { [weak self] in
|
tooltipAction.sink { [weak self] in
|
||||||
guard let self else { return }
|
guard let self else { return }
|
||||||
self.presentTooltip(surface: self.surface,
|
self.presentTooltip(tooltip: tooltipModel)
|
||||||
title: self.tooltipTitle,
|
|
||||||
content: self.tooltipContent,
|
|
||||||
closeButtonText: self.tooltipCloseButtonText)
|
|
||||||
}.store(in: &subscribers)
|
}.store(in: &subscribers)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,9 +70,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
|
|||||||
label.disabled = disabled
|
label.disabled = disabled
|
||||||
|
|
||||||
//add tooltip
|
//add tooltip
|
||||||
if let labelText, !labelText.isEmpty {
|
label.addTooltip(model: tooltipModel)
|
||||||
label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
@ -86,7 +82,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
|
|||||||
labelTextPosition = .left
|
labelTextPosition = .left
|
||||||
tooltipCloseButtonText = "Close"
|
tooltipCloseButtonText = "Close"
|
||||||
tooltipTitle = ""
|
tooltipTitle = ""
|
||||||
tooltipContent = ""
|
tooltipChild = nil
|
||||||
shouldUpdateView = true
|
shouldUpdateView = true
|
||||||
setNeedsUpdate()
|
setNeedsUpdate()
|
||||||
}
|
}
|
||||||
@ -94,20 +90,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable {
|
|||||||
|
|
||||||
|
|
||||||
extension Label {
|
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) {
|
public func addTooltip(model: TooltipModel) {
|
||||||
|
|
||||||
@ -124,8 +106,7 @@ extension Label {
|
|||||||
let tooltip = TooltipLabelAttribute(surface: surface,
|
let tooltip = TooltipLabelAttribute(surface: surface,
|
||||||
closeButtonText: model.closeButtonText,
|
closeButtonText: model.closeButtonText,
|
||||||
title: model.title,
|
title: model.title,
|
||||||
content: model.content,
|
child: model.child)
|
||||||
contentView: model.contentView)
|
|
||||||
newAttributes.append(tooltip)
|
newAttributes.append(tooltip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user