From 3d52d210f31173765203ce0f3e47717d1b3428e0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Sep 2023 08:22:58 -0500 Subject: [PATCH 1/6] fixed constraint error Signed-off-by: Matt Bruce --- VDS/Components/TitleLockup/TitleLockup.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 41a6cb70..455ed92b 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -379,7 +379,7 @@ open class TitleLockup: View { } //pin the last view to the bottom of this view - previousView?.pinBottom() + previousView?.pinBottom(0, .defaultHigh) //debugging for borders eyebrowLabel.debugBorder(show: hasDebugBorder, color: .green) From 3a3790d302fd0b2668924148facb1c8c8e6beeb2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Sep 2023 10:22:20 -0500 Subject: [PATCH 2/6] fixed bug in tooltip contentView Signed-off-by: Matt Bruce --- VDS/Components/Tooltip/TooltipDialog.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/VDS/Components/Tooltip/TooltipDialog.swift b/VDS/Components/Tooltip/TooltipDialog.swift index 5480c8c5..6985cfe9 100644 --- a/VDS/Components/Tooltip/TooltipDialog.swift +++ b/VDS/Components/Tooltip/TooltipDialog.swift @@ -149,9 +149,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { backgroundColor = backgroundColorConfiguration.getColor(self) scrollView.indicatorStyle = surface == .light ? .black : .white - titleLabel.removeFromSuperview() - contentLabel.removeFromSuperview() - contentView?.removeFromSuperview() + contentStackView.arrangedSubviews.forEach { $0.removeFromSuperview() } titleLabel.surface = surface contentLabel.surface = surface From b415aeafc5dc88a0fbfb8415cf1d5152ca95ac42 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Sep 2023 10:26:26 -0500 Subject: [PATCH 3/6] removed wrapper Signed-off-by: Matt Bruce --- VDS/Components/Tooltip/TooltipDialog.swift | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/VDS/Components/Tooltip/TooltipDialog.swift b/VDS/Components/Tooltip/TooltipDialog.swift index 6985cfe9..b79c453e 100644 --- a/VDS/Components/Tooltip/TooltipDialog.swift +++ b/VDS/Components/Tooltip/TooltipDialog.swift @@ -37,6 +37,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { private let contentStackView = UIStackView().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.axis = .vertical + $0.alignment = .leading $0.distribution = .fillProportionally $0.spacing = 0 } @@ -177,16 +178,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { if var surfaceable = contentView as? Surfaceable { surfaceable.surface = surface } - let wrapper = View() - wrapper.addSubview(contentView) - contentView - .pinTop() - .pinLeading() - .pinBottom() - .pinTrailingLessThanOrEqualTo() - - contentView.setNeedsLayout() - contentStackView.addArrangedSubview(wrapper) + contentStackView.addArrangedSubview(contentView) addedContent = true } From 1dd626d766367100a3fb2a48e3bec69c110c64dc Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Sep 2023 17:38:04 -0500 Subject: [PATCH 4/6] refactored tooltip to use a model Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 ++ .../Attributes/TooltipLabelAttribute.swift | 26 ++++----- .../TextFields/EntryFieldBase.swift | 16 ++--- VDS/Components/Tooltip/Tooltip.swift | 8 +-- .../Tooltip/TooltipAlertViewController.swift | 10 +--- VDS/Components/Tooltip/TooltipDialog.swift | 28 ++++----- .../Tooltip/TooltipLaunchable.swift | 9 +-- VDS/Components/Tooltip/TooltipModel.swift | 33 +++++++++++ .../Tooltip/TrailingTooltipLabel.swift | 58 ++----------------- 9 files changed, 79 insertions(+), 113 deletions(-) create mode 100644 VDS/Components/Tooltip/TooltipModel.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 4661e23d..e3948c92 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -92,6 +92,7 @@ EAA5EEEF28F5C908003B3210 /* VDSTypographyTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA5EEEC28F5C908003B3210 /* VDSTypographyTokens.xcframework */; }; EAA5EEF128F5C909003B3210 /* VDSColorTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA5EEED28F5C908003B3210 /* VDSColorTokens.xcframework */; }; EAA5EEF328F5C909003B3210 /* VDSFormControlsTokens.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAA5EEEE28F5C908003B3210 /* VDSFormControlsTokens.xcframework */; }; + EAA7456C2AB23E2000C1841F /* TooltipModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAA7456B2AB23E2000C1841F /* TooltipModel.swift */; }; EAB1D29C28A5618900DAE764 /* RadioButtonGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D29B28A5618900DAE764 /* RadioButtonGroup.swift */; }; EAB1D2CD28ABE76100DAE764 /* Withable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2CC28ABE76000DAE764 /* Withable.swift */; }; EAB1D2CF28ABEF2B00DAE764 /* Typography+Base.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAB1D2CE28ABEF2B00DAE764 /* Typography+Base.swift */; }; @@ -240,6 +241,7 @@ EAA5EEEC28F5C908003B3210 /* VDSTypographyTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSTypographyTokens.xcframework; path = ../SharedFrameworks/VDSTypographyTokens.xcframework; sourceTree = ""; }; EAA5EEED28F5C908003B3210 /* VDSColorTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSColorTokens.xcframework; path = ../SharedFrameworks/VDSColorTokens.xcframework; sourceTree = ""; }; EAA5EEEE28F5C908003B3210 /* VDSFormControlsTokens.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = VDSFormControlsTokens.xcframework; path = ../SharedFrameworks/VDSFormControlsTokens.xcframework; sourceTree = ""; }; + EAA7456B2AB23E2000C1841F /* TooltipModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipModel.swift; sourceTree = ""; }; EAB1D29B28A5618900DAE764 /* RadioButtonGroup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonGroup.swift; sourceTree = ""; }; EAB1D2CC28ABE76000DAE764 /* Withable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Withable.swift; sourceTree = ""; }; EAB1D2CE28ABEF2B00DAE764 /* Typography+Base.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Typography+Base.swift"; sourceTree = ""; }; @@ -691,6 +693,7 @@ children = ( EAB2375C29E8789100AABE9A /* Tooltip.swift */, EA8E40922A82889500934ED3 /* TooltipDialog.swift */, + EAA7456B2AB23E2000C1841F /* TooltipModel.swift */, EAB2376729E9992800AABE9A /* TooltipAlertViewController.swift */, EAB2376929E9E59100AABE9A /* TooltipLaunchable.swift */, EAB2376129E9880400AABE9A /* TrailingTooltipLabel.swift */, @@ -979,6 +982,7 @@ EAF1FE9929D4850E00101452 /* Clickable.swift in Sources */, EAD0688E2A55F819002E3A2D /* Loader.swift in Sources */, EAB5FEF829393A7200998C17 /* ButtonGroupConstants.swift in Sources */, + EAA7456C2AB23E2000C1841F /* TooltipModel.swift in Sources */, EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, EA513A952A4E1F82002A4DFF /* TitleLockupStyleConfiguration.swift in Sources */, 44604AD729CE196600E62B51 /* Line.swift in Sources */, diff --git a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift index 26867749..a98024b1 100644 --- a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift @@ -20,10 +20,7 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable /// Current Surface and this is used to pass down to child objects that implement Surfacable 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 model: Tooltip.TooltipModel public var presenter: UIView? public func setAttribute(on attributedString: NSMutableAttributedString) { @@ -67,27 +64,24 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable attributedString.append(NSAttributedString(attachment: tooltip)) addHandler(on: attributedString) } - - public init(id: UUID = UUID(), subscriber: AnyCancellable? = nil, surface: Surface, accessibleText: String? = nil, closeButtonText: String = "Close", title: String? = nil, content: String? = nil, contentView: UIView? = nil, presenter: UIView? = nil) { + + public init(id: UUID = UUID(), + subscriber: AnyCancellable? = nil, + accessibleText: String? = nil, + surface: Surface = .light, + model: Tooltip.TooltipModel, + presenter: UIView? = nil) { self.id = id self.subscriber = subscriber self.surface = surface + self.model = model self.accessibleText = accessibleText - self.closeButtonText = closeButtonText - self.title = title - self.content = content - self.contentView = contentView self.presenter = presenter //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, - presenter: self.presenter) + self.presentTooltip(surface: surface, model: model, presenter: self.presenter) } } diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index f62e0694..aaf03256 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -124,7 +124,6 @@ open class EntryFieldBase: Control, Changeable { $0.textStyle = .bodySmall } - open var tooltipView: UIView? open var icon: Icon = Icon().with { $0.size = .small } @@ -149,12 +148,8 @@ open class EntryFieldBase: Control, Changeable { open var errorText: String? { didSet { setNeedsUpdate() } } - open var tooltipTitle: String? { didSet { setNeedsUpdate() } } - - open var tooltipContent: String? { didSet { setNeedsUpdate() } } - - open var tooltipContentView: UIView? { didSet { setNeedsUpdate() } } - + open var tooltipModel: Tooltip.TooltipModel? { didSet { setNeedsUpdate() } } + open var transparentBackground: Bool = false { didSet { setNeedsUpdate() } } open var width: CGFloat? { didSet { setNeedsUpdate() } } @@ -244,8 +239,7 @@ open class EntryFieldBase: Control, Changeable { helperText = nil showError = false errorText = nil - tooltipTitle = nil - tooltipContent = nil + tooltipModel = nil transparentBackground = false width = nil maxLength = nil @@ -299,8 +293,8 @@ open class EntryFieldBase: Control, Changeable { updatedLabelText = "\(oldText) Optional" } - if let tooltipTitle, let tooltipContent { - attributes.append(TooltipLabelAttribute(surface: surface, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView, presenter: self)) + if let tooltipModel { + attributes.append(TooltipLabelAttribute(surface: surface, model: tooltipModel, presenter: self)) } //set the titleLabel diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index 679c260e..1333cc7e 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -134,10 +134,10 @@ open class Tooltip: Control, TooltipLaunchable { .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, + model: .init(closeButtonText: tooltip.closeButtonText, + title: tooltip.title, + content: tooltip.content, + contentView: tooltip.contentView), presenter: self) }) } diff --git a/VDS/Components/Tooltip/TooltipAlertViewController.swift b/VDS/Components/Tooltip/TooltipAlertViewController.swift index 29a9aba7..b71d92cf 100644 --- a/VDS/Components/Tooltip/TooltipAlertViewController.swift +++ b/VDS/Components/Tooltip/TooltipAlertViewController.swift @@ -33,10 +33,7 @@ open class TooltipAlertViewController: UIViewController, Surfaceable { //-------------------------------------------------- /// Current Surface and this is used to pass down to child objects that implement Surfacable 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 closeButtonText: String = "Close" { didSet { updateView() }} + open var model = Tooltip.TooltipModel() { didSet { updateView() }} open var presenter: UIView? { didSet { updateView() }} //-------------------------------------------------- @@ -106,9 +103,6 @@ open class TooltipAlertViewController: UIViewController, Surfaceable { open func updateView() { view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.3) tooltipDialog.surface = surface - tooltipDialog.titleText = titleText - tooltipDialog.contentText = contentText - tooltipDialog.contentView = contentView - tooltipDialog.closeButtonText = closeButtonText + tooltipDialog.model = model } } diff --git a/VDS/Components/Tooltip/TooltipDialog.swift b/VDS/Components/Tooltip/TooltipDialog.swift index b79c453e..fa15325e 100644 --- a/VDS/Components/Tooltip/TooltipDialog.swift +++ b/VDS/Components/Tooltip/TooltipDialog.swift @@ -55,22 +55,18 @@ open class TooltipDialog: View, UIScrollViewDelegate { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - open var titleText: String? { didSet { setNeedsUpdate() } } + open var model = Tooltip.TooltipModel() { didSet { setNeedsUpdate() } } + open var titleLabel = Label().with { label in label.isAccessibilityElement = true label.textStyle = .boldTitleMedium } - open var contentText: String? { didSet { setNeedsUpdate() } } open var contentLabel = Label().with { label in label.isAccessibilityElement = true label.textStyle = .bodyLarge } - - open var contentView: UIView? = nil - - open var closeButtonText: String = "Close" { didSet { setNeedsUpdate() } } - + open lazy var closeButton: UIButton = { let button = UIButton(type: .system) button.isAccessibilityElement = true @@ -146,7 +142,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() - + backgroundColor = backgroundColorConfiguration.getColor(self) scrollView.indicatorStyle = surface == .light ? .black : .white @@ -156,24 +152,24 @@ open class TooltipDialog: View, UIScrollViewDelegate { contentLabel.surface = surface line.surface = surface - titleLabel.text = titleText - contentLabel.text = contentText + titleLabel.text = model.title + contentLabel.text = model.content titleLabel.sizeToFit() contentLabel.sizeToFit() var addedTitle = false - if let titleText, !titleText.isEmpty { + if let titleText = model.title, !titleText.isEmpty { contentStackView.addArrangedSubview(titleLabel) addedTitle = true } var addedContent = false - if let contentText, !contentText.isEmpty { + if let contentText = model.content, !contentText.isEmpty { contentStackView.addArrangedSubview(contentLabel) addedContent = true - } else if let contentView { + } else if let contentView = model.contentView { contentView.translatesAutoresizingMaskIntoConstraints = false if var surfaceable = contentView as? Surfaceable { surfaceable.surface = surface @@ -189,8 +185,8 @@ open class TooltipDialog: View, UIScrollViewDelegate { let closeButtonTextColor = closeButtonTextColorConfiguration.getColor(self) closeButton.setTitleColor(closeButtonTextColor, for: .normal) closeButton.setTitleColor(closeButtonTextColor, for: .highlighted) - closeButton.setTitle(closeButtonText, for: .normal) - closeButton.accessibilityLabel = closeButtonText + closeButton.setTitle(model.closeButtonText, for: .normal) + closeButton.accessibilityLabel = model.closeButtonText contentStackView.setNeedsLayout() contentStackView.layoutIfNeeded() @@ -224,7 +220,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { open override func updateAccessibility() { super.updateAccessibility() - primaryAccessibilityElement.accessibilityHint = "Double tap on the \(closeButtonText) button to close." + primaryAccessibilityElement.accessibilityHint = "Double tap on the \(model.closeButtonText) button to close." var elements: [Any] = [primaryAccessibilityElement] contentStackView.arrangedSubviews.forEach{ elements.append($0) } diff --git a/VDS/Components/Tooltip/TooltipLaunchable.swift b/VDS/Components/Tooltip/TooltipLaunchable.swift index 33d09b16..514110b4 100644 --- a/VDS/Components/Tooltip/TooltipLaunchable.swift +++ b/VDS/Components/Tooltip/TooltipLaunchable.swift @@ -9,18 +9,15 @@ import Foundation import UIKit public protocol TooltipLaunchable { - func presentTooltip(surface: Surface, title: String?, content: String?, contentView: UIView?, closeButtonText: String, presenter: UIView?) + func presentTooltip(surface: Surface, model: Tooltip.TooltipModel, presenter: UIView?) } extension TooltipLaunchable { - public func presentTooltip(surface: Surface, title: String?, content: String?, contentView: UIView? = nil, closeButtonText: String = "Close", presenter: UIView? = nil) { + public func presentTooltip(surface: Surface, model: Tooltip.TooltipModel, presenter: UIView? = nil) { 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.model = model $0.presenter = presenter $0.modalPresentationStyle = .overCurrentContext $0.modalTransitionStyle = .crossDissolve diff --git a/VDS/Components/Tooltip/TooltipModel.swift b/VDS/Components/Tooltip/TooltipModel.swift new file mode 100644 index 00000000..ee690d74 --- /dev/null +++ b/VDS/Components/Tooltip/TooltipModel.swift @@ -0,0 +1,33 @@ +// +// TooltipModel.swift +// VDS +// +// Created by Matt Bruce on 9/13/23. +// + +import Foundation +import UIKit + +extension Tooltip { + + /// Model used to represent the tooltip. + public struct TooltipModel { + /// Current Surface and this is used to pass down to child objects that implement Surfacable + public var closeButtonText: String + public var title: String? + public var content: String? + public var contentView: UIView? + public var contentViewAlignment: UIStackView.Alignment? + public init(closeButtonText: String = "Close", + title: String? = nil, + content: String? = nil, + contentView: UIView? = nil, + contentViewAlignment: UIStackView.Alignment = .leading) { + self.closeButtonText = closeButtonText + self.title = title + self.content = content + self.contentView = contentView + self.contentViewAlignment = contentViewAlignment + } + } +} diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 4ea09a90..f4701b24 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -29,11 +29,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { super.init(coder: coder) } - //-------------------------------------------------- - // MARK: - Private Properties - //-------------------------------------------------- - private let tooltipAction = PassthroughSubject() - //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- @@ -58,16 +53,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { }() { didSet { setNeedsUpdate() } } /// Will render the text for Close button for tooltip dialog when on mobile devices - open var tooltipCloseButtonText: String = "Close" { didSet { setNeedsUpdate() } } - - /// Text rendered for the title of the tooltip - open var tooltipTitle: String? { didSet { setNeedsUpdate() } } - - /// Text rendered for the content of the tooltip - open var tooltipContent: String? { didSet { setNeedsUpdate() } } - - /// UIView rendered for the content area of the tooltip - open var tooltipContentView: UIView? { didSet { setNeedsUpdate() } } + open var tooltipModel: Tooltip.TooltipModel? { didSet { setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Overrides @@ -79,15 +65,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { addSubview(label) label.pinToSuperView() - //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, - presenter: self) - }.store(in: &subscribers) } /// Used to make changes to the View based off a change events or from local properties. @@ -102,8 +79,8 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.isEnabled = isEnabled //add tooltip - if let labelText, !labelText.isEmpty { - label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView)) + if let labelText, let tooltipModel, !labelText.isEmpty { + label.addTooltip(model: tooltipModel) } } @@ -115,9 +92,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { labelAttributes = nil labelTextStyle = .defaultStyle labelTextAlignment = .left - tooltipCloseButtonText = "Close" - tooltipTitle = "" - tooltipContent = "" + tooltipModel = nil shouldUpdateView = true setNeedsUpdate() } @@ -125,25 +100,9 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { extension Label { - /// Model used to represent the tooltip. - public struct TooltipModel { - /// Current Surface and this is used to pass down to child objects that implement Surfacable - 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 - } - } /// Helper to add a tool tip attribute to an existing label. - public func addTooltip(model: TooltipModel) { + public func addTooltip(model: Tooltip.TooltipModel) { var newAttributes: [any LabelAttributeModel] = [] if let attributes { @@ -155,12 +114,7 @@ extension Label { } if let text = text, !text.isEmpty { - let tooltip = TooltipLabelAttribute(surface: surface, - closeButtonText: model.closeButtonText, - title: model.title, - content: model.content, - contentView: model.contentView, - presenter: self) + let tooltip = TooltipLabelAttribute(surface: surface, model: model, presenter: self) newAttributes.append(tooltip) } From fdb7e955e210db8f3998a90b7aecdb97b2b2e2fa Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 13 Sep 2023 17:40:54 -0500 Subject: [PATCH 5/6] refactored naming convention to tooltipModel Signed-off-by: Matt Bruce --- .../Attributes/TooltipLabelAttribute.swift | 2 +- VDS/Components/Tooltip/Tooltip.swift | 2 +- .../Tooltip/TooltipAlertViewController.swift | 4 ++-- VDS/Components/Tooltip/TooltipDialog.swift | 18 +++++++++--------- VDS/Components/Tooltip/TooltipLaunchable.swift | 6 +++--- .../Tooltip/TrailingTooltipLabel.swift | 6 +++--- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift index a98024b1..914a8783 100644 --- a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift @@ -81,7 +81,7 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable //create the tooltip click event self.subscriber = action.sink { [weak self] in guard let self else { return } - self.presentTooltip(surface: surface, model: model, presenter: self.presenter) + self.presentTooltip(surface: surface, tooltipModel: model, presenter: self.presenter) } } diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index 1333cc7e..5b8390c8 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -134,7 +134,7 @@ open class Tooltip: Control, TooltipLaunchable { .sink(receiveValue: { [weak self] tooltip in guard let self else { return} self.presentTooltip(surface: tooltip.surface, - model: .init(closeButtonText: tooltip.closeButtonText, + tooltipModel: .init(closeButtonText: tooltip.closeButtonText, title: tooltip.title, content: tooltip.content, contentView: tooltip.contentView), diff --git a/VDS/Components/Tooltip/TooltipAlertViewController.swift b/VDS/Components/Tooltip/TooltipAlertViewController.swift index b71d92cf..60300997 100644 --- a/VDS/Components/Tooltip/TooltipAlertViewController.swift +++ b/VDS/Components/Tooltip/TooltipAlertViewController.swift @@ -33,7 +33,7 @@ open class TooltipAlertViewController: UIViewController, Surfaceable { //-------------------------------------------------- /// Current Surface and this is used to pass down to child objects that implement Surfacable open var surface: Surface = .light { didSet { updateView() }} - open var model = Tooltip.TooltipModel() { didSet { updateView() }} + open var tooltipModel = Tooltip.TooltipModel() { didSet { updateView() }} open var presenter: UIView? { didSet { updateView() }} //-------------------------------------------------- @@ -103,6 +103,6 @@ open class TooltipAlertViewController: UIViewController, Surfaceable { open func updateView() { view.backgroundColor = backgroundColorConfiguration.getColor(self).withAlphaComponent(0.3) tooltipDialog.surface = surface - tooltipDialog.model = model + tooltipDialog.tooltipModel = tooltipModel } } diff --git a/VDS/Components/Tooltip/TooltipDialog.swift b/VDS/Components/Tooltip/TooltipDialog.swift index fa15325e..a3db25c3 100644 --- a/VDS/Components/Tooltip/TooltipDialog.swift +++ b/VDS/Components/Tooltip/TooltipDialog.swift @@ -55,7 +55,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - open var model = Tooltip.TooltipModel() { didSet { setNeedsUpdate() } } + open var tooltipModel = Tooltip.TooltipModel() { didSet { setNeedsUpdate() } } open var titleLabel = Label().with { label in label.isAccessibilityElement = true @@ -152,24 +152,24 @@ open class TooltipDialog: View, UIScrollViewDelegate { contentLabel.surface = surface line.surface = surface - titleLabel.text = model.title - contentLabel.text = model.content + titleLabel.text = tooltipModel.title + contentLabel.text = tooltipModel.content titleLabel.sizeToFit() contentLabel.sizeToFit() var addedTitle = false - if let titleText = model.title, !titleText.isEmpty { + if let titleText = tooltipModel.title, !titleText.isEmpty { contentStackView.addArrangedSubview(titleLabel) addedTitle = true } var addedContent = false - if let contentText = model.content, !contentText.isEmpty { + if let contentText = tooltipModel.content, !contentText.isEmpty { contentStackView.addArrangedSubview(contentLabel) addedContent = true - } else if let contentView = model.contentView { + } else if let contentView = tooltipModel.contentView { contentView.translatesAutoresizingMaskIntoConstraints = false if var surfaceable = contentView as? Surfaceable { surfaceable.surface = surface @@ -185,8 +185,8 @@ open class TooltipDialog: View, UIScrollViewDelegate { let closeButtonTextColor = closeButtonTextColorConfiguration.getColor(self) closeButton.setTitleColor(closeButtonTextColor, for: .normal) closeButton.setTitleColor(closeButtonTextColor, for: .highlighted) - closeButton.setTitle(model.closeButtonText, for: .normal) - closeButton.accessibilityLabel = model.closeButtonText + closeButton.setTitle(tooltipModel.closeButtonText, for: .normal) + closeButton.accessibilityLabel = tooltipModel.closeButtonText contentStackView.setNeedsLayout() contentStackView.layoutIfNeeded() @@ -220,7 +220,7 @@ open class TooltipDialog: View, UIScrollViewDelegate { open override func updateAccessibility() { super.updateAccessibility() - primaryAccessibilityElement.accessibilityHint = "Double tap on the \(model.closeButtonText) button to close." + primaryAccessibilityElement.accessibilityHint = "Double tap on the \(tooltipModel.closeButtonText) button to close." var elements: [Any] = [primaryAccessibilityElement] contentStackView.arrangedSubviews.forEach{ elements.append($0) } diff --git a/VDS/Components/Tooltip/TooltipLaunchable.swift b/VDS/Components/Tooltip/TooltipLaunchable.swift index 514110b4..bcd988b8 100644 --- a/VDS/Components/Tooltip/TooltipLaunchable.swift +++ b/VDS/Components/Tooltip/TooltipLaunchable.swift @@ -9,15 +9,15 @@ import Foundation import UIKit public protocol TooltipLaunchable { - func presentTooltip(surface: Surface, model: Tooltip.TooltipModel, presenter: UIView?) + func presentTooltip(surface: Surface, tooltipModel: Tooltip.TooltipModel, presenter: UIView?) } extension TooltipLaunchable { - public func presentTooltip(surface: Surface, model: Tooltip.TooltipModel, presenter: UIView? = nil) { + public func presentTooltip(surface: Surface, tooltipModel: Tooltip.TooltipModel, presenter: UIView? = nil) { if let presenting = UIApplication.topViewController() { let tooltipViewController = TooltipAlertViewController(nibName: nil, bundle: nil).with { $0.surface = surface - $0.model = model + $0.tooltipModel = tooltipModel $0.presenter = presenter $0.modalPresentationStyle = .overCurrentContext $0.modalTransitionStyle = .crossDissolve diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index f4701b24..f1f26abc 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -80,7 +80,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { //add tooltip if let labelText, let tooltipModel, !labelText.isEmpty { - label.addTooltip(model: tooltipModel) + label.addTooltip(tooltipModel) } } @@ -102,7 +102,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { extension Label { /// Helper to add a tool tip attribute to an existing label. - public func addTooltip(model: Tooltip.TooltipModel) { + public func addTooltip(_ tooltipModel: Tooltip.TooltipModel) { var newAttributes: [any LabelAttributeModel] = [] if let attributes { @@ -114,7 +114,7 @@ extension Label { } if let text = text, !text.isEmpty { - let tooltip = TooltipLabelAttribute(surface: surface, model: model, presenter: self) + let tooltip = TooltipLabelAttribute(surface: surface, model: tooltipModel, presenter: self) newAttributes.append(tooltip) } From ad6c00214e83bc821faecc4c6c061f1823f4ef38 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 14 Sep 2023 08:31:51 -0500 Subject: [PATCH 6/6] removing touchUpInsideCount, since now we are keying off of onClickSubscriber Signed-off-by: Matt Bruce --- VDS/BaseClasses/Control.swift | 4 +--- VDS/Components/Buttons/ButtonBase.swift | 4 +--- VDS/Protocols/Clickable.swift | 2 -- VDS/Publishers/UIControlPublisher.swift | 11 ----------- 4 files changed, 2 insertions(+), 19 deletions(-) diff --git a/VDS/BaseClasses/Control.swift b/VDS/BaseClasses/Control.swift index b2f3d4ae..e9535f1a 100644 --- a/VDS/BaseClasses/Control.swift +++ b/VDS/BaseClasses/Control.swift @@ -62,15 +62,13 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { /// Whether the Control can handle the isHighlighted state. open var canHighlight: Bool = true - - open var touchUpInsideCount: Int = 0 var isHighlightAnimating = false /// Whether the Control is highlighted or not. open override var isHighlighted: Bool { didSet { - if canHighlight && isHighlightAnimating == false && touchUpInsideCount > 0 { + if canHighlight && isHighlightAnimating == false && onClickSubscriber != nil { isHighlightAnimating = true UIView.animate(withDuration: 0.1, animations: { [weak self] in self?.setNeedsUpdate() diff --git a/VDS/Components/Buttons/ButtonBase.swift b/VDS/Components/Buttons/ButtonBase.swift index e505b7f8..2c377d1c 100644 --- a/VDS/Components/Buttons/ButtonBase.swift +++ b/VDS/Components/Buttons/ButtonBase.swift @@ -96,15 +96,13 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { open var useScaledFont: Bool = false { didSet { setNeedsUpdate() } } open var userInfo = [String: Primitive]() - - open var touchUpInsideCount: Int = 0 internal var isHighlightAnimating = false /// Whether the Control is highlighted or not. open override var isHighlighted: Bool { didSet { - if isHighlightAnimating == false && touchUpInsideCount > 0 { + if isHighlightAnimating == false && onClickSubscriber != nil { isHighlightAnimating = true UIView.animate(withDuration: 0.1, animations: { [weak self] in self?.setNeedsUpdate() diff --git a/VDS/Protocols/Clickable.swift b/VDS/Protocols/Clickable.swift index 50445dc0..b8c49a88 100644 --- a/VDS/Protocols/Clickable.swift +++ b/VDS/Protocols/Clickable.swift @@ -10,8 +10,6 @@ import UIKit import Combine public protocol Clickable: ViewProtocol where Self: UIControl { - /// Reference count used when a subscriber is listening for the UIControl event .touchUpInside. - var touchUpInsideCount: Int { get set } /// Sets the primary Subscriber used for the UIControl event .touchUpInside. var onClickSubscriber: AnyCancellable? { get set } } diff --git a/VDS/Publishers/UIControlPublisher.swift b/VDS/Publishers/UIControlPublisher.swift index 6b8fa45d..711966f0 100644 --- a/VDS/Publishers/UIControlPublisher.swift +++ b/VDS/Publishers/UIControlPublisher.swift @@ -20,10 +20,6 @@ public final class UIControlSubscription 0 { - c.touchUpInsideCount -= 1 - } - } @objc private func eventHandler() { _ = subscriber?.receive(control)