refactored tooltip away from contentText & contentView to child: Any? and children: View
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
827269bb6d
commit
123831adf6
@ -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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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