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 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)"
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user