refactored tooltip/label to use protocol
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
1a3f76e196
commit
f6af646d09
@ -6,3 +6,22 @@
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public protocol TooltipLaunchable { }
|
||||
|
||||
extension TooltipLaunchable {
|
||||
public func presentTooltip(surface: Surface, title: String, content: String, closeButtonText: String = "Close") {
|
||||
if let presenting = UIApplication.topViewController() {
|
||||
let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with {
|
||||
$0.surface = surface
|
||||
$0.titleText = title
|
||||
$0.contentText = content
|
||||
$0.closeButtonText = closeButtonText
|
||||
$0.modalPresentationStyle = .overCurrentContext
|
||||
$0.modalTransitionStyle = .crossDissolve
|
||||
}
|
||||
presenting.present(tooltipViewController, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,7 +12,7 @@ import VDSFormControlsTokens
|
||||
import Combine
|
||||
|
||||
@objc(VDSTooltip)
|
||||
open class Tooltip: Control {
|
||||
open class Tooltip: Control, TooltipLaunchable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Enums
|
||||
@ -117,7 +117,10 @@ open class Tooltip: Control {
|
||||
onClickSubscriber = publisher(for: .touchUpInside)
|
||||
.sink(receiveValue: { [weak self] tooltip in
|
||||
guard let self else { return}
|
||||
self.presentTooltip()
|
||||
self.presentTooltip(surface: tooltip.surface,
|
||||
title: tooltip.title,
|
||||
content: tooltip.content,
|
||||
closeButtonText: tooltip.closeButtonText)
|
||||
})
|
||||
}
|
||||
|
||||
@ -146,17 +149,4 @@ open class Tooltip: Control {
|
||||
accessibilityLabel = "Tooltip: \(title)"
|
||||
}
|
||||
|
||||
private func presentTooltip() {
|
||||
if let presenting = UIApplication.topViewController() {
|
||||
let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with {
|
||||
$0.surface = surface
|
||||
$0.titleText = title
|
||||
$0.contentText = content
|
||||
$0.closeButtonText = closeButtonText
|
||||
$0.modalPresentationStyle = .overCurrentContext
|
||||
$0.modalTransitionStyle = .crossDissolve
|
||||
}
|
||||
presenting.present(tooltipViewController, animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import UIKit
|
||||
import Combine
|
||||
|
||||
@objc(VDSTrailingTooltipLabel)
|
||||
open class TrailingTooltipLabel: View {
|
||||
open class TrailingTooltipLabel: View, TooltipLaunchable {
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Properties
|
||||
@ -24,13 +24,15 @@ open class TrailingTooltipLabel: View {
|
||||
|
||||
open var labelText: String? { didSet { didChange() }}
|
||||
|
||||
open var labelAttributes: [any LabelAttributeModel]? { didSet { didChange() }}
|
||||
|
||||
open var labelTextStyle: TextStyle = .defaultStyle { didSet { didChange() }}
|
||||
|
||||
public lazy var textColorConfiguration: AnyColorable = {
|
||||
label.textColorConfiguration
|
||||
}() { didSet { didChange() }}
|
||||
|
||||
open var closeButtonText: String? = "Close" { didSet { didChange() }}
|
||||
open var closeButtonText: String = "Close" { didSet { didChange() }}
|
||||
|
||||
open var tooltipSize: Tooltip.Size = .medium { didSet { didChange() }}
|
||||
|
||||
@ -49,7 +51,11 @@ open class TrailingTooltipLabel: View {
|
||||
|
||||
//create the tooltip click event
|
||||
toolTipAction.sink { [weak self] in
|
||||
self?.showToolTip()
|
||||
guard let self else { return }
|
||||
self.presentTooltip(surface: self.surface,
|
||||
title: self.tooltipTitle,
|
||||
content: self.tooltipContent,
|
||||
closeButtonText: self.closeButtonText)
|
||||
}.store(in: &subscribers)
|
||||
}
|
||||
|
||||
@ -57,6 +63,10 @@ open class TrailingTooltipLabel: View {
|
||||
super.updateView()
|
||||
|
||||
var attributes: [any LabelAttributeModel] = []
|
||||
if let labelAttributes {
|
||||
attributes.append(contentsOf: labelAttributes)
|
||||
}
|
||||
|
||||
var updatedLabelText = labelText
|
||||
|
||||
//add the tool tip
|
||||
@ -77,8 +87,4 @@ open class TrailingTooltipLabel: View {
|
||||
label.surface = surface
|
||||
label.disabled = disabled
|
||||
}
|
||||
|
||||
private func showToolTip(){
|
||||
print("You should show the tooltip now!")
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user