From d4d1b8d7c95f1606a0ccf7131fe75737d78422ad Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Sat, 12 Aug 2023 09:35:16 -0500 Subject: [PATCH 01/54] fix for button Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/Button.swift | 47 +++++++++------------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index f81e3b40..b91f1a5c 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -22,9 +22,6 @@ open class Button: ButtonBase, Useable { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var minWidthConstraint: NSLayoutConstraint? - private var widthConstraint: NSLayoutConstraint? - private var heightConstraint: NSLayoutConstraint? private var initialSetupPerformed = false //-------------------------------------------------- @@ -36,7 +33,18 @@ open class Button: ButtonBase, Useable { open var size: ButtonSize = .large { didSet { setNeedsUpdate() }} - open var width: CGFloat? { didSet { setNeedsUpdate() }} + private var _width: CGFloat? = nil + open var width: CGFloat? { + get { _width } + set { + if let newValue, newValue > size.minimumWidth { + _width = newValue + } else { + _width = nil + } + setNeedsUpdate() + } + } open override var textColor: UIColor { textColorConfiguration.getColor(self) @@ -120,14 +128,6 @@ open class Button: ButtonBase, Useable { super.setup() isAccessibilityElement = true accessibilityTraits = .button - - //only 1 of the 2 widths can be on at the same time - widthConstraint = widthAnchor.constraint(equalToConstant: 0) - minWidthConstraint = widthAnchor.constraint(greaterThanOrEqualToConstant: size.minimumWidth) - - //height - heightConstraint = heightAnchor.constraint(equalToConstant: 0) - heightConstraint?.isActive = true } /// Resets to default settings. @@ -145,7 +145,12 @@ open class Button: ButtonBase, Useable { // MARK: - Overrides //-------------------------------------------------- open override var intrinsicContentSize: CGSize { - guard let width, width > 0 else { return super.intrinsicContentSize } + guard let width, width > 0 else { + var superSize = super.intrinsicContentSize + superSize.height = size.height + return superSize + } + return CGSize(width: width > size.minimumWidth ? width : size.minimumWidth, height: size.height) } @@ -156,9 +161,7 @@ open class Button: ButtonBase, Useable { let bgColor = backgroundColorConfiguration.getColor(self) let borderColor = borderColorConfiguration.getColor(self) let borderWidth = use == .secondary ? VDSFormControls.widthBorder : 0.0 - let buttonHeight = size.height let cornerRadius = size.cornerRadius - let minWidth = size.minimumWidth let edgeInsets = size.edgeInsets backgroundColor = bgColor @@ -166,18 +169,8 @@ open class Button: ButtonBase, Useable { layer.cornerRadius = cornerRadius layer.borderWidth = borderWidth contentEdgeInsets = edgeInsets - - minWidthConstraint?.constant = minWidth - heightConstraint?.constant = buttonHeight - - if let width, width > minWidth { - widthConstraint?.constant = width - widthConstraint?.isActive = true - minWidthConstraint?.isActive = false - } else { - widthConstraint?.isActive = false - minWidthConstraint?.isActive = true - } + + invalidateIntrinsicContentSize() } } From f73de3734bb9bd4a331940eaf4ab072eb81d5f9e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 14 Aug 2023 09:03:13 -0500 Subject: [PATCH 02/54] refactored inset to private, update constraints Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index bf2ff583..5f997c45 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -56,6 +56,11 @@ open class Badge: View { //-------------------------------------------------- // MARK: - Configuration //-------------------------------------------------- + private var minWidth: CGFloat = 23.0 + private var labelInset: UIEdgeInsets = .init(top: 2, + left: VDSLayout.Spacing.space1X.value, + bottom: 2, + right: VDSLayout.Spacing.space1X.value) /// ColorConfiguration that is mapped to the 'fillColor' for the surface. private var backgroundColorConfiguration: AnyColorable = { @@ -104,13 +109,10 @@ open class Badge: View { layer.cornerRadius = 2 addSubview(label) - label.pinToSuperView(.init(top: 2, - left: VDSLayout.Spacing.space1X.value, - bottom: 2, - right: VDSLayout.Spacing.space1X.value)) + label.pinToSuperView(labelInset) - maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 100) - minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: 23) + maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 0) + minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) minWidthConstraint?.isActive = true } @@ -145,11 +147,13 @@ open class Badge: View { label.surface = surface label.disabled = disabled - if let maxWidth = maxWidth, let minWidth = minWidthConstraint?.constant, maxWidth > minWidth { + if let maxWidth = maxWidth, maxWidth > minWidth { maxWidthConstraint?.constant = maxWidth maxWidthConstraint?.isActive = true + minWidthConstraint?.isActive = false } else { maxWidthConstraint?.isActive = false + minWidthConstraint?.isActive = true } } } From 970ea12bc255bbef2a016bb63dfe0a1fa74fe813 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 14 Aug 2023 09:10:49 -0500 Subject: [PATCH 03/54] update toggle shadows for disabled Signed-off-by: Matt Bruce --- VDS/Components/Toggle/ToggleView.swift | 28 +++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index bc17ffe3..fa217963 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -145,20 +145,7 @@ open class ToggleView: Control, Changeable { // Update shadow layers frames to match the view's bounds knobView.layer.insertSublayer(shadowLayer1, at: 0) knobView.layer.insertSublayer(shadowLayer2, at: 0) - - let shadowColor = VDSColor.paletteBlack.cgColor - shadowLayer1.cornerRadius = knobView.layer.cornerRadius - shadowLayer1.shadowColor = shadowColor - shadowLayer1.shadowOpacity = 0.24 - shadowLayer1.shadowOffset = .init(width: 0, height: 1) - shadowLayer1.shadowRadius = 5.0 - - shadowLayer2.cornerRadius = knobView.layer.cornerRadius - shadowLayer2.shadowColor = shadowColor - shadowLayer2.shadowOpacity = 0.08 - shadowLayer2.shadowOffset = .init(width: 0, height: 2) - shadowLayer2.shadowRadius = 2.0 - + } /// Resets to default settings. @@ -246,6 +233,19 @@ open class ToggleView: Control, Changeable { shadowLayer1.frame = knobView.bounds shadowLayer2.frame = knobView.bounds + + let shadowColor = isEnabled ? VDSColor.paletteBlack.cgColor : VDSColor.paletteGray95.cgColor + shadowLayer1.cornerRadius = knobView.layer.cornerRadius + shadowLayer1.shadowColor = shadowColor + shadowLayer1.shadowOpacity = isEnabled ? 0.24 : 0.1 + shadowLayer1.shadowOffset = .init(width: 0, height: 1) + shadowLayer1.shadowRadius = isEnabled ? 5.0 : 10.0 + + shadowLayer2.cornerRadius = knobView.layer.cornerRadius + shadowLayer2.shadowColor = shadowColor + shadowLayer2.shadowOpacity = isEnabled ? 0.08 : 0.04 + shadowLayer2.shadowOffset = .init(width: 0, height: 2) + shadowLayer2.shadowRadius = 2.0 } } From 3e3baac6098f21ff166518534edc05b87a0fe630 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 14 Aug 2023 15:17:45 -0500 Subject: [PATCH 04/54] refactored to for orientation Signed-off-by: Matt Bruce --- VDS/Components/Line/Line.swift | 42 ++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/VDS/Components/Line/Line.swift b/VDS/Components/Line/Line.swift index c9c33aba..ffef28b5 100644 --- a/VDS/Components/Line/Line.swift +++ b/VDS/Components/Line/Line.swift @@ -19,14 +19,21 @@ open class Line: View { case primary, secondary } + public enum Orientation: String, CaseIterable { + case horizontal, vertical + } + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - open var lineView = UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - open var style: Style = .primary { didSet { setNeedsUpdate() } } + open var orientation: Orientation = .horizontal { didSet { setNeedsUpdate() } } + + //-------------------------------------------------- + // MARK: - Private Properties + //-------------------------------------------------- + private var heightConstraint: NSLayoutConstraint? + private var widthConstraint: NSLayoutConstraint? //-------------------------------------------------- // MARK: - Configuration @@ -41,25 +48,32 @@ open class Line: View { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - - open override func setup() { - super.setup() - - addSubview(lineView) - lineView.height(1) - lineView.pinToSuperView() - } - /// Resets to default settings. open override func reset() { super.reset() style = .primary + orientation = .horizontal + } + + open override func setup() { + super.setup() + + heightConstraint = heightAnchor.constraint(equalToConstant: 1) + widthConstraint = widthAnchor.constraint(equalToConstant: 1) } /// Function used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() - lineView.backgroundColor = lineViewColorConfiguration.getColor(self) + if orientation == .vertical { + heightConstraint?.isActive = false + widthConstraint?.isActive = true + } else { + widthConstraint?.isActive = false + heightConstraint?.isActive = true + } + + backgroundColor = lineViewColorConfiguration.getColor(self) } } From 1bd254668f3bd8f3d355720237ef60584e11a6fd Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 15 Aug 2023 08:39:56 -0500 Subject: [PATCH 05/54] bug for icon Signed-off-by: Matt Bruce --- VDS/Components/Icon/Icon.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 0c496793..96a42903 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -24,6 +24,8 @@ open class Icon: View { //-------------------------------------------------- open var imageView = UIImageView().with { $0.translatesAutoresizingMaskIntoConstraints = false + $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.setContentCompressionResistancePriority(.required, for: .horizontal) $0.contentMode = .scaleAspectFill $0.clipsToBounds = true } From 5cda9843d1825788a57f9f3a692504c6e87a60a9 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 15 Aug 2023 08:43:16 -0500 Subject: [PATCH 06/54] updated badge Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 5f997c45..70111855 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -27,7 +27,10 @@ open class Badge: View { /// Label used to render text open var label = Label().with { + $0.setContentHuggingPriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.setContentHuggingPriority(.required, for: .horizontal) + $0.setContentCompressionResistancePriority(.required, for: .horizontal) $0.adjustsFontSizeToFitWidth = false $0.lineBreakMode = .byTruncatingTail $0.textPosition = .left @@ -140,12 +143,6 @@ open class Badge: View { updateTextColorConfig() backgroundColor = backgroundColorConfiguration.getColor(self) - - label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() - label.numberOfLines = numberOfLines - label.text = text - label.surface = surface - label.disabled = disabled if let maxWidth = maxWidth, maxWidth > minWidth { maxWidthConstraint?.constant = maxWidth @@ -155,5 +152,11 @@ open class Badge: View { maxWidthConstraint?.isActive = false minWidthConstraint?.isActive = true } + + label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() + label.numberOfLines = numberOfLines + label.text = text + label.surface = surface + label.disabled = disabled } } From 0f6a80a3bea404f2b41c4846633908cef019289e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 15 Aug 2023 13:47:31 -0500 Subject: [PATCH 07/54] added debug logic Signed-off-by: Matt Bruce --- VDS/Classes/BundleManager.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/VDS/Classes/BundleManager.swift b/VDS/Classes/BundleManager.swift index 50537c0d..c5b90dd4 100644 --- a/VDS/Classes/BundleManager.swift +++ b/VDS/Classes/BundleManager.swift @@ -9,6 +9,14 @@ import Foundation import UIKit +public func DebugLog(_ message: String, file: String = #file, line: Int = #line, function: String = #function) { + #if DEBUG + let path = (file as NSString).lastPathComponent + // using print because NSLog crashes when passing certain optionals + print("[\(path)] \(function) [Line \(line)] : \(message)") + #endif +} + /// Bundle Manager keeps all bundles together for ease of use for searching within any of them for a specific asset public class BundleManager { public static var shared = BundleManager() From d1a74ea3870cb7814305b075a7b4d96f08daf78e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 15 Aug 2023 13:48:51 -0500 Subject: [PATCH 08/54] added self Signed-off-by: Matt Bruce --- VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 99aef7f5..ed3a2c15 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -130,12 +130,13 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega //-------------------------------------------------- // MARK: - Public Functions //-------------------------------------------------- + open override func setup() { super.setup() addSubview(collectionView) collectionView.pinToSuperView() } - + //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -149,10 +150,11 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega open override func layoutSubviews() { super.layoutSubviews() - // Accounts for any collection size changes - DispatchQueue.main.async { - self.collectionView.collectionViewLayout.invalidateLayout() - } +// // Accounts for any collection size changes +// DispatchQueue.main.async { [weak self] in +// guard let self else { return } +// self.collectionView.collectionViewLayout.invalidateLayout() +// } } //-------------------------------------------------- From 0f8ab501921145f2e2768c6450857556b7216e24 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 16 Aug 2023 08:27:11 -0500 Subject: [PATCH 09/54] fixed layout issues Signed-off-by: Matt Bruce --- VDS/Components/Loader/Loader.swift | 9 ++++++++- VDS/Components/TitleLockup/TitleLockup.swift | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Loader/Loader.swift b/VDS/Components/Loader/Loader.swift index 9c67b6e2..dbaa1349 100644 --- a/VDS/Components/Loader/Loader.swift +++ b/VDS/Components/Loader/Loader.swift @@ -27,7 +27,14 @@ open class Loader: View { open var isActive: Bool = true { didSet { setNeedsUpdate() } } /// The Int used to determine the height and width of the Loader - open var size: Int = 40 { didSet { setNeedsUpdate() } } + open var size: Int = 40 { + didSet { + setNeedsUpdate(); + invalidateIntrinsicContentSize() + } + } + + open override var intrinsicContentSize: CGSize { .init(width: size, height: size) } //-------------------------------------------------- // MARK: - Lifecycle diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index bf3ea8f0..1b2b1af4 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -43,7 +43,7 @@ open class TitleLockup: View { private var stackView = UIStackView().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.axis = .vertical - $0.distribution = .fill + $0.distribution = .fillProportionally } private var otherStandardStyle: OtherStandardStyle { @@ -311,7 +311,6 @@ open class TitleLockup: View { eyebrowLabel.attributes = eyebrowModel.textAttributes eyebrowLabel.numberOfLines = eyebrowModel.numberOfLines eyebrowLabel.surface = surface - //When uniform size is true if let titleModel, isUniformSize { if titleModel.isBold { @@ -329,6 +328,7 @@ open class TitleLockup: View { eyebrowLabel.textColorConfiguration = textColorPrimaryConfiguration eyebrowLabel.textStyle = eyebrowModel.isBold ? otherStandardStyle.value.bold : otherStandardStyle.value.regular } + eyebrowLabel.sizeToFit() } else { eyebrowLabel.reset() } @@ -341,6 +341,7 @@ open class TitleLockup: View { titleLabel.attributes = titleModel.textAttributes titleLabel.numberOfLines = titleModel.numberOfLines titleLabel.surface = surface + titleLabel.sizeToFit() } else { titleLabel.reset() } @@ -354,6 +355,7 @@ open class TitleLockup: View { subTitleLabel.attributes = subTitleModel.textAttributes subTitleLabel.numberOfLines = subTitleModel.numberOfLines subTitleLabel.surface = surface + subTitleLabel.sizeToFit() } else { subTitleLabel.reset() } From 3ca168a53b85e2eea385a075312267e7d1101a48 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 16 Aug 2023 08:38:31 -0500 Subject: [PATCH 10/54] added canHighlight Signed-off-by: Matt Bruce --- VDS/Classes/Control.swift | 7 +++++-- VDS/Components/Tabs/Tab.swift | 3 +++ VDS/Components/Toggle/Toggle.swift | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 10eb8ef9..1acca2d5 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -52,7 +52,10 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { /// Whether the Control is selected or not. open override var isSelected: Bool { didSet { setNeedsUpdate() } } - + + /// Whether the Control can handle the isHighlighted state. + open var canHighlight: Bool = true + open var touchUpInsideCount: Int = 0 var isHighlightAnimating = false @@ -60,7 +63,7 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { /// Whether the Control is highlighted or not.. open override var isHighlighted: Bool { didSet { - if isHighlightAnimating == false && touchUpInsideCount > 0 { + if canHighlight && isHighlightAnimating == false && touchUpInsideCount > 0 { isHighlightAnimating = true UIView.animate(withDuration: 0.1, animations: { [weak self] in self?.setNeedsUpdate() diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index d33bea63..7369202f 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -124,6 +124,9 @@ extension Tabs { open override func setup() { super.setup() + + canHighlight = false + addLayoutGuide(layoutGuide) addSubview(label) accessibilityTraits = .button diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 82a602b2..c4194496 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -140,7 +140,8 @@ open class Toggle: Control, Changeable { open override func setup() { super.setup() - + + canHighlight = false isAccessibilityElement = true accessibilityTraits = .button addSubview(label) From d5489dc9afbbff74d2694ca3d0aa12ab76ef7ae2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 17 Aug 2023 13:50:53 -0500 Subject: [PATCH 11/54] updated logic Signed-off-by: Matt Bruce --- VDS/Components/Icon/Icon.swift | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 96a42903..68ba7f97 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -19,13 +19,20 @@ open class Icon: View { private var widthConstraint: NSLayoutConstraint? private var heightConstraint: NSLayoutConstraint? + private var dimensions: CGSize { + guard let customSize else { return size.dimensions } + return .init(width: customSize, height: customSize) + } + //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- open var imageView = UIImageView().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.setContentHuggingPriority(.required, for: .vertical) $0.setContentCompressionResistancePriority(.required, for: .horizontal) + $0.setContentHuggingPriority(.required, for: .horizontal) $0.contentMode = .scaleAspectFill $0.clipsToBounds = true } @@ -44,7 +51,7 @@ open class Icon: View { //functions //-------------------------------------------------- - // MARK: - Lifecycle + // MARK: - Overrides //-------------------------------------------------- open override func setup() { @@ -85,12 +92,6 @@ open class Icon: View { } //set the icon dimensions - var dimensions = size.dimensions - - if let customSize { - dimensions = .init(width: customSize, height: customSize) - } - heightConstraint?.constant = dimensions.height widthConstraint?.constant = dimensions.width @@ -101,8 +102,9 @@ open class Icon: View { } else { imageView.image = nil } + } - + private func getImage(for imageName: String) -> UIImage? { return BundleManager.shared.image(for: imageName) From e186b77763598fcadd65f5964cc9c8d09e94e700 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 17 Aug 2023 14:16:50 -0500 Subject: [PATCH 12/54] refactored tooltip to use icon Signed-off-by: Matt Bruce --- VDS/Components/Tabs/Tabs.swift | 2 +- VDS/Components/Tooltip/Tooltip.swift | 34 ++++++++-------------------- 2 files changed, 11 insertions(+), 25 deletions(-) diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index 548178e5..928daa8d 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -200,7 +200,7 @@ open class Tabs: View { /// Function used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() - + updateStackView() updateTabs() updateContentView() diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index c522137f..d3adc11d 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -38,10 +38,10 @@ open class Tooltip: Control, TooltipLaunchable { //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- - open var imageView = UIImageView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - $0.contentMode = .scaleAspectFill - $0.clipsToBounds = true + open var icon = Icon().with { + $0.name = .info + $0.size = .small + $0.isUserInteractionEnabled = false } open var closeButtonText: String = "Close" { didSet { setNeedsUpdate() }} @@ -111,18 +111,8 @@ open class Tooltip: Control, TooltipLaunchable { open override func setup() { super.setup() - if let image = BundleManager.shared.image(for: "info") { - infoImage = image - } - - addSubview(imageView) - - imageView.pinToSuperView() - heightConstraint = imageView.heightAnchor.constraint(equalToConstant: size.value.dimensions.height) - heightConstraint?.isActive = true - widthConstraint = imageView.widthAnchor.constraint(equalToConstant: size.value.dimensions.width) - widthConstraint?.isActive = true - + addSubview(icon) + icon.pinToSuperView() backgroundColor = .clear isAccessibilityElement = true @@ -149,7 +139,6 @@ open class Tooltip: Control, TooltipLaunchable { content = "" fillColor = .primary closeButtonText = "Close" - imageView.image = nil shouldUpdateView = true setNeedsUpdate() } @@ -157,15 +146,12 @@ open class Tooltip: Control, TooltipLaunchable { /// Function used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() - - //set the dimensions - let dimensions = size.value.dimensions - heightConstraint?.constant = dimensions.height - widthConstraint?.constant = dimensions.width + + //get the size + icon.size = size.value //get the color for the image - let imageColor = iconColorConfiguration.getColor(self) - imageView.image = infoImage.withTintColor(imageColor) + icon.color = iconColorConfiguration.getColor(self) } open override func updateAccessibility() { From 32017ea803acad7b95ba54d5c3e7c4d46250689f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 17 Aug 2023 15:01:48 -0500 Subject: [PATCH 13/54] fixed constraints Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index c4194496..aa3eb40f 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -158,17 +158,20 @@ open class Toggle: Control, Changeable { labelConstraints = [ heightEqual, heightGreater, - label.widthAnchor.constraint(lessThanOrEqualToConstant: labelMaxWidth), label.topAnchor.constraint(equalTo: topAnchor), label.bottomAnchor.constraint(equalTo: bottomAnchor), ] leftConstraints = [ - toggleView.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: spacingBetween) + toggleView.leadingAnchor.constraint(equalTo: label.trailingAnchor, constant: spacingBetween), + label.leadingAnchor.constraint(equalTo: leadingAnchor), + toggleView.trailingAnchor.constraint(equalTo: trailingAnchor) ] rightConstraints = [ - label.leadingAnchor.constraint(equalTo: toggleView.trailingAnchor, constant: spacingBetween) + toggleView.leadingAnchor.constraint(equalTo: leadingAnchor), + label.leadingAnchor.constraint(equalTo: toggleView.trailingAnchor, constant: spacingBetween), + label.trailingAnchor.constraint(equalTo: trailingAnchor) ] } From a93edcc5ea5ab6b5f225a609a0ce13c20c4edd92 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 18 Aug 2023 16:15:41 -0500 Subject: [PATCH 14/54] fixed bug Signed-off-by: Matt Bruce --- VDS/Components/Toggle/ToggleView.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index fa217963..2be8ac0f 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -201,8 +201,6 @@ open class ToggleView: Control, Changeable { } knobTrailingConstraint?.isActive = true knobLeadingConstraint?.isActive = true - setNeedsLayout() - layoutIfNeeded() } private func updateToggle() { From efc15eabdf12c308adef12034e70b5a76c415a2d Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 18 Aug 2023 16:16:05 -0500 Subject: [PATCH 15/54] added label width and update anchor on right Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index aa3eb40f..e329c256 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -153,6 +153,10 @@ open class Toggle: Control, Changeable { let heightGreater = heightAnchor.constraint(greaterThanOrEqualToConstant: toggleContainerSize.height) heightGreater.priority = .defaultHigh + let labelWidth = label.widthAnchor.constraint(lessThanOrEqualToConstant: labelMaxWidth) + labelWidth.priority = .required + labelWidth.isActive = true + // Set up initial constraints for label and switch toggleView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true @@ -171,7 +175,7 @@ open class Toggle: Control, Changeable { rightConstraints = [ toggleView.leadingAnchor.constraint(equalTo: leadingAnchor), label.leadingAnchor.constraint(equalTo: toggleView.trailingAnchor, constant: spacingBetween), - label.trailingAnchor.constraint(equalTo: trailingAnchor) + label.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor) ] } @@ -227,6 +231,7 @@ open class Toggle: Control, Changeable { private var showLabel: Bool { showText && !statusText.isEmpty } + private func updateLabel() { label.isHidden = !showLabel @@ -250,7 +255,6 @@ open class Toggle: Control, Changeable { NSLayoutConstraint.deactivate(rightConstraints) NSLayoutConstraint.deactivate(labelConstraints) } - invalidateIntrinsicContentSize() } //-------------------------------------------------- From 28db6509cc107a67f4ab31c4589e9428424c3fef Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 18 Aug 2023 16:33:14 -0500 Subject: [PATCH 16/54] used intrinsicSize for line Signed-off-by: Matt Bruce --- VDS/Components/Line/Line.swift | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/VDS/Components/Line/Line.swift b/VDS/Components/Line/Line.swift index ffef28b5..e64e7406 100644 --- a/VDS/Components/Line/Line.swift +++ b/VDS/Components/Line/Line.swift @@ -29,12 +29,6 @@ open class Line: View { open var style: Style = .primary { didSet { setNeedsUpdate() } } open var orientation: Orientation = .horizontal { didSet { setNeedsUpdate() } } - //-------------------------------------------------- - // MARK: - Private Properties - //-------------------------------------------------- - private var heightConstraint: NSLayoutConstraint? - private var widthConstraint: NSLayoutConstraint? - //-------------------------------------------------- // MARK: - Configuration //-------------------------------------------------- @@ -44,10 +38,19 @@ open class Line: View { config.setSurfaceColors(VDSColor.elementsLowcontrastOnlight, VDSColor.elementsLowcontrastOndark, forKey: .secondary) return config.eraseToAnyColorable() }() - + //-------------------------------------------------- - // MARK: - Lifecycle + // MARK: - Overrides //-------------------------------------------------- + + open override var intrinsicContentSize: CGSize { + if orientation == .vertical { + return .init(width: 1, height: bounds.height) + } else { + return .init(width: bounds.width, height: 1) + } + } + /// Resets to default settings. open override func reset() { super.reset() @@ -57,23 +60,15 @@ open class Line: View { open override func setup() { super.setup() - - heightConstraint = heightAnchor.constraint(equalToConstant: 1) - widthConstraint = widthAnchor.constraint(equalToConstant: 1) } /// Function used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() - - if orientation == .vertical { - heightConstraint?.isActive = false - widthConstraint?.isActive = true - } else { - widthConstraint?.isActive = false - heightConstraint?.isActive = true - } backgroundColor = lineViewColorConfiguration.getColor(self) + + invalidateIntrinsicContentSize() } + } From 6f7fb965e50bda7ade3bb69d81eaa9787cdc8be7 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 21 Aug 2023 13:25:21 -0500 Subject: [PATCH 17/54] removed view and added line Signed-off-by: Matt Bruce --- .../Buttons/ButtonGroup/ButtonGroup.swift | 15 ++++++++----- .../Buttons/TextLink/TextLink.swift | 22 +++---------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index ed3a2c15..fba66594 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -135,6 +135,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega super.setup() addSubview(collectionView) collectionView.pinToSuperView() + backgroundColor = .red } //-------------------------------------------------- @@ -150,11 +151,11 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega open override func layoutSubviews() { super.layoutSubviews() -// // Accounts for any collection size changes -// DispatchQueue.main.async { [weak self] in -// guard let self else { return } -// self.collectionView.collectionViewLayout.invalidateLayout() -// } + // Accounts for any collection size changes + DispatchQueue.main.async { [weak self] in + guard let self else { return } + self.collectionView.collectionViewLayout.invalidateLayout() + } } //-------------------------------------------------- @@ -197,5 +198,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega public func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> Buttonable { buttons[indexPath.row] } - + public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { + print("index") + } } diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index ca7aac1d..e0856e83 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -64,10 +64,6 @@ open class TextLink: ButtonBase { super.init(coder: coder) } - private var line = UIView().with { - $0.translatesAutoresizingMaskIntoConstraints = false - } - //-------------------------------------------------- // MARK: - Public Functions //-------------------------------------------------- @@ -76,13 +72,6 @@ open class TextLink: ButtonBase { isAccessibilityElement = true accessibilityTraits = .link if let titleLabel { - addSubview(line) - line.pinLeading(titleLabel.leadingAnchor) - line.pinTrailing(titleLabel.trailingAnchor) - line.pinTop(titleLabel.bottomAnchor) - line.pinBottom(bottomAnchor) - lineHeightConstraint = line.heightAnchor.constraint(equalToConstant: 1.0) - lineHeightConstraint?.isActive = true titleLabel.debugBorder(show: true) } } @@ -106,14 +95,9 @@ open class TextLink: ButtonBase { open override var intrinsicContentSize: CGSize { return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize } - - /// Function used to make changes to the View based off a change events or from local properties. - open override func updateView() { - //need to set the properties so the super class - //can render out the label correctly - line.backgroundColor = textColor - //always call last so the label is rendered - super.updateView() + open override func layoutSubviews() { + super.layoutSubviews() + addBorder(side: .bottom, width: 1, color: textColor) } } From c9f6caa680eba24d5693cd9bb3e030b43d258d56 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 21 Aug 2023 13:54:36 -0500 Subject: [PATCH 18/54] went to intrinsic size Signed-off-by: Matt Bruce --- VDS/Components/Icon/Icon.swift | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index 68ba7f97..58a515db 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -16,9 +16,6 @@ open class Icon: View { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- - private var widthConstraint: NSLayoutConstraint? - private var heightConstraint: NSLayoutConstraint? - private var dimensions: CGSize { guard let customSize else { return size.dimensions } return .init(width: customSize, height: customSize) @@ -29,10 +26,6 @@ open class Icon: View { //-------------------------------------------------- open var imageView = UIImageView().with { $0.translatesAutoresizingMaskIntoConstraints = false - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.setContentHuggingPriority(.required, for: .vertical) - $0.setContentCompressionResistancePriority(.required, for: .horizontal) - $0.setContentHuggingPriority(.required, for: .horizontal) $0.contentMode = .scaleAspectFill $0.clipsToBounds = true } @@ -57,14 +50,14 @@ open class Icon: View { open override func setup() { super.setup() + setContentCompressionResistancePriority(.required, for: .vertical) + setContentHuggingPriority(.required, for: .vertical) + setContentCompressionResistancePriority(.required, for: .horizontal) + setContentHuggingPriority(.required, for: .horizontal) + addSubview(imageView) imageView.pinToSuperView() - heightConstraint = imageView.heightAnchor.constraint(equalToConstant: size.dimensions.height) - heightConstraint?.isActive = true - widthConstraint = imageView.widthAnchor.constraint(equalToConstant: size.dimensions.width) - widthConstraint?.isActive = true - backgroundColor = .clear isAccessibilityElement = true @@ -77,6 +70,10 @@ open class Icon: View { color = VDSColor.paletteBlack imageView.image = nil } + + open override var intrinsicContentSize: CGSize { + dimensions + } /// Function used to make changes to the View based off a change events or from local properties. open override func updateView() { @@ -90,11 +87,7 @@ open class Icon: View { } else if surface == .light && color == VDSColor.paletteBlack { imageColor = VDSColor.elementsPrimaryOnlight } - - //set the icon dimensions - heightConstraint?.constant = dimensions.height - widthConstraint?.constant = dimensions.width - + //get the image name //set the image if let name, let image = getImage(for: name.rawValue) { @@ -102,7 +95,8 @@ open class Icon: View { } else { imageView.image = nil } - + + invalidateIntrinsicContentSize() } private func getImage(for imageName: String) -> UIImage? { From 5502cdaf46e2a00eac6d8c87ea7774547d993dae Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 21 Aug 2023 15:36:30 -0500 Subject: [PATCH 19/54] updated badge Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 49 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 70111855..33428b8d 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -27,12 +27,11 @@ open class Badge: View { /// Label used to render text open var label = Label().with { - $0.setContentHuggingPriority(.required, for: .vertical) - $0.setContentCompressionResistancePriority(.required, for: .vertical) - $0.setContentHuggingPriority(.required, for: .horizontal) - $0.setContentCompressionResistancePriority(.required, for: .horizontal) - $0.adjustsFontSizeToFitWidth = false $0.lineBreakMode = .byTruncatingTail + $0.setContentCompressionResistancePriority(.required, for: .vertical) + $0.setContentHuggingPriority(.defaultHigh, for: .vertical) + $0.setContentCompressionResistancePriority(.required, for: .horizontal) + $0.setContentHuggingPriority(.defaultHigh, for: .horizontal) $0.textPosition = .left $0.textStyle = .boldBodySmall } @@ -40,7 +39,7 @@ open class Badge: View { /// This will render the badges fill color based on the available options. /// When used in conjunction with the surface prop, this fill color will change its tint automatically based on a light or dark surface. open var fillColor: FillColor = .red { didSet { setNeedsUpdate() }} - + /// The text that will be shown in the label. open var text: String = "" { didSet { setNeedsUpdate() }} @@ -49,13 +48,23 @@ open class Badge: View { /// This will restrict the badge height to a specific number of lines. If the text overflows the allowable space, ellipsis will show. open var numberOfLines: Int = 1 { didSet { setNeedsUpdate() }} - + //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- - private var maxWidthConstraint: NSLayoutConstraint? - private var minWidthConstraint: NSLayoutConstraint? - + private var labelWidthConstraint: NSLayoutConstraint? + + private var widthConstraint: NSLayoutConstraint { + // Determine which constraint to activate based on the maxWidth and minWidth properties + if let maxWidth = maxWidth, maxWidth > minWidth { + // Apply maximum width constraint if set and greater than minWidth + return label.widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth) + } else { + // Apply minimum width constraint + return label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) + } + } + //-------------------------------------------------- // MARK: - Configuration //-------------------------------------------------- @@ -104,20 +113,16 @@ open class Badge: View { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - + open override func setup() { super.setup() accessibilityElements = [label] layer.cornerRadius = 2 - + addSubview(label) label.pinToSuperView(labelInset) - maxWidthConstraint = label.widthAnchor.constraint(lessThanOrEqualToConstant: 0) - minWidthConstraint = label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) - minWidthConstraint?.isActive = true - } /// Resets to default settings. @@ -144,19 +149,15 @@ open class Badge: View { backgroundColor = backgroundColorConfiguration.getColor(self) - if let maxWidth = maxWidth, maxWidth > minWidth { - maxWidthConstraint?.constant = maxWidth - maxWidthConstraint?.isActive = true - minWidthConstraint?.isActive = false - } else { - maxWidthConstraint?.isActive = false - minWidthConstraint?.isActive = true - } + labelWidthConstraint?.isActive = false + labelWidthConstraint = widthConstraint + labelWidthConstraint?.isActive = true label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() label.numberOfLines = numberOfLines label.text = text label.surface = surface label.disabled = disabled + } } From 79d1fe9b0f9a14ade00949030c46d6a236685e11 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 21 Aug 2023 17:36:45 -0500 Subject: [PATCH 20/54] removed code Signed-off-by: Matt Bruce --- VDS/Components/TitleLockup/TitleLockup.swift | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 1b2b1af4..354644ee 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -328,9 +328,6 @@ open class TitleLockup: View { eyebrowLabel.textColorConfiguration = textColorPrimaryConfiguration eyebrowLabel.textStyle = eyebrowModel.isBold ? otherStandardStyle.value.bold : otherStandardStyle.value.regular } - eyebrowLabel.sizeToFit() - } else { - eyebrowLabel.reset() } if let titleModel, !titleModel.text.isEmpty { @@ -341,9 +338,6 @@ open class TitleLockup: View { titleLabel.attributes = titleModel.textAttributes titleLabel.numberOfLines = titleModel.numberOfLines titleLabel.surface = surface - titleLabel.sizeToFit() - } else { - titleLabel.reset() } if let subTitleModel, !subTitleModel.text.isEmpty { @@ -355,9 +349,6 @@ open class TitleLockup: View { subTitleLabel.attributes = subTitleModel.textAttributes subTitleLabel.numberOfLines = subTitleModel.numberOfLines subTitleLabel.surface = surface - subTitleLabel.sizeToFit() - } else { - subTitleLabel.reset() } //if both first 2 rows not empty set spacing @@ -378,5 +369,5 @@ open class TitleLockup: View { eyebrowLabel.isHidden = eyebrowTextIsEmpty titleLabel.isHidden = titleTextIsEmpty subTitleLabel.isHidden = subTitleTextIsEmpty - } + } } From 45780bd898c763d12143527603e9ae03593c26e4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 21 Aug 2023 17:50:24 -0500 Subject: [PATCH 21/54] updated table Signed-off-by: Matt Bruce --- .../Buttons/ButtonGroup/ButtonGroup.swift | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index fba66594..e15bea2c 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -11,8 +11,12 @@ import VDSColorTokens import VDSFormControlsTokens import Combine +public protocol Refreshablable { + var onRefresh: (()->Void)? { get set } +} + @objc(VDSButtonGroup) -open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, ButtongGroupPositionLayoutDelegate { +open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, ButtongGroupPositionLayoutDelegate, Refreshablable { //-------------------------------------------------- // MARK: - Enums @@ -135,7 +139,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega super.setup() addSubview(collectionView) collectionView.pinToSuperView() - backgroundColor = .red } //-------------------------------------------------- @@ -155,9 +158,12 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega DispatchQueue.main.async { [weak self] in guard let self else { return } self.collectionView.collectionViewLayout.invalidateLayout() + self.onRefresh?() } } - + + open var onRefresh: (() -> Void)? + //-------------------------------------------------- // MARK: - UICollectionViewDataSource //-------------------------------------------------- @@ -198,7 +204,4 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega public func collectionView(_ collectionView: UICollectionView, buttonableAtIndexPath indexPath: IndexPath) -> Buttonable { buttons[indexPath.row] } - public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { - print("index") - } } From d6998092edd367f6c8aa7d4cb480f2ed7139017a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 08:13:34 -0500 Subject: [PATCH 22/54] removed Signed-off-by: Matt Bruce --- VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index e15bea2c..836ba6da 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -11,12 +11,8 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public protocol Refreshablable { - var onRefresh: (()->Void)? { get set } -} - @objc(VDSButtonGroup) -open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, ButtongGroupPositionLayoutDelegate, Refreshablable { +open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UICollectionViewDelegate, ButtongGroupPositionLayoutDelegate { //-------------------------------------------------- // MARK: - Enums @@ -158,12 +154,9 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega DispatchQueue.main.async { [weak self] in guard let self else { return } self.collectionView.collectionViewLayout.invalidateLayout() - self.onRefresh?() } } - - open var onRefresh: (() -> Void)? - + //-------------------------------------------------- // MARK: - UICollectionViewDataSource //-------------------------------------------------- From 45cd013784bf97df4874f1c5f56ba36df1d4e8bd Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 08:23:23 -0500 Subject: [PATCH 23/54] fixed layout issue Signed-off-by: Matt Bruce --- VDS/Components/Toggle/ToggleView.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 2be8ac0f..482acd63 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -120,11 +120,10 @@ open class ToggleView: Control, Changeable { addSubview(toggleView) toggleView.addSubview(knobView) - + toggleView.pinToSuperView() NSLayoutConstraint.activate([ toggleView.widthAnchor.constraint(equalToConstant: toggleSize.width), toggleView.heightAnchor.constraint(equalToConstant: toggleSize.height), - toggleView.centerYAnchor.constraint(equalTo: centerYAnchor), knobView.heightAnchor.constraint(equalToConstant: knobSize.height), knobView.widthAnchor.constraint(equalToConstant: knobSize.width), knobView.centerYAnchor.constraint(equalTo: toggleView.centerYAnchor), @@ -201,6 +200,8 @@ open class ToggleView: Control, Changeable { } knobTrailingConstraint?.isActive = true knobLeadingConstraint?.isActive = true + setNeedsLayout() + layoutIfNeeded() } private func updateToggle() { From 57375576ac15892dc8f8bc0d2806d959377e3a08 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 14:16:21 -0500 Subject: [PATCH 24/54] added priority to extension Signed-off-by: Matt Bruce --- .../UIView+NSLayoutConstraint.swift | 102 +++++++++--------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/VDS/Extensions/UIView+NSLayoutConstraint.swift b/VDS/Extensions/UIView+NSLayoutConstraint.swift index 8bc4f28f..ed363dc3 100644 --- a/VDS/Extensions/UIView+NSLayoutConstraint.swift +++ b/VDS/Extensions/UIView+NSLayoutConstraint.swift @@ -171,8 +171,8 @@ extension UIView { /// Adds a topAnchor. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func pinTop(_ constant: CGFloat = 0.0) -> Self { - return pinTop(nil, constant) + public func pinTop(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + return pinTop(nil, constant, priority) } @discardableResult @@ -180,8 +180,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the topAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinTop(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinTop(anchor: anchor, constant: constant) + public func pinTop(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTop(anchor: anchor, constant: constant, priority: priority) return self } @@ -190,8 +190,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the topAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinTopLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinTopLessThanOrEqualTo(anchor: anchor, constant: constant) + public func pinTopLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTopLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) return self } @@ -200,8 +200,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the topAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinTopGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinTopGreaterThanOrEqualTo(anchor: anchor, constant: constant) + public func pinTopGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTopGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) return self } @@ -210,10 +210,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the topAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor guard let found else { return nil } - return topAnchor.constraint(equalTo: found, constant: constant).activate() + return topAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -221,10 +221,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the topAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor guard let found else { return nil } - return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).activate() + return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -232,10 +232,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the topAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor guard let found else { return nil } - return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).activate() + return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } } @@ -248,8 +248,8 @@ extension UIView { /// Adds a bottomAnchor. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func pinBottom(_ constant: CGFloat = 0.0) -> Self { - return pinBottom(nil, constant) + public func pinBottom(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + return pinBottom(nil, constant, priority) } @discardableResult @@ -257,8 +257,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the bottomAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinBottom(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinBottom(anchor: anchor, constant: constant) + public func pinBottom(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinBottom(anchor: anchor, constant: constant, priority: priority) return self } @@ -267,8 +267,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the bottomAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinBottomLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinBottomLessThanOrEqualTo(anchor: anchor, constant: constant) + public func pinBottomLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinBottomLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) return self } @@ -277,8 +277,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the bottomAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinBottomGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinBottomGreaterThanOrEqualTo(anchor: anchor, constant: constant) + public func pinBottomGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinBottomGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) return self } @@ -287,10 +287,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the bottomAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor guard let found else { return nil } - return bottomAnchor.constraint(equalTo: found, constant: -constant).activate() + return bottomAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -298,10 +298,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the bottomAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor guard let found else { return nil } - return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).activate() + return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -309,10 +309,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the bottomAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor guard let found else { return nil } - return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).activate() + return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } } @@ -325,8 +325,8 @@ extension UIView { /// Adds a leadingAnchor. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func pinLeading(_ constant: CGFloat = 0.0) -> Self { - return pinLeading(nil, constant) + public func pinLeading(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + return pinLeading(nil, constant, priority) } @discardableResult @@ -334,8 +334,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the leadingAnchor. /// - constant: Constant size. /// - Returns: Yourself. - public func pinLeading(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinLeading(anchor: anchor, constant: constant) + public func pinLeading(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinLeading(anchor: anchor, constant: constant, priority: priority) return self } @@ -344,8 +344,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the leadingAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinLeadingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinLeadingLessThanOrEqualTo(anchor: anchor, constant: constant) + public func pinLeadingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinLeadingLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) return self } @@ -354,8 +354,8 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the leadingAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinLeadingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinLeadingGreaterThanOrEqualTo(anchor: anchor, constant: constant) + public func pinLeadingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinLeadingGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) return self } @@ -364,10 +364,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the leadingAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor guard let found else { return nil } - return leadingAnchor.constraint(equalTo: found, constant: constant).activate() + return leadingAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -375,10 +375,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the leadingAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor guard let found else { return nil } - return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).activate() + return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -386,10 +386,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the leadingAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor guard let found else { return nil } - return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).activate() + return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } } @@ -402,7 +402,7 @@ extension UIView { /// Adds a trailingAnchor. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func pinTrailing(_ constant: CGFloat = 0.0) -> Self { + public func pinTrailing(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { pinTrailing(nil, constant) } @@ -411,7 +411,7 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the trailingAnchor. /// - constant: Constant size. /// - Returns: Yourself. - public func pinTrailing(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { + public func pinTrailing(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { pinTrailing(anchor: anchor, constant: constant) return self } @@ -421,7 +421,7 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the trailingAnchor /// - constant: Constant size. /// - Returns: Yourself. - public func pinTrailingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { + public func pinTrailingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { pinTrailingLessThanOrEqualTo(anchor: anchor, constant: constant) return self } @@ -441,10 +441,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the trailingAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor guard let found else { return nil } - return trailingAnchor.constraint(equalTo: found, constant: -constant).activate() + return trailingAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -452,10 +452,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the trailingAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor guard let found else { return nil } - return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).activate() + return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult @@ -463,10 +463,10 @@ extension UIView { /// - Parameter anchor:The anchor in which to attach the trailingAnchor /// - constant: Constant size. /// - Returns: The Constraint that was created. - public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0) -> NSLayoutConstraint? { + public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor guard let found else { return nil } - return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).activate() + return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } } From e88f97e70eb4e120cb2b238ad4ad03c1aafba617 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 14:26:02 -0500 Subject: [PATCH 25/54] fixed constraint issues Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 33 ++++++++++---------- VDS/Components/Tabs/Tab.swift | 31 ++++++++---------- VDS/Components/TitleLockup/TitleLockup.swift | 7 +++-- 3 files changed, 34 insertions(+), 37 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 33428b8d..b0224473 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -52,17 +52,13 @@ open class Badge: View { //-------------------------------------------------- // MARK: - Constraints //-------------------------------------------------- - private var labelWidthConstraint: NSLayoutConstraint? + private var maxWidthConstraint: NSLayoutConstraint? - private var widthConstraint: NSLayoutConstraint { - // Determine which constraint to activate based on the maxWidth and minWidth properties - if let maxWidth = maxWidth, maxWidth > minWidth { - // Apply maximum width constraint if set and greater than minWidth - return label.widthAnchor.constraint(lessThanOrEqualToConstant: maxWidth) - } else { - // Apply minimum width constraint - return label.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) - } + private func updateMaxWidth() { + maxWidthConstraint?.isActive = false + guard let maxWidth else { return } + maxWidthConstraint?.constant = maxWidth + maxWidthConstraint?.isActive = true } //-------------------------------------------------- @@ -121,8 +117,15 @@ open class Badge: View { layer.cornerRadius = 2 addSubview(label) - label.pinToSuperView(labelInset) + label + .pinTop(labelInset.top) + .pinLeading(labelInset.left) + .pinTrailing(labelInset.right) + .pinBottom(labelInset.bottom, .defaultHigh) + + label.widthGreaterThanEqualTo(constant: minWidth) + maxWidthConstraint = label.widthLessThanEqualTo(constant: 0).with { $0.isActive = false } } /// Resets to default settings. @@ -146,18 +149,14 @@ open class Badge: View { super.updateView() updateTextColorConfig() - + updateMaxWidth() + backgroundColor = backgroundColorConfiguration.getColor(self) - labelWidthConstraint?.isActive = false - labelWidthConstraint = widthConstraint - labelWidthConstraint?.isActive = true - label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() label.numberOfLines = numberOfLines label.text = text label.surface = surface label.disabled = disabled - } } diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index 7369202f..b688e8d4 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -95,12 +95,11 @@ extension Tabs { private let layoutGuide = UILayoutGuide() - private var widthConstraint: NSLayoutConstraint? { - if let width, orientation == .vertical { - return layoutGuide.widthAnchor.constraint(equalToConstant: width) - } else { - return layoutGuide.widthAnchor.constraint(greaterThanOrEqualToConstant: minWidth) - } + private func updateWidth() { + labelWidthConstraint?.isActive = false + guard let width else { return } + labelWidthConstraint?.constant = width + labelWidthConstraint?.isActive = true } //-------------------------------------------------- @@ -138,16 +137,14 @@ extension Tabs { layoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor), layoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor)]) + //pin trailing label.pinTrailing(layoutGuide.trailingAnchor) - - labelTopConstraint = label.topAnchor.constraint(equalTo: layoutGuide.topAnchor) - labelTopConstraint?.isActive = true - - labelBottomConstraint = label.bottomAnchor.constraint(equalTo: layoutGuide.bottomAnchor) - labelBottomConstraint?.isActive = true - - labelLeadingConstraint = label.leadingAnchor.constraint(equalTo: layoutGuide.leadingAnchor) - labelLeadingConstraint?.isActive = true + + //setup constraints + labelWidthConstraint = label.width(constant: 0).with { $0.isActive = false } + labelTopConstraint = label.pinTop(anchor: layoutGuide.topAnchor) + labelLeadingConstraint = label.pinLeading(anchor: layoutGuide.leadingAnchor) + labelBottomConstraint = label.pinBottom(anchor: layoutGuide.bottomAnchor, priority: .defaultHigh) } /// Function used to make changes to the View based off a change events or from local properties. @@ -159,9 +156,7 @@ extension Tabs { accessibilityIdentifier = "VDSTab:\(text)" //constaints - labelWidthConstraint?.isActive = false - labelWidthConstraint = widthConstraint - labelWidthConstraint?.isActive = true + updateWidth() labelLeadingConstraint?.constant = leadingSpace labelTopConstraint?.constant = otherSpace labelBottomConstraint?.constant = -otherSpace diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 354644ee..2b1dd4db 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -269,8 +269,11 @@ open class TitleLockup: View { stackView.addArrangedSubview(subTitleLabel) //pin stackview to edges - stackView.pinToSuperView() - + stackView + .pinTop() + .pinLeading() + .pinTrailing() + .pinBottom(0, .defaultHigh) } /// Resets to default settings. From 8741e14770f962fd84bbbcd9fb77d0d45f7daf6a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 15:13:48 -0500 Subject: [PATCH 26/54] added layoutguide extension Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 + VDS/Extensions/UILayoutGuide.swift | 464 +++++++++++++++++++++++++++++ 2 files changed, 468 insertions(+) create mode 100644 VDS/Extensions/UILayoutGuide.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index addff05e..41fb8bb7 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -48,6 +48,7 @@ EA33623E2892EE950071C351 /* UIDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623D2892EE950071C351 /* UIDevice.swift */; }; EA3362402892EF6C0071C351 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623F2892EF6B0071C351 /* Label.swift */; }; EA33624728931B050071C351 /* Initable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33624628931B050071C351 /* Initable.swift */; }; + EA471F382A9545A700CE9E58 /* UILayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */; }; EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */; }; EA4DB2FD28D3D0CA00103EE3 /* AnyEquatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */; }; EA4DB30228DCBCA500103EE3 /* Badge.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB30128DCBCA500103EE3 /* Badge.swift */; }; @@ -194,6 +195,7 @@ EA33623D2892EE950071C351 /* UIDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDevice.swift; sourceTree = ""; }; EA33623F2892EF6B0071C351 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; EA33624628931B050071C351 /* Initable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Initable.swift; sourceTree = ""; }; + EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UILayoutGuide.swift; sourceTree = ""; }; EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectorGroupHandlerBase.swift; sourceTree = ""; }; EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyEquatable.swift; sourceTree = ""; }; EA4DB30128DCBCA500103EE3 /* Badge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Badge.swift; sourceTree = ""; }; @@ -467,6 +469,7 @@ EA3361A7288B23300071C351 /* UIColor.swift */, EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */, EA33623D2892EE950071C351 /* UIDevice.swift */, + EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */, EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */, EA8E40902A7D3F6300934ED3 /* UIView+Accessibility.swift */, EAB5FED329267EB300998C17 /* UIView+NSLayoutConstraint.swift */, @@ -951,6 +954,7 @@ EA5F86D02A1F936100BC83E4 /* TabsContainer.swift in Sources */, EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */, EAC9258F2911C9DE00091998 /* EntryField.swift in Sources */, + EA471F382A9545A700CE9E58 /* UILayoutGuide.swift in Sources */, EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */, EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */, EABFEB642A26473700C4C106 /* NSAttributedString.swift in Sources */, diff --git a/VDS/Extensions/UILayoutGuide.swift b/VDS/Extensions/UILayoutGuide.swift new file mode 100644 index 00000000..bd2a75a4 --- /dev/null +++ b/VDS/Extensions/UILayoutGuide.swift @@ -0,0 +1,464 @@ +// +// NSLayoutGuide.swift +// VDS +// +// Created by Matt Bruce on 8/22/23. +// + +import Foundation +import UIKit + + +//-------------------------------------------------- +// MARK: - Pinning +//-------------------------------------------------- +extension UILayoutGuide { + @discardableResult + /// Pins each to the all 4 anchor points to a view. + /// - Parameters: + /// - view: View that you will be pinned within. + /// - edges: Insets for each side. + /// - Returns: Yourself. + public func pin(_ view: UIView, with edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self { + pinLeading(view.leadingAnchor, edges.left) + pinTrailing(view.trailingAnchor, edges.right) + pinTop(view.topAnchor, edges.top) + pinBottom(view.bottomAnchor, edges.bottom) + return self + } + + @discardableResult + + /// Pins each to the all 4 anchor points to the view you are set within. + /// - Parameter edges: Insets for each side. + /// - Returns: Yourself. + public func pinToOwningView(_ edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self { + if let owningView { + pin(owningView, with: edges) + } + return self + } +} + +//-------------------------------------------------- +// MARK: - HeightAnchor +//-------------------------------------------------- +extension UILayoutGuide { + + @discardableResult + /// Adds a heightAnchor. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func height(_ constant: CGFloat) -> Self { + height(constant: constant) + return self + } + + @discardableResult + /// Adds a heightAnchor where the height constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func heightGreaterThanEqualTo(_ constant: CGFloat) -> Self { + heightGreaterThanEqualTo(constant: constant) + return self + } + + @discardableResult + /// Adds a heightAnchor where the height constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func heightLessThanEqualTo(_ constant: CGFloat) -> Self { + heightLessThanEqualTo(constant: constant) + return self + } + + @discardableResult + /// Adds a heightAnchor for the constant passed into the method. + /// - Parameter constant: Constant size. + /// - Returns: The Constraint that was created. + public func height(constant: CGFloat) -> NSLayoutConstraint { + heightAnchor.constraint(equalToConstant: constant).activate() + } + + @discardableResult + /// Adds a heightAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: The Constraint that was created. + public func heightGreaterThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { + heightAnchor.constraint(greaterThanOrEqualToConstant: constant).activate() + } + + @discardableResult + /// Adds a heightAnchor where the constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: The Constraint that was created. + public func heightLessThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { + heightAnchor.constraint(lessThanOrEqualToConstant: constant).activate() + } + +} + +//-------------------------------------------------- +// MARK: - WidthAnchor +//-------------------------------------------------- +extension UILayoutGuide { + + @discardableResult + /// Adds a widthAnchor. + /// - Parameter constant: Width Constant size. + /// - Returns: Yourself. + public func width(_ constant: CGFloat) -> Self { + width(constant: constant) + return self + } + + @discardableResult + /// Adds a widthAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func widthGreaterThanEqualTo(_ constant: CGFloat) -> Self { + widthGreaterThanEqualTo(constant: constant) + return self + } + + @discardableResult + /// Adds a widthAnchor where the constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func widthLessThanEqualTo(_ constant: CGFloat) -> Self { + widthLessThanEqualTo(constant: constant) + return self + } + + @discardableResult + /// Adds a widthAnchor for the constant passed into the method. + /// - Parameter constant: Constant size. + /// - Returns: The Constraint that was created. + public func width(constant: CGFloat) -> NSLayoutConstraint { + widthAnchor.constraint(equalToConstant: constant).activate() + } + + @discardableResult + /// Adds a widthAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: The Constraint that was created. + public func widthGreaterThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { + widthAnchor.constraint(greaterThanOrEqualToConstant: constant).activate() + } + + @discardableResult + /// Adds a widthAnchor with the constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter constant: Constant size. + /// - Returns: The Constraint that was created. + public func widthLessThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { + widthAnchor.constraint(lessThanOrEqualToConstant: constant).activate() + } +} + +//-------------------------------------------------- +// MARK: - TopAnchor +//-------------------------------------------------- +extension UILayoutGuide { + + @discardableResult + /// Adds a topAnchor. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func pinTop(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + return pinTop(nil, constant, priority) + } + + @discardableResult + /// Adds a topAnchor to a specific YAxisAnchor. + /// - Parameter anchor:The anchor in which to attach the topAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinTop(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTop(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a topAnchor to a specific YAxisAnchor passed in using a lessThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the topAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinTopLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTopLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a topAnchor to a specific YAxisAnchor passed in using a greaterThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the topAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinTopGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTopGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a topAnchor for the constant passed into the method. + /// - Parameter anchor:The anchor in which to attach the topAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor + guard let found else { return nil } + return topAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a topAnchor with the constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the topAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor + guard let found else { return nil } + return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a topAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the topAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor + guard let found else { return nil } + return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } + } + +} + +//-------------------------------------------------- +// MARK: - BottomAnchor +//-------------------------------------------------- +extension UILayoutGuide { + @discardableResult + /// Adds a bottomAnchor. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func pinBottom(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + return pinBottom(nil, constant, priority) + } + + @discardableResult + /// Adds a bottomAnchor to a specific YAxisAnchor. + /// - Parameter anchor:The anchor in which to attach the bottomAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinBottom(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinBottom(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a bottomAnchor to a specific YAxisAnchor passed in using a lessThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the bottomAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinBottomLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinBottomLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a bottomAnchor to a specific YAxisAnchor passed in using a greaterThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the bottomAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinBottomGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinBottomGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a bottomAnchor for the constant passed into the method. + /// - Parameter anchor:The anchor in which to attach the bottomAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor + guard let found else { return nil } + return bottomAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a bottomAnchor with the constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the bottomAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor + guard let found else { return nil } + return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a bottomAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the bottomAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor + guard let found else { return nil } + return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } + } +} + +//-------------------------------------------------- +// MARK: - LeadingAnchor +//-------------------------------------------------- +extension UILayoutGuide { + + @discardableResult + /// Adds a leadingAnchor. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func pinLeading(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + return pinLeading(nil, constant, priority) + } + + @discardableResult + /// Adds a leadingAnchor to a specific XAxisAnchor. + /// - Parameter anchor:The anchor in which to attach the leadingAnchor. + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinLeading(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinLeading(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a leadingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the leadingAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinLeadingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinLeadingLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a leadingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the leadingAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinLeadingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinLeadingGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) + return self + } + + @discardableResult + /// Adds a leadingAnchor for the constant passed into the method. + /// - Parameter anchor:The anchor in which to attach the leadingAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor + guard let found else { return nil } + return leadingAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a leadingAnchor with the constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the leadingAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor + guard let found else { return nil } + return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a leadingAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the leadingAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor + guard let found else { return nil } + return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } + } +} + +//-------------------------------------------------- +// MARK: - TrailingAnchor +//-------------------------------------------------- +extension UILayoutGuide { + + @discardableResult + /// Adds a trailingAnchor. + /// - Parameter constant: Constant size. + /// - Returns: Yourself. + public func pinTrailing(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTrailing(nil, constant) + } + + @discardableResult + /// Adds a trailingAnchor to a specific XAxisAnchor. + /// - Parameter anchor:The anchor in which to attach the trailingAnchor. + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinTrailing(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTrailing(anchor: anchor, constant: constant) + return self + } + + @discardableResult + /// Adds a trailingAnchor to a specific XAxisAnchor passed in using a lessThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the trailingAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinTrailingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { + pinTrailingLessThanOrEqualTo(anchor: anchor, constant: constant) + return self + } + + @discardableResult + /// Adds a trailingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint + /// - Parameter anchor:The anchor in which to attach the trailingAnchor + /// - constant: Constant size. + /// - Returns: Yourself. + public func pinTrailingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { + pinTrailingGreaterThanOrEqualTo(anchor: anchor, constant: constant) + return self + } + + @discardableResult + /// Adds a trailingAnchor for the constant passed into the method. + /// - Parameter anchor:The anchor in which to attach the trailingAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor + guard let found else { return nil } + return trailingAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a trailingAnchor with the constant passed in using a lessThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the trailingAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor + guard let found else { return nil } + return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } + } + + @discardableResult + /// Adds a trailingAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. + /// - Parameter anchor:The anchor in which to attach the trailingAnchor + /// - constant: Constant size. + /// - Returns: The Constraint that was created. + public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { + let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor + guard let found else { return nil } + return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } + } +} From a1fd61992c4c61bb875abe2a807de716fb7e22c1 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 15:22:42 -0500 Subject: [PATCH 27/54] refactored loader Signed-off-by: Matt Bruce --- VDS/Components/Loader/Loader.swift | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/VDS/Components/Loader/Loader.swift b/VDS/Components/Loader/Loader.swift index dbaa1349..9fd4e4e3 100644 --- a/VDS/Components/Loader/Loader.swift +++ b/VDS/Components/Loader/Loader.swift @@ -43,13 +43,15 @@ open class Loader: View { super.setup() addSubview(icon) + icon + .pinTopGreaterThanOrEqualTo() + .pinLeadingGreaterThanOrEqualTo() + .pinTrailingLessThanOrEqualTo() + .pinBottomLessThanOrEqualTo() + NSLayoutConstraint.activate([ icon.centerXAnchor.constraint(equalTo: centerXAnchor), - icon.centerYAnchor.constraint(equalTo: centerYAnchor), - icon.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor), - icon.trailingAnchor.constraint(lessThanOrEqualTo: trailingAnchor), - icon.topAnchor.constraint(greaterThanOrEqualTo: topAnchor), - icon.bottomAnchor.constraint(lessThanOrEqualTo: bottomAnchor) + icon.centerYAnchor.constraint(equalTo: centerYAnchor) ]) } From b80be084ceee5aae97ecef041ac54b7f23e68b5e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 15:23:10 -0500 Subject: [PATCH 28/54] refactored tabs Signed-off-by: Matt Bruce --- VDS/Components/Tabs/Tab.swift | 7 ++----- VDS/Components/Tabs/Tabs.swift | 12 ++++++------ VDS/Components/Tabs/TabsContainer.swift | 7 +------ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index b688e8d4..d21113ac 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -131,11 +131,8 @@ extension Tabs { accessibilityTraits = .button isAccessibilityElement = true - //activate the constraints - NSLayoutConstraint.activate([layoutGuide.topAnchor.constraint(equalTo: topAnchor), - layoutGuide.bottomAnchor.constraint(equalTo: bottomAnchor), - layoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor), - layoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor)]) + //pin layoutguide + layoutGuide.pinToOwningView() //pin trailing label.pinTrailing(layoutGuide.trailingAnchor) diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index 928daa8d..bc14d54f 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -187,13 +187,13 @@ open class Tabs: View { contentView.heightAnchor.constraint(equalTo: scrollView.heightAnchor).isActive = true - borderlineViewWidthConstraint = borderlineView.widthAnchor.constraint(equalToConstant: 0) - borderlineViewHeightConstraint = borderlineView.heightAnchor.constraint(equalToConstant: 0) + borderlineViewWidthConstraint = borderlineView.width(constant: 0) + borderlineViewHeightConstraint = borderlineView.height(constant: 0) - borderlineViewLeadingConstraint = borderlineView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor) - borderlineViewTrailingConstraint = borderlineView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor) - borderlineViewTopConstraint = borderlineView.topAnchor.constraint(equalTo: contentView.topAnchor) - borderlineViewBottomConstraint = borderlineView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor) + borderlineViewLeadingConstraint = borderlineView.pinLeading(anchor: contentView.leadingAnchor) + borderlineViewTrailingConstraint = borderlineView.pinTrailing(anchor: contentView.trailingAnchor) + borderlineViewTopConstraint = borderlineView.pinTop(anchor: contentView.topAnchor) + borderlineViewBottomConstraint = borderlineView.pinBottom(anchor: contentView.bottomAnchor) } diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 50eab591..5a48e6ea 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -132,12 +132,7 @@ open class TabsContainer: View { stackView.addArrangedSubview(tabMenu) stackView.addArrangedSubview(contentView) - NSLayoutConstraint.activate([ - tabMenuLayoutGuide.topAnchor.constraint(equalTo: topAnchor), - tabMenuLayoutGuide.bottomAnchor.constraint(equalTo: bottomAnchor), - tabMenuLayoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor), - tabMenuLayoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor) - ]) + tabMenuLayoutGuide.pinToOwningView() } /// Function used to make changes to the View based off a change events or from local properties. From 6604036bf71e7951e8ef661994350b0f201ff4a4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 15:23:30 -0500 Subject: [PATCH 29/54] refactored more anchors Signed-off-by: Matt Bruce --- .../BadgeIndicator/BadgeIndicator.swift | 15 ++++----------- .../Icon/ButtonIcon/ButtonIcon.swift | 19 +++++++------------ 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/VDS/Components/BadgeIndicator/BadgeIndicator.swift b/VDS/Components/BadgeIndicator/BadgeIndicator.swift index 25dd7a75..acf43519 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -258,19 +258,12 @@ open class BadgeIndicator: View { badgeView.addSubview(label) accessibilityElements = [label] - heightConstraint = badgeView.heightAnchor.constraint(greaterThanOrEqualToConstant: badgeSize) - heightConstraint?.isActive = true - - widthConstraint = badgeView.widthAnchor.constraint(greaterThanOrEqualToConstant: badgeSize) - widthConstraint?.isActive = true + heightConstraint = badgeView.heightGreaterThanEqualTo(constant: badgeSize) + widthConstraint = badgeView.widthGreaterThanEqualTo(constant: badgeSize) //we are insetting the padding to compensate for the border - NSLayoutConstraint.activate([ - badgeView.topAnchor.constraint(equalTo: topAnchor, constant: borderWidth), - badgeView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -borderWidth), - badgeView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: borderWidth), - badgeView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -borderWidth)]) - + badgeView.pinToSuperView(.init(top: borderWidth, left: borderWidth, bottom: borderWidth, right: borderWidth)) + labelContraints.topConstraint = label.pinTopGreaterThanOrEqualTo(anchor: badgeView.topAnchor) labelContraints.bottomConstraint = label.pinBottomGreaterThanOrEqualTo(anchor: badgeView.bottomAnchor) labelContraints.leadingConstraint = label.pinLeadingGreaterThanOrEqualTo(anchor: badgeView.leadingAnchor) diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift index 00efaca1..f3e14b9f 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift @@ -235,22 +235,17 @@ open class ButtonIcon: Control { addSubview(icon) //determines the height/width of the icon - layoutGuideWidthConstraint = iconLayoutGuide.widthAnchor.constraint(equalToConstant: size.containerSize) - layoutGuideHeightConstraint = iconLayoutGuide.heightAnchor.constraint(equalToConstant: size.containerSize) + layoutGuideWidthConstraint = iconLayoutGuide.width(constant: size.containerSize) + layoutGuideHeightConstraint = iconLayoutGuide.height(constant: size.containerSize) + //pin layout guide + iconLayoutGuide.pinToOwningView() + //determines the center point of the icon centerXConstraint = icon.centerXAnchor.constraint(equalTo: iconLayoutGuide.centerXAnchor, constant: 0) + centerXConstraint?.activate() centerYConstraint = icon.centerYAnchor.constraint(equalTo: iconLayoutGuide.centerYAnchor, constant: 0) - - //activate the constraints - NSLayoutConstraint.activate([layoutGuideWidthConstraint!, - layoutGuideHeightConstraint!, - centerXConstraint!, - centerYConstraint!, - iconLayoutGuide.topAnchor.constraint(equalTo: topAnchor), - iconLayoutGuide.bottomAnchor.constraint(equalTo: bottomAnchor), - iconLayoutGuide.leadingAnchor.constraint(equalTo: leadingAnchor), - iconLayoutGuide.trailingAnchor.constraint(equalTo: trailingAnchor)]) + centerYConstraint?.activate() } /// Resets to default settings. From 17705efcb80faf4ee879e40e7fa4677133a5cf0a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 15:38:11 -0500 Subject: [PATCH 30/54] added priority Signed-off-by: Matt Bruce --- VDS/Extensions/UILayoutGuide.swift | 48 +++++++++---------- .../UIView+NSLayoutConstraint.swift | 48 +++++++++---------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/VDS/Extensions/UILayoutGuide.swift b/VDS/Extensions/UILayoutGuide.swift index bd2a75a4..7dc638db 100644 --- a/VDS/Extensions/UILayoutGuide.swift +++ b/VDS/Extensions/UILayoutGuide.swift @@ -49,8 +49,8 @@ extension UILayoutGuide { /// Adds a heightAnchor. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func height(_ constant: CGFloat) -> Self { - height(constant: constant) + public func height(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + height(constant: constant, priority: priority) return self } @@ -58,8 +58,8 @@ extension UILayoutGuide { /// Adds a heightAnchor where the height constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func heightGreaterThanEqualTo(_ constant: CGFloat) -> Self { - heightGreaterThanEqualTo(constant: constant) + public func heightGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + heightGreaterThanEqualTo(constant: constant, priority: priority) return self } @@ -67,8 +67,8 @@ extension UILayoutGuide { /// Adds a heightAnchor where the height constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func heightLessThanEqualTo(_ constant: CGFloat) -> Self { - heightLessThanEqualTo(constant: constant) + public func heightLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + heightLessThanEqualTo(constant: constant, priority: priority) return self } @@ -76,24 +76,24 @@ extension UILayoutGuide { /// Adds a heightAnchor for the constant passed into the method. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func height(constant: CGFloat) -> NSLayoutConstraint { - heightAnchor.constraint(equalToConstant: constant).activate() + public func height(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + heightAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a heightAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func heightGreaterThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - heightAnchor.constraint(greaterThanOrEqualToConstant: constant).activate() + public func heightGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + heightAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a heightAnchor where the constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func heightLessThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - heightAnchor.constraint(lessThanOrEqualToConstant: constant).activate() + public func heightLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + heightAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } } @@ -107,8 +107,8 @@ extension UILayoutGuide { /// Adds a widthAnchor. /// - Parameter constant: Width Constant size. /// - Returns: Yourself. - public func width(_ constant: CGFloat) -> Self { - width(constant: constant) + public func width(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + width(constant: constant, priority: priority) return self } @@ -116,8 +116,8 @@ extension UILayoutGuide { /// Adds a widthAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func widthGreaterThanEqualTo(_ constant: CGFloat) -> Self { - widthGreaterThanEqualTo(constant: constant) + public func widthGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + widthGreaterThanEqualTo(constant: constant, priority: priority) return self } @@ -125,8 +125,8 @@ extension UILayoutGuide { /// Adds a widthAnchor where the constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func widthLessThanEqualTo(_ constant: CGFloat) -> Self { - widthLessThanEqualTo(constant: constant) + public func widthLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + widthLessThanEqualTo(constant: constant, priority: priority) return self } @@ -134,24 +134,24 @@ extension UILayoutGuide { /// Adds a widthAnchor for the constant passed into the method. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func width(constant: CGFloat) -> NSLayoutConstraint { - widthAnchor.constraint(equalToConstant: constant).activate() + public func width(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + widthAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a widthAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func widthGreaterThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - widthAnchor.constraint(greaterThanOrEqualToConstant: constant).activate() + public func widthGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + widthAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a widthAnchor with the constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func widthLessThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - widthAnchor.constraint(lessThanOrEqualToConstant: constant).activate() + public func widthLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + widthAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } } diff --git a/VDS/Extensions/UIView+NSLayoutConstraint.swift b/VDS/Extensions/UIView+NSLayoutConstraint.swift index ed363dc3..229492e1 100644 --- a/VDS/Extensions/UIView+NSLayoutConstraint.swift +++ b/VDS/Extensions/UIView+NSLayoutConstraint.swift @@ -56,8 +56,8 @@ extension UIView { /// Adds a heightAnchor. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func height(_ constant: CGFloat) -> Self { - height(constant: constant) + public func height(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + height(constant: constant, priority: priority) return self } @@ -65,8 +65,8 @@ extension UIView { /// Adds a heightAnchor where the height constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func heightGreaterThanEqualTo(_ constant: CGFloat) -> Self { - heightGreaterThanEqualTo(constant: constant) + public func heightGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + heightGreaterThanEqualTo(constant: constant, priority: priority) return self } @@ -74,8 +74,8 @@ extension UIView { /// Adds a heightAnchor where the height constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func heightLessThanEqualTo(_ constant: CGFloat) -> Self { - heightLessThanEqualTo(constant: constant) + public func heightLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + heightLessThanEqualTo(constant: constant, priority: priority) return self } @@ -83,24 +83,24 @@ extension UIView { /// Adds a heightAnchor for the constant passed into the method. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func height(constant: CGFloat) -> NSLayoutConstraint { - heightAnchor.constraint(equalToConstant: constant).activate() + public func height(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + heightAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a heightAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func heightGreaterThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - heightAnchor.constraint(greaterThanOrEqualToConstant: constant).activate() + public func heightGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + heightAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a heightAnchor where the constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func heightLessThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - heightAnchor.constraint(lessThanOrEqualToConstant: constant).activate() + public func heightLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + heightAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } } @@ -114,8 +114,8 @@ extension UIView { /// Adds a widthAnchor. /// - Parameter constant: Width Constant size. /// - Returns: Yourself. - public func width(_ constant: CGFloat) -> Self { - width(constant: constant) + public func width(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + width(constant: constant, priority: priority) return self } @@ -123,8 +123,8 @@ extension UIView { /// Adds a widthAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func widthGreaterThanEqualTo(_ constant: CGFloat) -> Self { - widthGreaterThanEqualTo(constant: constant) + public func widthGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + widthGreaterThanEqualTo(constant: constant, priority: priority) return self } @@ -132,8 +132,8 @@ extension UIView { /// Adds a widthAnchor where the constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: Yourself. - public func widthLessThanEqualTo(_ constant: CGFloat) -> Self { - widthLessThanEqualTo(constant: constant) + public func widthLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { + widthLessThanEqualTo(constant: constant, priority: priority) return self } @@ -141,24 +141,24 @@ extension UIView { /// Adds a widthAnchor for the constant passed into the method. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func width(constant: CGFloat) -> NSLayoutConstraint { - widthAnchor.constraint(equalToConstant: constant).activate() + public func width(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + widthAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a widthAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func widthGreaterThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - widthAnchor.constraint(greaterThanOrEqualToConstant: constant).activate() + public func widthGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + widthAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } @discardableResult /// Adds a widthAnchor with the constant passed in using a lessThanOrEqualTo Constraint. /// - Parameter constant: Constant size. /// - Returns: The Constraint that was created. - public func widthLessThanEqualTo(constant: CGFloat) -> NSLayoutConstraint { - widthAnchor.constraint(lessThanOrEqualToConstant: constant).activate() + public func widthLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { + widthAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } } } From 50e8ea468a6f253918cdb533a9acd2a44dcbaad0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 15:46:16 -0500 Subject: [PATCH 31/54] refactored toggle Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 13 +++---------- VDS/Components/Toggle/ToggleView.swift | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index e329c256..c6350ce2 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -147,21 +147,14 @@ open class Toggle: Control, Changeable { addSubview(label) addSubview(toggleView) - let heightEqual = heightAnchor.constraint(equalToConstant: toggleContainerSize.height) - heightEqual.priority = .defaultLow - - let heightGreater = heightAnchor.constraint(greaterThanOrEqualToConstant: toggleContainerSize.height) - heightGreater.priority = .defaultHigh - - let labelWidth = label.widthAnchor.constraint(lessThanOrEqualToConstant: labelMaxWidth) - labelWidth.priority = .required - labelWidth.isActive = true + label.widthLessThanEqualTo(labelMaxWidth) // Set up initial constraints for label and switch toggleView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true labelConstraints = [ - heightEqual, heightGreater, + height(constant: toggleContainerSize.height, priority: .defaultLow), + heightGreaterThanEqualTo(constant: toggleContainerSize.height, priority: .defaultHigh), label.topAnchor.constraint(equalTo: topAnchor), label.bottomAnchor.constraint(equalTo: bottomAnchor), ] diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 482acd63..018c887d 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -117,18 +117,22 @@ open class ToggleView: Control, Changeable { isAccessibilityElement = true accessibilityTraits = .button - + addSubview(toggleView) toggleView.addSubview(knobView) + toggleView.pinToSuperView() - NSLayoutConstraint.activate([ - toggleView.widthAnchor.constraint(equalToConstant: toggleSize.width), - toggleView.heightAnchor.constraint(equalToConstant: toggleSize.height), - knobView.heightAnchor.constraint(equalToConstant: knobSize.height), - knobView.widthAnchor.constraint(equalToConstant: knobSize.width), - knobView.centerYAnchor.constraint(equalTo: toggleView.centerYAnchor), - knobView.topAnchor.constraint(greaterThanOrEqualTo: toggleView.topAnchor) - ]) + + toggleView + .width(toggleSize.width) + .height(toggleSize.height) + + knobView + .pinTopGreaterThanOrEqualTo() + .width(knobSize.width) + .height(knobSize.height) + + knobView.centerYAnchor.constraint(equalTo: toggleView.centerYAnchor).activate() // Set cornerRadius knobView.layer.cornerRadius = knobSize.height / 2.0 From f39ba505b22725d6010ac90320f745f137ff7bc0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 15:55:32 -0500 Subject: [PATCH 32/54] updated Signed-off-by: Matt Bruce --- VDS/Components/TileContainer/TileContainer.swift | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index e96f9f04..45a6dbaf 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -168,14 +168,10 @@ open class TileContainer: Control { containerView.backgroundColor = .clear - containerTopConstraint = containerView.topAnchor.constraint(equalTo: topAnchor, constant: padding.value) - containerTopConstraint?.isActive = true - containerBottomConstraint = containerView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: padding.value) - containerBottomConstraint?.isActive = true - containerLeadingConstraint = containerView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: padding.value) - containerLeadingConstraint?.isActive = true - containerTrailingConstraint = containerView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: padding.value) - containerTrailingConstraint?.isActive = true + containerTopConstraint = containerView.pinTop(anchor: topAnchor, constant: padding.value) + containerBottomConstraint = containerView.pinBottom(anchor: bottomAnchor, constant: padding.value) + containerLeadingConstraint = containerView.pinLeading(anchor: leadingAnchor, constant: padding.value) + containerTrailingConstraint = containerView.pinTrailing(anchor: trailingAnchor, constant: padding.value) highlightView.pinToSuperView() highlightView.isHidden = true From 071e627fe6130b3706fba9a56e2c880d7a5fe9f2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 16:05:36 -0500 Subject: [PATCH 33/54] refactored to use protocol Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 8 +- .../Icon/ButtonIcon/ButtonIcon.swift | 2 +- VDS/Components/Tabs/Tab.swift | 2 +- VDS/Components/Tabs/TabsContainer.swift | 2 +- .../UIView+NSLayoutConstraint.swift | 455 ------------------ .../LayoutConstraintable.swift} | 72 ++- 6 files changed, 56 insertions(+), 485 deletions(-) rename VDS/{Extensions/UILayoutGuide.swift => Protocols/LayoutConstraintable.swift} (91%) diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 41fb8bb7..6aeb33a6 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -48,7 +48,7 @@ EA33623E2892EE950071C351 /* UIDevice.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623D2892EE950071C351 /* UIDevice.swift */; }; EA3362402892EF6C0071C351 /* Label.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33623F2892EF6B0071C351 /* Label.swift */; }; EA33624728931B050071C351 /* Initable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA33624628931B050071C351 /* Initable.swift */; }; - EA471F382A9545A700CE9E58 /* UILayoutGuide.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */; }; + EA471F3A2A95587500CE9E58 /* LayoutConstraintable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA471F392A95587500CE9E58 /* LayoutConstraintable.swift */; }; EA4DB18528CA967F00103EE3 /* SelectorGroupHandlerBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */; }; EA4DB2FD28D3D0CA00103EE3 /* AnyEquatable.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */; }; EA4DB30228DCBCA500103EE3 /* Badge.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA4DB30128DCBCA500103EE3 /* Badge.swift */; }; @@ -195,7 +195,7 @@ EA33623D2892EE950071C351 /* UIDevice.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDevice.swift; sourceTree = ""; }; EA33623F2892EF6B0071C351 /* Label.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Label.swift; sourceTree = ""; }; EA33624628931B050071C351 /* Initable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Initable.swift; sourceTree = ""; }; - EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UILayoutGuide.swift; sourceTree = ""; }; + EA471F392A95587500CE9E58 /* LayoutConstraintable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutConstraintable.swift; sourceTree = ""; }; EA4DB18428CA967F00103EE3 /* SelectorGroupHandlerBase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SelectorGroupHandlerBase.swift; sourceTree = ""; }; EA4DB2FC28D3D0CA00103EE3 /* AnyEquatable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnyEquatable.swift; sourceTree = ""; }; EA4DB30128DCBCA500103EE3 /* Badge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Badge.swift; sourceTree = ""; }; @@ -469,7 +469,6 @@ EA3361A7288B23300071C351 /* UIColor.swift */, EA81410F2A127066004F60D2 /* UIColor+VDSColor.swift */, EA33623D2892EE950071C351 /* UIDevice.swift */, - EA471F372A9545A700CE9E58 /* UILayoutGuide.swift */, EAF7F0B6289C12A600B287F5 /* UITapGestureRecognizer.swift */, EA8E40902A7D3F6300934ED3 /* UIView+Accessibility.swift */, EAB5FED329267EB300998C17 /* UIView+NSLayoutConstraint.swift */, @@ -494,6 +493,7 @@ EAF7F0A1289AFB3900B287F5 /* Errorable.swift */, EA3361AE288B26310071C351 /* FormFieldable.swift */, EA33624628931B050071C351 /* Initable.swift */, + EA471F392A95587500CE9E58 /* LayoutConstraintable.swift */, EA985C7C297DAED300F2FF2E /* Primitive.swift */, EAF7F0A5289B0CE000B287F5 /* Resetable.swift */, EA3361C8289054C50071C351 /* Surfaceable.swift */, @@ -954,7 +954,6 @@ EA5F86D02A1F936100BC83E4 /* TabsContainer.swift in Sources */, EAF7F0B1289B177F00B287F5 /* ColorLabelAttribute.swift in Sources */, EAC9258F2911C9DE00091998 /* EntryField.swift in Sources */, - EA471F382A9545A700CE9E58 /* UILayoutGuide.swift in Sources */, EAB1D2EA28AE84AA00DAE764 /* UIControlPublisher.swift in Sources */, EAD068922A560B65002E3A2D /* LoaderViewController.swift in Sources */, EABFEB642A26473700C4C106 /* NSAttributedString.swift in Sources */, @@ -967,6 +966,7 @@ EA0D1C372A681CCE00E5C127 /* ToggleView.swift in Sources */, EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */, EA3361BD288B2C760071C351 /* TypeAlias.swift in Sources */, + EA471F3A2A95587500CE9E58 /* LayoutConstraintable.swift in Sources */, EAB1D2CF28ABEF2B00DAE764 /* Typography.swift in Sources */, EA0D1C3B2A6AD51B00E5C127 /* Typogprahy+Styles.swift in Sources */, EAF7F09A2899B17200B287F5 /* CATransaction.swift in Sources */, diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift index f3e14b9f..63e8000a 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift @@ -239,7 +239,7 @@ open class ButtonIcon: Control { layoutGuideHeightConstraint = iconLayoutGuide.height(constant: size.containerSize) //pin layout guide - iconLayoutGuide.pinToOwningView() + iconLayoutGuide.pinToSuperView() //determines the center point of the icon centerXConstraint = icon.centerXAnchor.constraint(equalTo: iconLayoutGuide.centerXAnchor, constant: 0) diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index d21113ac..83bdb665 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -132,7 +132,7 @@ extension Tabs { isAccessibilityElement = true //pin layoutguide - layoutGuide.pinToOwningView() + layoutGuide.pinToSuperView() //pin trailing label.pinTrailing(layoutGuide.trailingAnchor) diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 5a48e6ea..58745a5b 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -132,7 +132,7 @@ open class TabsContainer: View { stackView.addArrangedSubview(tabMenu) stackView.addArrangedSubview(contentView) - tabMenuLayoutGuide.pinToOwningView() + tabMenuLayoutGuide.pinToSuperView() } /// Function used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Extensions/UIView+NSLayoutConstraint.swift b/VDS/Extensions/UIView+NSLayoutConstraint.swift index 229492e1..e53dc1d5 100644 --- a/VDS/Extensions/UIView+NSLayoutConstraint.swift +++ b/VDS/Extensions/UIView+NSLayoutConstraint.swift @@ -10,466 +10,11 @@ import UIKit import VDSFormControlsTokens extension UIView { - public func constraint(with identifier: String) -> NSLayoutConstraint? { return constraints.first { $0.identifier == identifier } } } -//-------------------------------------------------- -// MARK: - Pinning -//-------------------------------------------------- -extension UIView { - @discardableResult - /// Pins each to the all 4 anchor points to a view. - /// - Parameters: - /// - view: View that you will be pinned within. - /// - edges: Insets for each side. - /// - Returns: Yourself. - public func pin(_ view: UIView, with edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self { - pinLeading(view.leadingAnchor, edges.left) - pinTrailing(view.trailingAnchor, edges.right) - pinTop(view.topAnchor, edges.top) - pinBottom(view.bottomAnchor, edges.bottom) - return self - } - - @discardableResult - - /// Pins each to the all 4 anchor points to the view you are set within. - /// - Parameter edges: Insets for each side. - /// - Returns: Yourself. - public func pinToSuperView(_ edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self { - if let superview { - pin(superview, with: edges) - } - return self - } -} - -//-------------------------------------------------- -// MARK: - HeightAnchor -//-------------------------------------------------- -extension UIView { - - @discardableResult - /// Adds a heightAnchor. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func height(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { - height(constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a heightAnchor where the height constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func heightGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { - heightGreaterThanEqualTo(constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a heightAnchor where the height constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func heightLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { - heightLessThanEqualTo(constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a heightAnchor for the constant passed into the method. - /// - Parameter constant: Constant size. - /// - Returns: The Constraint that was created. - public func height(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { - heightAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a heightAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: The Constraint that was created. - public func heightGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { - heightAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a heightAnchor where the constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: The Constraint that was created. - public func heightLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { - heightAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } - } - -} - -//-------------------------------------------------- -// MARK: - WidthAnchor -//-------------------------------------------------- -extension UIView { - - @discardableResult - /// Adds a widthAnchor. - /// - Parameter constant: Width Constant size. - /// - Returns: Yourself. - public func width(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { - width(constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a widthAnchor where the constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func widthGreaterThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { - widthGreaterThanEqualTo(constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a widthAnchor where the constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func widthLessThanEqualTo(_ constant: CGFloat, _ priority: UILayoutPriority = .required) -> Self { - widthLessThanEqualTo(constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a widthAnchor for the constant passed into the method. - /// - Parameter constant: Constant size. - /// - Returns: The Constraint that was created. - public func width(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { - widthAnchor.constraint(equalToConstant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a widthAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: The Constraint that was created. - public func widthGreaterThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { - widthAnchor.constraint(greaterThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a widthAnchor with the constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter constant: Constant size. - /// - Returns: The Constraint that was created. - public func widthLessThanEqualTo(constant: CGFloat, priority: UILayoutPriority = .required) -> NSLayoutConstraint { - widthAnchor.constraint(lessThanOrEqualToConstant: constant).with { $0.priority = priority; $0.isActive = true } - } -} - -//-------------------------------------------------- -// MARK: - TopAnchor -//-------------------------------------------------- -extension UIView { - - @discardableResult - /// Adds a topAnchor. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func pinTop(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - return pinTop(nil, constant, priority) - } - - @discardableResult - /// Adds a topAnchor to a specific YAxisAnchor. - /// - Parameter anchor:The anchor in which to attach the topAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinTop(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinTop(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a topAnchor to a specific YAxisAnchor passed in using a lessThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the topAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinTopLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinTopLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a topAnchor to a specific YAxisAnchor passed in using a greaterThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the topAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinTopGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinTopGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a topAnchor for the constant passed into the method. - /// - Parameter anchor:The anchor in which to attach the topAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor - guard let found else { return nil } - return topAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a topAnchor with the constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the topAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor - guard let found else { return nil } - return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a topAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the topAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor - guard let found else { return nil } - return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } - } - -} - -//-------------------------------------------------- -// MARK: - BottomAnchor -//-------------------------------------------------- -extension UIView { - @discardableResult - /// Adds a bottomAnchor. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func pinBottom(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - return pinBottom(nil, constant, priority) - } - - @discardableResult - /// Adds a bottomAnchor to a specific YAxisAnchor. - /// - Parameter anchor:The anchor in which to attach the bottomAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinBottom(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinBottom(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a bottomAnchor to a specific YAxisAnchor passed in using a lessThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the bottomAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinBottomLessThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinBottomLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a bottomAnchor to a specific YAxisAnchor passed in using a greaterThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the bottomAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinBottomGreaterThanOrEqualTo(_ anchor: NSLayoutYAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinBottomGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a bottomAnchor for the constant passed into the method. - /// - Parameter anchor:The anchor in which to attach the bottomAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor - guard let found else { return nil } - return bottomAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a bottomAnchor with the constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the bottomAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor - guard let found else { return nil } - return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a bottomAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the bottomAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor - guard let found else { return nil } - return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } - } -} - -//-------------------------------------------------- -// MARK: - LeadingAnchor -//-------------------------------------------------- -extension UIView { - - @discardableResult - /// Adds a leadingAnchor. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func pinLeading(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - return pinLeading(nil, constant, priority) - } - - @discardableResult - /// Adds a leadingAnchor to a specific XAxisAnchor. - /// - Parameter anchor:The anchor in which to attach the leadingAnchor. - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinLeading(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinLeading(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a leadingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the leadingAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinLeadingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinLeadingLessThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a leadingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the leadingAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinLeadingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinLeadingGreaterThanOrEqualTo(anchor: anchor, constant: constant, priority: priority) - return self - } - - @discardableResult - /// Adds a leadingAnchor for the constant passed into the method. - /// - Parameter anchor:The anchor in which to attach the leadingAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor - guard let found else { return nil } - return leadingAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a leadingAnchor with the constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the leadingAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor - guard let found else { return nil } - return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a leadingAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the leadingAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor - guard let found else { return nil } - return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } - } -} - -//-------------------------------------------------- -// MARK: - TrailingAnchor -//-------------------------------------------------- -extension UIView { - - @discardableResult - /// Adds a trailingAnchor. - /// - Parameter constant: Constant size. - /// - Returns: Yourself. - public func pinTrailing(_ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinTrailing(nil, constant) - } - - @discardableResult - /// Adds a trailingAnchor to a specific XAxisAnchor. - /// - Parameter anchor:The anchor in which to attach the trailingAnchor. - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinTrailing(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinTrailing(anchor: anchor, constant: constant) - return self - } - - @discardableResult - /// Adds a trailingAnchor to a specific XAxisAnchor passed in using a lessThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the trailingAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinTrailingLessThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0, _ priority: UILayoutPriority = .required) -> Self { - pinTrailingLessThanOrEqualTo(anchor: anchor, constant: constant) - return self - } - - @discardableResult - /// Adds a trailingAnchor to a specific XAxisAnchor passed in using a greaterThanOrEqualTo Constraint - /// - Parameter anchor:The anchor in which to attach the trailingAnchor - /// - constant: Constant size. - /// - Returns: Yourself. - public func pinTrailingGreaterThanOrEqualTo(_ anchor: NSLayoutXAxisAnchor? = nil, _ constant: CGFloat = 0.0) -> Self { - pinTrailingGreaterThanOrEqualTo(anchor: anchor, constant: constant) - return self - } - - @discardableResult - /// Adds a trailingAnchor for the constant passed into the method. - /// - Parameter anchor:The anchor in which to attach the trailingAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor - guard let found else { return nil } - return trailingAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a trailingAnchor with the constant passed in using a lessThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the trailingAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor - guard let found else { return nil } - return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } - } - - @discardableResult - /// Adds a trailingAnchor with the constant passed in using a greaterThanOrEqualTo Constraint. - /// - Parameter anchor:The anchor in which to attach the trailingAnchor - /// - constant: Constant size. - /// - Returns: The Constraint that was created. - public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor - guard let found else { return nil } - return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } - } -} - extension NSLayoutConstraint { @discardableResult diff --git a/VDS/Extensions/UILayoutGuide.swift b/VDS/Protocols/LayoutConstraintable.swift similarity index 91% rename from VDS/Extensions/UILayoutGuide.swift rename to VDS/Protocols/LayoutConstraintable.swift index 7dc638db..ceededbc 100644 --- a/VDS/Extensions/UILayoutGuide.swift +++ b/VDS/Protocols/LayoutConstraintable.swift @@ -1,5 +1,5 @@ // -// NSLayoutGuide.swift +// LayoutConstraintable.swift // VDS // // Created by Matt Bruce on 8/22/23. @@ -7,12 +7,27 @@ import Foundation import UIKit +import VDSFormControlsTokens +public protocol LayoutConstraintable { + var superview: UIView? { get } + + var leadingAnchor: NSLayoutXAxisAnchor { get } + var trailingAnchor: NSLayoutXAxisAnchor { get } + var topAnchor: NSLayoutYAxisAnchor { get } + var bottomAnchor: NSLayoutYAxisAnchor { get } + + var widthAnchor: NSLayoutDimension { get } + var heightAnchor: NSLayoutDimension { get } + + var centerXAnchor: NSLayoutXAxisAnchor { get } + var centerYAnchor: NSLayoutYAxisAnchor { get } +} //-------------------------------------------------- // MARK: - Pinning //-------------------------------------------------- -extension UILayoutGuide { +extension LayoutConstraintable { @discardableResult /// Pins each to the all 4 anchor points to a view. /// - Parameters: @@ -32,9 +47,9 @@ extension UILayoutGuide { /// Pins each to the all 4 anchor points to the view you are set within. /// - Parameter edges: Insets for each side. /// - Returns: Yourself. - public func pinToOwningView(_ edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self { - if let owningView { - pin(owningView, with: edges) + public func pinToSuperView(_ edges: UIEdgeInsets = UIEdgeInsets.zero) -> Self { + if let superview { + pin(superview, with: edges) } return self } @@ -43,7 +58,7 @@ extension UILayoutGuide { //-------------------------------------------------- // MARK: - HeightAnchor //-------------------------------------------------- -extension UILayoutGuide { +extension LayoutConstraintable { @discardableResult /// Adds a heightAnchor. @@ -101,7 +116,7 @@ extension UILayoutGuide { //-------------------------------------------------- // MARK: - WidthAnchor //-------------------------------------------------- -extension UILayoutGuide { +extension LayoutConstraintable { @discardableResult /// Adds a widthAnchor. @@ -158,7 +173,7 @@ extension UILayoutGuide { //-------------------------------------------------- // MARK: - TopAnchor //-------------------------------------------------- -extension UILayoutGuide { +extension LayoutConstraintable { @discardableResult /// Adds a topAnchor. @@ -204,7 +219,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinTop(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor + let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor guard let found else { return nil } return topAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @@ -215,7 +230,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinTopLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor + let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor guard let found else { return nil } return topAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @@ -226,7 +241,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinTopGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.topAnchor + let found: NSLayoutYAxisAnchor? = anchor ?? superview?.topAnchor guard let found else { return nil } return topAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @@ -236,7 +251,7 @@ extension UILayoutGuide { //-------------------------------------------------- // MARK: - BottomAnchor //-------------------------------------------------- -extension UILayoutGuide { +extension LayoutConstraintable { @discardableResult /// Adds a bottomAnchor. /// - Parameter constant: Constant size. @@ -281,7 +296,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinBottom(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor + let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor guard let found else { return nil } return bottomAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @@ -292,7 +307,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinBottomLessThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor + let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor guard let found else { return nil } return bottomAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @@ -303,7 +318,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinBottomGreaterThanOrEqualTo(anchor: NSLayoutYAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutYAxisAnchor? = anchor ?? owningView?.bottomAnchor + let found: NSLayoutYAxisAnchor? = anchor ?? superview?.bottomAnchor guard let found else { return nil } return bottomAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @@ -312,7 +327,7 @@ extension UILayoutGuide { //-------------------------------------------------- // MARK: - LeadingAnchor //-------------------------------------------------- -extension UILayoutGuide { +extension LayoutConstraintable { @discardableResult /// Adds a leadingAnchor. @@ -358,7 +373,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinLeading(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor + let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor guard let found else { return nil } return leadingAnchor.constraint(equalTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @@ -369,7 +384,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinLeadingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor + let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor guard let found else { return nil } return leadingAnchor.constraint(lessThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @@ -380,7 +395,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinLeadingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.leadingAnchor + let found: NSLayoutXAxisAnchor? = anchor ?? superview?.leadingAnchor guard let found else { return nil } return leadingAnchor.constraint(greaterThanOrEqualTo: found, constant: constant).with { $0.priority = priority; $0.isActive = true } } @@ -389,7 +404,7 @@ extension UILayoutGuide { //-------------------------------------------------- // MARK: - TrailingAnchor //-------------------------------------------------- -extension UILayoutGuide { +extension LayoutConstraintable { @discardableResult /// Adds a trailingAnchor. @@ -435,7 +450,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinTrailing(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor + let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor guard let found else { return nil } return trailingAnchor.constraint(equalTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @@ -446,7 +461,7 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinTrailingLessThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor + let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor guard let found else { return nil } return trailingAnchor.constraint(lessThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } @@ -457,8 +472,19 @@ extension UILayoutGuide { /// - constant: Constant size. /// - Returns: The Constraint that was created. public func pinTrailingGreaterThanOrEqualTo(anchor: NSLayoutXAxisAnchor?, constant: CGFloat = 0.0, priority: UILayoutPriority = .required) -> NSLayoutConstraint? { - let found: NSLayoutXAxisAnchor? = anchor ?? owningView?.trailingAnchor + let found: NSLayoutXAxisAnchor? = anchor ?? superview?.trailingAnchor guard let found else { return nil } return trailingAnchor.constraint(greaterThanOrEqualTo: found, constant: -constant).with { $0.priority = priority; $0.isActive = true } } } + + +//-------------------------------------------------- +// MARK: - Implementations +//-------------------------------------------------- +extension UIView: LayoutConstraintable {} +extension UILayoutGuide: LayoutConstraintable { + public var superview: UIView? { + owningView + } +} From d3c3840ab35e6416a9d560cb8aa214550b844dfe Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 16:08:42 -0500 Subject: [PATCH 34/54] fixed bug in badge Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index b0224473..ac8c0e94 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -56,7 +56,7 @@ open class Badge: View { private func updateMaxWidth() { maxWidthConstraint?.isActive = false - guard let maxWidth else { return } + guard let maxWidth, maxWidth > minWidth else { return } maxWidthConstraint?.constant = maxWidth maxWidthConstraint?.isActive = true } From 1986eceae208e45ad93caaf85a024bfb827aa463 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 17:07:28 -0500 Subject: [PATCH 35/54] updated tabs for logic on numberoflines Signed-off-by: Matt Bruce --- VDS/Components/Tabs/Tabs.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index bc14d54f..cd138d60 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -144,6 +144,10 @@ open class Tabs: View { orientation == .horizontal && fillContainer ? .center : .left } + private var applyOverflow: Bool { + orientation == .horizontal && overflow == .scroll && !fillContainer + } + //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- @@ -258,7 +262,9 @@ open class Tabs: View { /// Updates the Tab individual views from local properties. private func updateTabs() { + let numberOfLines = applyOverflow ? 1 : 0 for (index, tabItem) in tabViews.enumerated() { + tabItem.label.numberOfLines = numberOfLines tabItem.size = size tabItem.isSelected = selectedIndex == index tabItem.index = index @@ -277,10 +283,10 @@ open class Tabs: View { contentViewWidthConstraint?.isActive = false // Apply overflow - if orientation == .horizontal && overflow == .scroll && !fillContainer { - let contentWidth = tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width + if applyOverflow { contentViewWidthConstraint = nil - scrollView.contentSize = CGSize(width: contentWidth, height: scrollView.bounds.height) + scrollView.contentSize = CGSize(width: tabStackView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).width, + height: scrollView.bounds.height) } else { contentViewWidthConstraint = contentView.widthAnchor.constraint(equalTo: scrollView.widthAnchor) scrollView.contentSize = bounds.size @@ -294,6 +300,11 @@ open class Tabs: View { scrollToSelectedIndex(animated: true) } + open override func layoutSubviews() { + super.layoutSubviews() + updateContentView() + } + //update layout for borderline private func updateBorderline() { //borderLine From 90ac92144fe999b723e0fb080577357571509ee4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 17:07:40 -0500 Subject: [PATCH 36/54] added overrides Signed-off-by: Matt Bruce --- VDS/Components/Label/Label.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 27f3fd79..46b8bb39 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -44,6 +44,10 @@ open class Label: UILabel, ViewProtocol, UserInfoable { open var userInfo = [String: Primitive]() + open override var numberOfLines: Int { didSet { setNeedsUpdate() }} + + open override var lineBreakMode: NSLineBreakMode { didSet { setNeedsUpdate() }} + override open var text: String? { didSet { attributes = nil From ee48532cce5fe9e1de200bfa3ef256c7de86e662 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 22 Aug 2023 17:10:02 -0500 Subject: [PATCH 37/54] fixed other bugs for tab Signed-off-by: Matt Bruce --- VDS/Components/Tabs/Tab.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index 83bdb665..16a39935 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -97,7 +97,7 @@ extension Tabs { private func updateWidth() { labelWidthConstraint?.isActive = false - guard let width else { return } + guard let width, width > minWidth else { return } labelWidthConstraint?.constant = width labelWidthConstraint?.isActive = true } @@ -138,7 +138,8 @@ extension Tabs { label.pinTrailing(layoutGuide.trailingAnchor) //setup constraints - labelWidthConstraint = label.width(constant: 0).with { $0.isActive = false } + labelWidthConstraint = layoutGuide.width(constant: 0).with { $0.isActive = false } + layoutGuide.widthGreaterThanEqualTo(minWidth) labelTopConstraint = label.pinTop(anchor: layoutGuide.topAnchor) labelLeadingConstraint = label.pinLeading(anchor: layoutGuide.leadingAnchor) labelBottomConstraint = label.pinBottom(anchor: layoutGuide.bottomAnchor, priority: .defaultHigh) @@ -164,7 +165,6 @@ extension Tabs { label.textStyle = textStyle label.textPosition = textPosition label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() - setNeedsLayout() layoutIfNeeded() From cfe0f6135b2e20604e296fe581b34bc44c253bae Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 23 Aug 2023 09:54:24 -0500 Subject: [PATCH 38/54] revert back to original Signed-off-by: Matt Bruce --- .../Buttons/TextLink/TextLink.swift | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index e0856e83..b4d8a745 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -18,6 +18,10 @@ open class TextLink: ButtonBase { // MARK: - Private Properties //-------------------------------------------------- private var lineHeightConstraint: NSLayoutConstraint? + + private var line = UIView().with { + $0.translatesAutoresizingMaskIntoConstraints = false + } //-------------------------------------------------- // MARK: - Properties @@ -72,7 +76,13 @@ open class TextLink: ButtonBase { isAccessibilityElement = true accessibilityTraits = .link if let titleLabel { - titleLabel.debugBorder(show: true) + addSubview(line) + line.pinLeading(titleLabel.leadingAnchor) + line.pinTrailing(titleLabel.trailingAnchor) + line.pinTop(titleLabel.bottomAnchor) + line.pinBottom(bottomAnchor, 0, .defaultHigh) + lineHeightConstraint = line.heightAnchor.constraint(equalToConstant: 1.0) + lineHeightConstraint?.isActive = true } } @@ -81,7 +91,7 @@ open class TextLink: ButtonBase { super.reset() shouldUpdateView = false text = nil - size = .large + size = .large accessibilityCustomActions = [] isAccessibilityElement = true accessibilityTraits = .link @@ -95,9 +105,14 @@ open class TextLink: ButtonBase { open override var intrinsicContentSize: CGSize { return titleLabel?.intrinsicContentSize ?? super.intrinsicContentSize } + + /// Function used to make changes to the View based off a change events or from local properties. + open override func updateView() { + //need to set the properties so the super class + //can render out the label correctly + line.backgroundColor = textColor - open override func layoutSubviews() { - super.layoutSubviews() - addBorder(side: .bottom, width: 1, color: textColor) + //always call last so the label is rendered + super.updateView() } } From 9c3fbe9a84bb3b3530b2bd809603637668a081ff Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Wed, 23 Aug 2023 16:56:39 -0500 Subject: [PATCH 39/54] fixed issue Signed-off-by: Matt Bruce --- VDS/Components/Buttons/TextLink/TextLink.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index b4d8a745..8b6ea74b 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -75,13 +75,14 @@ open class TextLink: ButtonBase { super.setup() isAccessibilityElement = true accessibilityTraits = .link + if let titleLabel { addSubview(line) line.pinLeading(titleLabel.leadingAnchor) line.pinTrailing(titleLabel.trailingAnchor) line.pinTop(titleLabel.bottomAnchor) line.pinBottom(bottomAnchor, 0, .defaultHigh) - lineHeightConstraint = line.heightAnchor.constraint(equalToConstant: 1.0) + lineHeightConstraint = line.height(constant: 1) lineHeightConstraint?.isActive = true } } From 7e061d28e57e176728cc22821ec9078cc1e933e4 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 24 Aug 2023 14:21:01 -0500 Subject: [PATCH 40/54] updated action label Signed-off-by: Matt Bruce --- .../Attributes/ActionLabelAttribute.swift | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift index 4a29f613..67241895 100644 --- a/VDS/Components/Label/Attributes/ActionLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ActionLabelAttribute.swift @@ -38,18 +38,17 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel { public var length: Int public var shouldUnderline: Bool public var accessibleText: String? - public var action: PassthroughSubject + public var action = PassthroughSubject() public var subscriber: AnyCancellable? //-------------------------------------------------- // MARK: - Initializer //-------------------------------------------------- - public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil, action: PassthroughSubject = .init() ) { + public init(location: Int, length: Int, shouldUnderline: Bool = true, accessibleText: String? = nil) { self.location = location self.length = length self.shouldUnderline = shouldUnderline self.accessibleText = accessibleText - self.action = action } private enum CodingKeys: String, CodingKey { @@ -67,3 +66,19 @@ public struct ActionLabelAttribute: ActionLabelAttributeModel { extension NSAttributedString.Key { public static let action = NSAttributedString.Key(rawValue: "action") } + +extension String { + public func nsRange(of text: String) -> NSRange? { + guard let found = range(of: text) else { return nil } + return NSRange(found, in: self) + } +} + + +extension ActionLabelAttribute { + + public init? (text: String, linkText: String, accessibleText: String? = nil) { + guard let range = text.nsRange(of: linkText) else { return nil } + self.init(location: range.location, length: range.length) + } +} From f08f1672fb87d015c888103c5b6a3b1ffb1bf546 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 10:18:00 -0500 Subject: [PATCH 41/54] fixed attributes Signed-off-by: Matt Bruce --- .../Buttons/TextLinkCaret/TextLinkCaret.swift | 2 +- .../Attributes/ImageLabelAttribute.swift | 19 ++++++++++++++++++- .../Attributes/TooltipLabelAttribute.swift | 3 +-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index a41ebfb0..2e75e6a3 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -119,7 +119,7 @@ extension TextLinkCaret { } func setAttribute(on attributedString: NSMutableAttributedString) { - let imageAttr = ImageLabelAttribute(location: location, imageName: "\(position.rawValue)-caret-bold", frame: .init(x: 0, y: 0, width: caretSize.width, height: caretSize.height), tintColor: tintColor) + let imageAttr = ImageLabelAttribute(location: location, imageName: "\(position.rawValue)-caret-bold", frame: .init(x: 0, y: 0, width: caretSize.width, height: caretSize.height), tintColor: tintColor, accessibleText: "Caret") let spacer = NSAttributedString.spacer(for: spacerWidth) guard let image = try? imageAttr.getAttachment() else { return } diff --git a/VDS/Components/Label/Attributes/ImageLabelAttribute.swift b/VDS/Components/Label/Attributes/ImageLabelAttribute.swift index dcd98629..7cc2f224 100644 --- a/VDS/Components/Label/Attributes/ImageLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/ImageLabelAttribute.swift @@ -28,7 +28,8 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel { public var image: UIImage? public var frame: CGRect? public var tintColor: UIColor? - + public var accessibleText: String? + //-------------------------------------------------- // MARK: - Equatable //-------------------------------------------------- @@ -40,11 +41,27 @@ public struct ImageLabelAttribute: AttachmentLabelAttributeModel { return id == equatable.id && range == equatable.range && imageName == equatable.imageName } + public init(id: UUID = UUID(), location: Int, imageName: String? = nil, image: UIImage? = nil, frame: CGRect? = nil, tintColor: UIColor? = nil, accessibleText: String? = nil) { + self.id = id + self.location = location + self.imageName = imageName + self.image = image + self.frame = frame + self.tintColor = tintColor + self.accessibleText = accessibleText + } + //-------------------------------------------------- // MARK: - Private Functions //-------------------------------------------------- private func imageAttachment(image: UIImage) -> NSTextAttachment { let attachment = NSTextAttachment() + if let accessibleText { + attachment.accessibilityLabel = accessibleText + attachment.isAccessibilityElement = true + } else { + attachment.isAccessibilityElement = false + } attachment.image = tintColor != nil ? image.withTintColor(tintColor!) : image if let frame { attachment.bounds = frame diff --git a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift index d77e03fe..26867749 100644 --- a/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift +++ b/VDS/Components/Label/Attributes/TooltipLabelAttribute.swift @@ -68,9 +68,8 @@ public class TooltipLabelAttribute: ActionLabelAttributeModel, TooltipLaunchable addHandler(on: attributedString) } - public init(id: UUID = UUID(), action: PassthroughSubject = PassthroughSubject(), 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, surface: Surface, accessibleText: String? = nil, closeButtonText: String = "Close", title: String? = nil, content: String? = nil, contentView: UIView? = nil, presenter: UIView? = nil) { self.id = id - self.action = action self.subscriber = subscriber self.surface = surface self.accessibleText = accessibleText From f2610016a70914362e610308c1568f0755ccbe35 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 10:18:17 -0500 Subject: [PATCH 42/54] removed toggleview as accessible Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index c6350ce2..cfdef454 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -86,6 +86,7 @@ open class Toggle: Control, Changeable { open var toggleView = ToggleView().with { $0.setContentCompressionResistancePriority(.defaultHigh, for: .horizontal) $0.isUserInteractionEnabled = false + $0.isAccessibilityElement = false } open var label = Label().with { From 8489ba90853adcdb70c3d985f3283bb6dcfc31df Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 13:02:46 -0500 Subject: [PATCH 43/54] added enabling as a protocol for controls and view Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 ++++ VDS/Protocols/Enabling.swift | 14 ++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 VDS/Protocols/Enabling.swift diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 6aeb33a6..29d74e3e 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -140,6 +140,7 @@ EAF7F0B9289C139800B287F5 /* ColorConfiguration.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */; }; EAF7F11728A1475A00B287F5 /* RadioButtonItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F11528A1475A00B287F5 /* RadioButtonItem.swift */; }; EAF7F13328A2A16500B287F5 /* AttachmentLabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF7F13228A2A16500B287F5 /* AttachmentLabelAttributeModel.swift */; }; + EAF978212A99035B00C2FEA9 /* Enabling.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAF978202A99035B00C2FEA9 /* Enabling.swift */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -287,6 +288,7 @@ EAF7F0B8289C139800B287F5 /* ColorConfiguration.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorConfiguration.swift; sourceTree = ""; }; EAF7F11528A1475A00B287F5 /* RadioButtonItem.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RadioButtonItem.swift; sourceTree = ""; }; EAF7F13228A2A16500B287F5 /* AttachmentLabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttachmentLabelAttributeModel.swift; sourceTree = ""; }; + EAF978202A99035B00C2FEA9 /* Enabling.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Enabling.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -489,6 +491,7 @@ EAF1FE9829D4850E00101452 /* Clickable.swift */, EAA5EEDF28F49DB3003B3210 /* Colorable.swift */, EA3361A9288B25E40071C351 /* Disabling.swift */, + EAF978202A99035B00C2FEA9 /* Enabling.swift */, EA5E305929510F8B0082B959 /* EnumSubset.swift */, EAF7F0A1289AFB3900B287F5 /* Errorable.swift */, EA3361AE288B26310071C351 /* FormFieldable.swift */, @@ -981,6 +984,7 @@ EA3361AF288B26310071C351 /* FormFieldable.swift in Sources */, EA513A952A4E1F82002A4DFF /* TitleLockupStyleConfiguration.swift in Sources */, 44604AD729CE196600E62B51 /* Line.swift in Sources */, + EAF978212A99035B00C2FEA9 /* Enabling.swift in Sources */, EA5E3058295105A40082B959 /* Tilelet.swift in Sources */, EA89201528B56CF4006B9984 /* RadioBoxGroup.swift in Sources */, EA985C1D296CD13600F2FF2E /* BundleManager.swift in Sources */, diff --git a/VDS/Protocols/Enabling.swift b/VDS/Protocols/Enabling.swift new file mode 100644 index 00000000..de9fb3ef --- /dev/null +++ b/VDS/Protocols/Enabling.swift @@ -0,0 +1,14 @@ +// +// Enabling.swift +// VDS +// +// Created by Matt Bruce on 8/25/23. +// + +import Foundation + +/// Any object that can be disabled, which may change the appearance +public protocol Enabling { + /// Whether this object is disabled or not + var isEnabled: Bool { get set } +} From 5811fa7a01e9bf90ab560d7759f6e1b7fd732da3 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 13:03:34 -0500 Subject: [PATCH 44/54] added isEnabled for setters where disabled is set Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 4 ++-- VDS/Classes/SelectorGroupHandlerBase.swift | 8 ++++++++ VDS/Classes/SelectorItemBase.swift | 4 ++++ VDS/Components/Badge/Badge.swift | 1 + .../BadgeIndicator/BadgeIndicator.swift | 1 + VDS/Components/Buttons/Button/ButtonBase.swift | 2 +- .../Buttons/ButtonGroup/ButtonGroup.swift | 10 ++++++++++ VDS/Components/Checkbox/CheckboxGroup.swift | 1 + VDS/Components/RadioBox/RadioBoxGroup.swift | 1 + VDS/Components/RadioBox/RadioBoxItem.swift | 3 +++ VDS/Components/RadioButton/RadioButtonGroup.swift | 1 + VDS/Components/RadioSwatch/RadioSwatchGroup.swift | 15 ++++++++++++++- VDS/Components/Tabs/TabsContainer.swift | 1 + .../TextFields/EntryField/EntryField.swift | 4 +++- .../TextFields/InputField/InputField.swift | 1 + VDS/Components/Toggle/Toggle.swift | 2 ++ VDS/Components/Tooltip/TrailingTooltipLabel.swift | 3 ++- VDS/Protocols/ViewProtocol.swift | 2 +- 18 files changed, 57 insertions(+), 7 deletions(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 317a16d3..9fc40c68 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -143,7 +143,7 @@ public class ControlColorConfiguration: KeyColorConfigurable { ///Meant to be used with any object that implements Surfaceable and Disabling. More than likely this is any View. public class ViewColorConfiguration: KeyColorConfigurable { public typealias KeyType = Bool - public typealias ObjectType = Surfaceable & Disabling + public typealias ObjectType = Surfaceable & Disabling & Enabling public var keyColors: [KeyColorConfiguration] = [] public required init() { } @@ -161,7 +161,7 @@ public class ViewColorConfiguration: KeyColorConfigurable { /// - Parameter object: Object that implements Surfaceable and Disabling /// - Returns: UIColor correspoding to either true/false for the disabled state and surface public func getColor(_ object: ObjectType) -> UIColor { - if let keyColor = keyColors.first(where: {$0.key == object.disabled }) { + if let keyColor = keyColors.first(where: {$0.key == !object.isEnabled }) { return keyColor.surfaceConfig.getColor(object) } else { return .clear //default diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index 868276ba..3136a234 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -37,6 +37,14 @@ open class SelectorGroupHandlerBase: Control, Changeable { } } + override open var isEnabled: Bool { + didSet { + selectorViews.forEach { handler in + handler.isEnabled = isEnabled + } + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable. override open var surface: Surface { didSet { diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index b7c916b2..3b057e74 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -192,6 +192,7 @@ open class SelectorItemBase: Control, Errorable, selectorView.isSelected = isSelected selectorView.isHighlighted = isHighlighted selectorView.disabled = disabled + selectorView.isEnabled = isEnabled selectorView.surface = surface } @@ -238,6 +239,7 @@ open class SelectorItemBase: Control, Errorable, if let labelText { label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled label.attributes = labelTextAttributes label.text = labelText label.isHidden = false @@ -253,6 +255,7 @@ open class SelectorItemBase: Control, Errorable, childLabel.text = childText childLabel.surface = surface childLabel.disabled = disabled + childLabel.isEnabled = isEnabled childLabel.attributes = childTextAttributes childLabel.isHidden = false @@ -277,6 +280,7 @@ open class SelectorItemBase: Control, Errorable, errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled + errorLabel.isEnabled = isEnabled mainStackView.spacing = 8 errorLabel.isHidden = false } else { diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index ac8c0e94..2c4da9fe 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -158,5 +158,6 @@ open class Badge: View { label.text = text label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled } } diff --git a/VDS/Components/BadgeIndicator/BadgeIndicator.swift b/VDS/Components/BadgeIndicator/BadgeIndicator.swift index acf43519..043624be 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -342,6 +342,7 @@ open class BadgeIndicator: View { label.text = getText() label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled label.sizeToFit() setNeedsLayout() layoutIfNeeded() diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 2f1e23b5..66b208b8 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -11,7 +11,7 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public protocol Buttonable: UIControl, Surfaceable, Disabling { +public protocol Buttonable: UIControl, Surfaceable, Disabling, Enabling { var availableSizes: [ButtonSize] { get } var text: String? { get set } var intrinsicContentSize: CGSize { get } diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 836ba6da..972e8e65 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -103,6 +103,16 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega } } + /// Whether this object is enabled or not + override open var isEnabled: Bool { + didSet { + buttons.forEach { button in + var b = button + b.isEnabled = isEnabled + } + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable override open var surface: Surface { didSet { diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 763a18ab..69cde8e3 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -41,6 +41,7 @@ open class CheckboxGroup: SelectorGroupHandlerBase { selectorViews = selectorModels.enumerated().map { index, model in return CheckboxItem().with { $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 209a5769..a6d2ec06 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -44,6 +44,7 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { $0.subTextRight = model.subText $0.subTextRightAttributes = model.subTextAttributes $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.inputId = model.inputId $0.isSelected = model.selected } diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index e789785e..4b33d5c0 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -188,6 +188,7 @@ open class RadioBoxItem: Control, Changeable { textLabel.text = text textLabel.surface = surface textLabel.disabled = disabled + textLabel.isEnabled = isEnabled textLabel.attributes = textAttributes //subText label @@ -195,6 +196,7 @@ open class RadioBoxItem: Control, Changeable { subTextLabel.text = subText subTextLabel.surface = surface subTextLabel.disabled = disabled + subTextLabel.isEnabled = isEnabled subTextLabel.attributes = subTextAttributes subTextLabel.isHidden = false @@ -210,6 +212,7 @@ open class RadioBoxItem: Control, Changeable { subTextRightLabel.text = subTextRight subTextRightLabel.surface = surface subTextRightLabel.disabled = disabled + subTextRightLabel.isEnabled = isEnabled subTextRightLabel.attributes = subTextRightAttributes subTextRightLabel.isHidden = false diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 4298f827..863899b8 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -36,6 +36,7 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { selectorViews = selectorModels.enumerated().map { index, model in return RadioButtonItem().with { $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 25827392..91ab2413 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -33,6 +33,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo $0.secondaryColor = model.secondaryColor $0.strikethrough = model.strikethrough $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value @@ -80,6 +81,17 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo collectionView.reloadData() } } + + /// Whether this object is disabled or not + override public var isEnabled: Bool { + didSet { + for selector in selectorViews { + selector.isEnabled = isEnabled + } + collectionView.reloadData() + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable override public var surface: Surface { didSet { @@ -133,6 +145,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo label.text = selectedHandler?.text ?? " " label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled collectionView.reloadData() } @@ -151,7 +164,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo // MARK: - UICollectionViewDelegate //-------------------------------------------------- open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { - return !selectorViews[indexPath.row].disabled + return selectorViews[indexPath.row].isEnabled } open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 58745a5b..39c92d4d 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -164,6 +164,7 @@ open class TabsContainer: View { tabMenu.surface = surface tabMenu.disabled = disabled + tabMenu.isEnabled = isEnabled tabMenu.orientation = orientation tabMenu.borderLine = borderLine tabMenu.fillContainer = fillContainer diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 819e805e..dab18d80 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -302,7 +302,7 @@ open class EntryField: Control, Changeable { titleLabel.attributes = attributes titleLabel.surface = surface titleLabel.disabled = disabled - + titleLabel.isEnabled = isEnabled } open func updateErrorLabel(){ @@ -310,6 +310,7 @@ open class EntryField: Control, Changeable { errorLabel.text = errorText errorLabel.surface = surface errorLabel.disabled = disabled + errorLabel.isEnabled = isEnabled errorLabel.isHidden = false icon.name = .error icon.color = VDSColor.paletteBlack @@ -327,6 +328,7 @@ open class EntryField: Control, Changeable { helperLabel.text = helperText helperLabel.surface = surface helperLabel.disabled = disabled + helperLabel.isEnabled = isEnabled helperLabel.isHidden = false } else { helperLabel.isHidden = true diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index f6df3da8..2fe4d2e9 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -176,6 +176,7 @@ open class InputField: EntryField, UITextFieldDelegate { successLabel.text = successText successLabel.surface = surface successLabel.disabled = disabled + successLabel.isEnabled = isEnabled successLabel.isHidden = false errorLabel.isHidden = true icon.name = .checkmarkAlt diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index cfdef454..1d9b0599 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -200,6 +200,7 @@ open class Toggle: Control, Changeable { updateLabel() toggleView.surface = surface toggleView.disabled = disabled + toggleView.isEnabled = isEnabled toggleView.isOn = isOn } @@ -235,6 +236,7 @@ open class Toggle: Control, Changeable { label.text = statusText label.surface = surface label.disabled = disabled + label.isEnabled = isEnabled switch textPosition { case .left: NSLayoutConstraint.deactivate(rightConstraints) diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 4a1be607..d119333e 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -72,7 +72,8 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.attributes = labelAttributes label.surface = surface label.disabled = disabled - + label.isEnabled = isEnabled + //add tooltip if let labelText, !labelText.isEmpty { label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent, contentView: tooltipContentView)) diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index 47b9f9b0..cf5e26dd 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -9,7 +9,7 @@ import Foundation import UIKit import Combine -public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Surfaceable { +public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Enabling, Surfaceable { /// Set of Subscribers for any Publishers for this Control. var subscribers: Set { get set } From 7f461e72e9556d7fd13f15bc75106cc942026a8c Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 14:55:11 -0500 Subject: [PATCH 45/54] removed disabled Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 2 +- VDS/Classes/Control.swift | 12 +----------- VDS/Classes/SelectorGroupHandlerBase.swift | 10 +--------- VDS/Classes/SelectorItemBase.swift | 6 +----- VDS/Classes/View.swift | 12 +----------- VDS/Components/Badge/Badge.swift | 1 - .../BadgeIndicator/BadgeIndicator.swift | 1 - VDS/Components/Buttons/Button/ButtonBase.swift | 14 ++------------ .../Buttons/ButtonGroup/ButtonGroup.swift | 10 ---------- VDS/Components/Checkbox/Checkbox.swift | 2 +- VDS/Components/Checkbox/CheckboxGroup.swift | 3 +-- VDS/Components/Label/Label.swift | 14 ++------------ VDS/Components/RadioBox/RadioBoxGroup.swift | 3 +-- VDS/Components/RadioBox/RadioBoxItem.swift | 3 --- .../RadioButton/RadioButtonGroup.swift | 3 +-- VDS/Components/RadioSwatch/RadioSwatch.swift | 8 ++++---- .../RadioSwatch/RadioSwatchGroup.swift | 16 ++-------------- VDS/Components/Tabs/TabsContainer.swift | 1 - .../TextFields/EntryField/EntryField.swift | 7 ++----- .../TextFields/InputField/InputField.swift | 5 ++--- .../TextFields/TextArea/TextArea.swift | 2 +- VDS/Components/Toggle/Toggle.swift | 3 +-- VDS/Components/Toggle/ToggleView.swift | 2 +- .../Tooltip/TrailingTooltipLabel.swift | 1 - VDS/Protocols/Disabling.swift | 10 +++++----- VDS/Protocols/ViewProtocol.swift | 2 +- 26 files changed, 32 insertions(+), 121 deletions(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 9fc40c68..4e1e8952 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -143,7 +143,7 @@ public class ControlColorConfiguration: KeyColorConfigurable { ///Meant to be used with any object that implements Surfaceable and Disabling. More than likely this is any View. public class ViewColorConfiguration: KeyColorConfigurable { public typealias KeyType = Bool - public typealias ObjectType = Surfaceable & Disabling & Enabling + public typealias ObjectType = Surfaceable & Enabling public var keyColors: [KeyColorConfiguration] = [] public required init() { } diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 1acca2d5..73ea2f82 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -40,16 +40,6 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { /// Current Surface and this is used to pass down to child objects that implement Surfacable open var surface: Surface = .light { didSet { setNeedsUpdate() } } - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - /// Whether the Control is selected or not. open override var isSelected: Bool { didSet { setNeedsUpdate() } } @@ -140,7 +130,7 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + isEnabled = true } //-------------------------------------------------- diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index 3136a234..122dea1b 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -28,15 +28,7 @@ open class SelectorGroupHandlerBase: Control, Changeable { } } - /// Whether this object is disabled or not - override open var disabled: Bool { - didSet { - selectorViews.forEach { handler in - handler.disabled = disabled - } - } - } - + /// Whether this object is enabled or not override open var isEnabled: Bool { didSet { selectorViews.forEach { handler in diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index 3b057e74..e7942bdb 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -33,7 +33,7 @@ open class SelectorItemBase: Control, Errorable, // MARK: - Private Properties //-------------------------------------------------- private var shouldShowError: Bool { - guard showError && !disabled && errorText?.isEmpty == false else { return false } + guard showError && isEnabled && errorText?.isEmpty == false else { return false } return true } @@ -191,7 +191,6 @@ open class SelectorItemBase: Control, Errorable, selectorView.showError = showError selectorView.isSelected = isSelected selectorView.isHighlighted = isHighlighted - selectorView.disabled = disabled selectorView.isEnabled = isEnabled selectorView.surface = surface } @@ -238,7 +237,6 @@ open class SelectorItemBase: Control, Errorable, //top label if let labelText { label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled label.attributes = labelTextAttributes label.text = labelText @@ -254,7 +252,6 @@ open class SelectorItemBase: Control, Errorable, if let childText { childLabel.text = childText childLabel.surface = surface - childLabel.disabled = disabled childLabel.isEnabled = isEnabled childLabel.attributes = childTextAttributes childLabel.isHidden = false @@ -279,7 +276,6 @@ open class SelectorItemBase: Control, Errorable, if let errorText, shouldShowError { errorLabel.text = errorText errorLabel.surface = surface - errorLabel.disabled = disabled errorLabel.isEnabled = isEnabled mainStackView.spacing = 8 errorLabel.isHidden = false diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index 8f1e40a3..66866fb1 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -33,16 +33,6 @@ open class View: UIView, ViewProtocol, UserInfoable { /// Current Surface and this is used to pass down to child objects that implement Surfacable open var surface: Surface = .light { didSet { setNeedsUpdate() } } - /// Whether this object is disabled or not. - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - /// Whether the View is enabled or not. open var isEnabled: Bool = true { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -101,7 +91,7 @@ open class View: UIView, ViewProtocol, UserInfoable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + isEnabled = true } } diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 2c4da9fe..ef7569fb 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -157,7 +157,6 @@ open class Badge: View { label.numberOfLines = numberOfLines label.text = text label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled } } diff --git a/VDS/Components/BadgeIndicator/BadgeIndicator.swift b/VDS/Components/BadgeIndicator/BadgeIndicator.swift index 043624be..c71b4f31 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -341,7 +341,6 @@ open class BadgeIndicator: View { label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() label.text = getText() label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled label.sizeToFit() setNeedsLayout() diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 66b208b8..a8e983ba 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -11,7 +11,7 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public protocol Buttonable: UIControl, Surfaceable, Disabling, Enabling { +public protocol Buttonable: UIControl, Surfaceable, Enabling { var availableSizes: [ButtonSize] { get } var text: String? { get set } var intrinsicContentSize: CGSize { get } @@ -83,16 +83,6 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab } } } - - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } /// Whether the Control is enabled or not. open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -144,7 +134,7 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab open func reset() { shouldUpdateView = false surface = .light - disabled = false + isEnabled = true text = nil accessibilityCustomActions = [] shouldUpdateView = true diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 972e8e65..c0472fe6 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -93,16 +93,6 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Whether this object is disabled or not - override open var disabled: Bool { - didSet { - buttons.forEach { button in - var b = button - b.disabled = disabled - } - } - } - /// Whether this object is enabled or not override open var isEnabled: Bool { didSet { diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 9c22e616..1179e58e 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -99,7 +99,7 @@ open class Checkbox: SelectorBase { shapeLayer?.removeAllAnimations() - if isAnimated && !disabled && !isHighlighted { + if isAnimated && isEnabled && !isHighlighted { let animateStrokeEnd = CABasicAnimation(keyPath: "strokeEnd") animateStrokeEnd.timingFunction = CAMediaTimingFunction(name: .linear) animateStrokeEnd.duration = 0.3 diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 69cde8e3..c5cd4d9e 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -40,7 +40,6 @@ open class CheckboxGroup: SelectorGroupHandlerBase { if let selectorModels { selectorViews = selectorModels.enumerated().map { index, model in return CheckboxItem().with { - $0.disabled = model.disabled $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId @@ -111,7 +110,7 @@ open class CheckboxGroup: SelectorGroupHandlerBase { } extension CheckboxGroup { - public struct CheckboxModel : Surfaceable, Disabling, Initable, FormFieldable, Errorable { + public struct CheckboxModel : Surfaceable, Initable, FormFieldable, Errorable { /// Whether this object is disabled or not public var disabled: Bool diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 46b8bb39..98d2f57b 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -54,17 +54,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { setNeedsUpdate() } } - - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - + /// Whether the View is enabled or not. open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -123,7 +113,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { open func reset() { shouldUpdateView = false surface = .light - disabled = false + isEnabled = true attributes = nil textStyle = .defaultStyle textPosition = .left diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index a6d2ec06..2443bc74 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -43,7 +43,6 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { $0.subTextAttributes = model.subTextAttributes $0.subTextRight = model.subText $0.subTextRightAttributes = model.subTextAttributes - $0.disabled = model.disabled $0.isEnabled = !model.disabled $0.inputId = model.inputId $0.isSelected = model.selected @@ -107,7 +106,7 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { } extension RadioBoxGroup { - public struct RadioBoxModel: Surfaceable, Initable, Disabling, FormFieldable { + public struct RadioBoxModel: Surfaceable, Initable, FormFieldable { /// Whether this object is disabled or not public var disabled: Bool /// Current Surface and this is used to pass down to child objects that implement Surfacable diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index 4b33d5c0..b9f16b5e 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -187,7 +187,6 @@ open class RadioBoxItem: Control, Changeable { //text label textLabel.text = text textLabel.surface = surface - textLabel.disabled = disabled textLabel.isEnabled = isEnabled textLabel.attributes = textAttributes @@ -195,7 +194,6 @@ open class RadioBoxItem: Control, Changeable { if let subText { subTextLabel.text = subText subTextLabel.surface = surface - subTextLabel.disabled = disabled subTextLabel.isEnabled = isEnabled subTextLabel.attributes = subTextAttributes subTextLabel.isHidden = false @@ -211,7 +209,6 @@ open class RadioBoxItem: Control, Changeable { if let subTextRight { subTextRightLabel.text = subTextRight subTextRightLabel.surface = surface - subTextRightLabel.disabled = disabled subTextRightLabel.isEnabled = isEnabled subTextRightLabel.attributes = subTextRightAttributes subTextRightLabel.isHidden = false diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 863899b8..d16d1835 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -35,7 +35,6 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { if let selectorModels { selectorViews = selectorModels.enumerated().map { index, model in return RadioButtonItem().with { - $0.disabled = model.disabled $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId @@ -115,7 +114,7 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { } extension RadioButtonGroup { - public struct RadioButtonModel: Surfaceable, Disabling, Initable, FormFieldable, Errorable { + public struct RadioButtonModel: Surfaceable, Initable, FormFieldable, Errorable { /// Whether this object is disabled or not public var disabled: Bool diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 1658482d..9f61b4ec 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -176,13 +176,13 @@ open class RadioSwatch: Control { var fillColorBackground: UIColor = .clear if let fillImage { - fillView.image = disabled ? fillImage.image(alpha: disabledAlpha) : fillImage + fillView.image = !isEnabled ? fillImage.image(alpha: disabledAlpha) : fillImage } else { fillView.image = nil if let primary = primaryColor, let secondary = secondaryColor { - let firstColor = disabled ? primary.withAlphaComponent(disabledAlpha) : primary - let secondColor = disabled ? secondary.withAlphaComponent(disabledAlpha) : secondary + let firstColor = !isEnabled ? primary.withAlphaComponent(disabledAlpha) : primary + let secondColor = !isEnabled ? secondary.withAlphaComponent(disabledAlpha) : secondary let gradient = CAGradientLayer() gradientLayer = gradient gradient.frame = fillView.bounds @@ -195,7 +195,7 @@ open class RadioSwatch: Control { } } - fillView.backgroundColor = disabled ? fillColorBackground.withAlphaComponent(disabledAlpha) : fillColorBackground + fillView.backgroundColor = !isEnabled ? fillColorBackground.withAlphaComponent(disabledAlpha) : fillColorBackground fillView.layer.borderColor = fillBorderColor.cgColor fillView.layer.cornerRadius = fillView.bounds.width * 0.5 fillView.layer.borderWidth = selectorBorderWidth diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 91ab2413..0f455451 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -32,7 +32,6 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo $0.primaryColor = model.primaryColor $0.secondaryColor = model.secondaryColor $0.strikethrough = model.strikethrough - $0.disabled = model.disabled $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId @@ -72,17 +71,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Whether this object is disabled or not - override public var disabled: Bool { - didSet { - for selector in selectorViews { - selector.disabled = disabled - } - collectionView.reloadData() - } - } - - /// Whether this object is disabled or not + /// Whether this object is enabled or not override public var isEnabled: Bool { didSet { for selector in selectorViews { @@ -144,7 +133,6 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo label.textStyle = .bodySmall label.text = selectedHandler?.text ?? " " label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled collectionView.reloadData() } @@ -206,7 +194,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo } extension RadioSwatchGroup { - public struct RadioSwatchModel: Surfaceable, Disabling, Initable { + public struct RadioSwatchModel: Surfaceable, Initable { /// Whether this object is disabled or not public var disabled: Bool = false /// Current Surface and this is used to pass down to child objects that implement Surfacable diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 39c92d4d..0b8db53d 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -163,7 +163,6 @@ open class TabsContainer: View { contentViewWidthConstraint?.isActive = true tabMenu.surface = surface - tabMenu.disabled = disabled tabMenu.isEnabled = isEnabled tabMenu.orientation = orientation tabMenu.borderLine = borderLine diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index dab18d80..933d53ee 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -283,7 +283,7 @@ open class EntryField: Control, Changeable { //dealing with the "Optional" addition to the text if let oldText = updatedLabelText, !required, !oldText.hasSuffix("Optional") { - if !disabled { + if isEnabled { let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2, length: 8, color: VDSColor.elementsSecondaryOnlight) @@ -301,7 +301,6 @@ open class EntryField: Control, Changeable { titleLabel.text = updatedLabelText titleLabel.attributes = attributes titleLabel.surface = surface - titleLabel.disabled = disabled titleLabel.isEnabled = isEnabled } @@ -309,13 +308,12 @@ open class EntryField: Control, Changeable { if showError, let errorText { errorLabel.text = errorText errorLabel.surface = surface - errorLabel.disabled = disabled errorLabel.isEnabled = isEnabled errorLabel.isHidden = false icon.name = .error icon.color = VDSColor.paletteBlack icon.surface = surface - icon.isHidden = disabled + icon.isHidden = !isEnabled } else { icon.isHidden = true errorLabel.isHidden = true @@ -327,7 +325,6 @@ open class EntryField: Control, Changeable { if let helperText { helperLabel.text = helperText helperLabel.surface = surface - helperLabel.disabled = disabled helperLabel.isEnabled = isEnabled helperLabel.isHidden = false } else { diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 2fe4d2e9..eb7ca72a 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -165,7 +165,7 @@ open class InputField: EntryField, UITextFieldDelegate { open override func updateView() { super.updateView() - textField.isEnabled = !disabled + textField.isEnabled = isEnabled textField.textColor = textFieldTextColorConfiguration.getColor(self) //show error or success @@ -175,14 +175,13 @@ open class InputField: EntryField, UITextFieldDelegate { } else if showSuccess, let successText { successLabel.text = successText successLabel.surface = surface - successLabel.disabled = disabled successLabel.isEnabled = isEnabled successLabel.isHidden = false errorLabel.isHidden = true icon.name = .checkmarkAlt icon.color = VDSColor.paletteBlack icon.surface = surface - icon.isHidden = disabled + icon.isHidden = !isEnabled } else { icon.isHidden = true successLabel.isHidden = true diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index eb7e45e0..6d94399f 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -95,7 +95,7 @@ open class TextArea: EntryField { open override func updateView() { super.updateView() - textView.isEditable = !disabled + textView.isEditable = isEnabled textView.textColor = textViewTextColorConfiguration.getColor(self) //set the width constraints diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 1d9b0599..9f030d90 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -179,6 +179,7 @@ open class Toggle: Control, Changeable { super.reset() shouldUpdateView = false label.reset() + isEnabled = true isOn = false isAnimated = true showText = false @@ -199,7 +200,6 @@ open class Toggle: Control, Changeable { updateLabel() toggleView.surface = surface - toggleView.disabled = disabled toggleView.isEnabled = isEnabled toggleView.isOn = isOn } @@ -235,7 +235,6 @@ open class Toggle: Control, Changeable { label.textStyle = textStyle label.text = statusText label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled switch textPosition { case .left: diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 018c887d..58292cc4 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -215,7 +215,7 @@ open class ToggleView: Control, Changeable { shadowLayer1.backgroundColor = knobColor.cgColor shadowLayer2.backgroundColor = knobColor.cgColor - if disabled || !isAnimated { + if !isEnabled || !isAnimated { toggleView.backgroundColor = toggleColor knobView.backgroundColor = knobColor constrainKnob() diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index d119333e..0555a5a9 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -71,7 +71,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.textPosition = labelTextPosition label.attributes = labelAttributes label.surface = surface - label.disabled = disabled label.isEnabled = isEnabled //add tooltip diff --git a/VDS/Protocols/Disabling.swift b/VDS/Protocols/Disabling.swift index 51a5bb50..12b938a7 100644 --- a/VDS/Protocols/Disabling.swift +++ b/VDS/Protocols/Disabling.swift @@ -7,8 +7,8 @@ import Foundation -/// Any object that can be disabled, which may change the appearance -public protocol Disabling { - /// Whether this object is disabled or not - var disabled: Bool { get set } -} +///// Any object that can be disabled, which may change the appearance +//public protocol Disabling { +// /// Whether this object is disabled or not +// var disabled: Bool { get set } +//} diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index cf5e26dd..f6d878c3 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -9,7 +9,7 @@ import Foundation import UIKit import Combine -public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Enabling, Surfaceable { +public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surfaceable { /// Set of Subscribers for any Publishers for this Control. var subscribers: Set { get set } From 1c3dfca2d72525771b8d6cc1e0eaf1d2979a162a Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 15:08:16 -0500 Subject: [PATCH 46/54] implemented isEnabled Signed-off-by: Matt Bruce --- VDS/Classes/SelectorGroupHandlerBase.swift | 9 +++++++++ VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index 868276ba..5a08d9a4 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -37,6 +37,15 @@ open class SelectorGroupHandlerBase: Control, Changeable { } } + /// Whether this object is enabled or not + override open var isEnabled: Bool { + didSet { + selectorViews.forEach { handler in + handler.isEnabled = isEnabled + } + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable. override open var surface: Surface { didSet { diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 836ba6da..61035c31 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -103,6 +103,15 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega } } + override open var isEnabled: Bool { + didSet { + buttons.forEach { button in + var b = button + b.isEnabled = isEnabled + } + } + } + /// Current Surface and this is used to pass down to child objects that implement Surfacable override open var surface: Surface { didSet { From 44d065da6d2367877b9d8991bbb710b9830f8034 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 15:37:29 -0500 Subject: [PATCH 47/54] added enabling, removed disabled Signed-off-by: Matt Bruce --- VDS/Protocols/ViewProtocol.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index 47b9f9b0..f6d878c3 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -9,7 +9,7 @@ import Foundation import UIKit import Combine -public protocol ViewProtocol: AnyObject, Initable, Resettable, Disabling, Surfaceable { +public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surfaceable { /// Set of Subscribers for any Publishers for this Control. var subscribers: Set { get set } From ff0cf0ddbb7be021dcd348af09a9bebfc9496858 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 15:37:53 -0500 Subject: [PATCH 48/54] updated for enabling Signed-off-by: Matt Bruce --- VDS/Components/Buttons/Button/ButtonBase.swift | 16 +++------------- .../Buttons/ButtonGroup/ButtonGroup.swift | 14 +------------- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 2f1e23b5..8142b4da 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -11,7 +11,7 @@ import VDSColorTokens import VDSFormControlsTokens import Combine -public protocol Buttonable: UIControl, Surfaceable, Disabling { +public protocol Buttonable: UIControl, Surfaceable, Enabling { var availableSizes: [ButtonSize] { get } var text: String? { get set } var intrinsicContentSize: CGSize { get } @@ -83,17 +83,7 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab } } } - - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - + /// Whether the Control is enabled or not. open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -144,7 +134,7 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab open func reset() { shouldUpdateView = false surface = .light - disabled = false + isEnabled = true text = nil accessibilityCustomActions = [] shouldUpdateView = true diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 61035c31..ae2c53a8 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -94,21 +94,9 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega // MARK: - Overrides //-------------------------------------------------- /// Whether this object is disabled or not - override open var disabled: Bool { - didSet { - buttons.forEach { button in - var b = button - b.disabled = disabled - } - } - } - override open var isEnabled: Bool { didSet { - buttons.forEach { button in - var b = button - b.isEnabled = isEnabled - } + buttons.forEach { $0.isEnabled = isEnabled } } } From d10b5755119e75c115145b7143768ab118d916ff Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 15:39:48 -0500 Subject: [PATCH 49/54] remvoed comment Signed-off-by: Matt Bruce --- VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index ae2c53a8..e0db8b10 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -93,7 +93,7 @@ open class ButtonGroup: View, UICollectionViewDataSource, UICollectionViewDelega //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Whether this object is disabled or not + /// Whether this object is enabled or not override open var isEnabled: Bool { didSet { buttons.forEach { $0.isEnabled = isEnabled } From 1b9a2799b24833df9ca48fe68c36ddffeb531e80 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 15:40:07 -0500 Subject: [PATCH 50/54] updated colorconfiguration to look at isEnabled Signed-off-by: Matt Bruce --- VDS/Classes/ColorConfiguration.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VDS/Classes/ColorConfiguration.swift b/VDS/Classes/ColorConfiguration.swift index 317a16d3..4e1e8952 100644 --- a/VDS/Classes/ColorConfiguration.swift +++ b/VDS/Classes/ColorConfiguration.swift @@ -143,7 +143,7 @@ public class ControlColorConfiguration: KeyColorConfigurable { ///Meant to be used with any object that implements Surfaceable and Disabling. More than likely this is any View. public class ViewColorConfiguration: KeyColorConfigurable { public typealias KeyType = Bool - public typealias ObjectType = Surfaceable & Disabling + public typealias ObjectType = Surfaceable & Enabling public var keyColors: [KeyColorConfiguration] = [] public required init() { } @@ -161,7 +161,7 @@ public class ViewColorConfiguration: KeyColorConfigurable { /// - Parameter object: Object that implements Surfaceable and Disabling /// - Returns: UIColor correspoding to either true/false for the disabled state and surface public func getColor(_ object: ObjectType) -> UIColor { - if let keyColor = keyColors.first(where: {$0.key == object.disabled }) { + if let keyColor = keyColors.first(where: {$0.key == !object.isEnabled }) { return keyColor.surfaceConfig.getColor(object) } else { return .clear //default From a6a0003c3b0d7f9954345b8b51589c24a3f2442e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 15:46:00 -0500 Subject: [PATCH 51/54] refactored label to remove disabled. Signed-off-by: Matt Bruce --- VDS/Classes/SelectorItemBase.swift | 6 +++--- VDS/Components/Badge/Badge.swift | 2 +- VDS/Components/BadgeIndicator/BadgeIndicator.swift | 2 +- VDS/Components/Label/Label.swift | 12 +----------- VDS/Components/RadioBox/RadioBoxItem.swift | 6 +++--- VDS/Components/RadioSwatch/RadioSwatchGroup.swift | 2 +- .../TextFields/EntryField/EntryField.swift | 6 +++--- .../TextFields/InputField/InputField.swift | 2 +- VDS/Components/Toggle/Toggle.swift | 2 +- VDS/Components/Tooltip/TrailingTooltipLabel.swift | 2 +- 10 files changed, 16 insertions(+), 26 deletions(-) diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index b7c916b2..9d90507f 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -237,7 +237,7 @@ open class SelectorItemBase: Control, Errorable, //top label if let labelText { label.surface = surface - label.disabled = disabled + label.isEnabled = isEnabled label.attributes = labelTextAttributes label.text = labelText label.isHidden = false @@ -252,7 +252,7 @@ open class SelectorItemBase: Control, Errorable, if let childText { childLabel.text = childText childLabel.surface = surface - childLabel.disabled = disabled + childLabel.isEnabled = isEnabled childLabel.attributes = childTextAttributes childLabel.isHidden = false @@ -276,7 +276,7 @@ open class SelectorItemBase: Control, Errorable, if let errorText, shouldShowError { errorLabel.text = errorText errorLabel.surface = surface - errorLabel.disabled = disabled + errorLabel.isEnabled = isEnabled mainStackView.spacing = 8 errorLabel.isHidden = false } else { diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index ac8c0e94..ef7569fb 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -157,6 +157,6 @@ open class Badge: View { label.numberOfLines = numberOfLines label.text = text label.surface = surface - label.disabled = disabled + label.isEnabled = isEnabled } } diff --git a/VDS/Components/BadgeIndicator/BadgeIndicator.swift b/VDS/Components/BadgeIndicator/BadgeIndicator.swift index acf43519..c71b4f31 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -341,7 +341,7 @@ open class BadgeIndicator: View { label.textColorConfiguration = textColorConfiguration.eraseToAnyColorable() label.text = getText() label.surface = surface - label.disabled = disabled + label.isEnabled = isEnabled label.sizeToFit() setNeedsLayout() layoutIfNeeded() diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 46b8bb39..437eea9d 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -55,16 +55,6 @@ open class Label: UILabel, ViewProtocol, UserInfoable { } } - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - /// Whether the View is enabled or not. open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } @@ -123,7 +113,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { open func reset() { shouldUpdateView = false surface = .light - disabled = false + isEnabled = true attributes = nil textStyle = .defaultStyle textPosition = .left diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index e789785e..b9f16b5e 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -187,14 +187,14 @@ open class RadioBoxItem: Control, Changeable { //text label textLabel.text = text textLabel.surface = surface - textLabel.disabled = disabled + textLabel.isEnabled = isEnabled textLabel.attributes = textAttributes //subText label if let subText { subTextLabel.text = subText subTextLabel.surface = surface - subTextLabel.disabled = disabled + subTextLabel.isEnabled = isEnabled subTextLabel.attributes = subTextAttributes subTextLabel.isHidden = false @@ -209,7 +209,7 @@ open class RadioBoxItem: Control, Changeable { if let subTextRight { subTextRightLabel.text = subTextRight subTextRightLabel.surface = surface - subTextRightLabel.disabled = disabled + subTextRightLabel.isEnabled = isEnabled subTextRightLabel.attributes = subTextRightAttributes subTextRightLabel.isHidden = false diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 25827392..6ee3e4b9 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -132,7 +132,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo label.textStyle = .bodySmall label.text = selectedHandler?.text ?? " " label.surface = surface - label.disabled = disabled + label.isEnabled = isEnabled collectionView.reloadData() } diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index 819e805e..f581d54a 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -301,7 +301,7 @@ open class EntryField: Control, Changeable { titleLabel.text = updatedLabelText titleLabel.attributes = attributes titleLabel.surface = surface - titleLabel.disabled = disabled + titleLabel.isEnabled = isEnabled } @@ -309,7 +309,7 @@ open class EntryField: Control, Changeable { if showError, let errorText { errorLabel.text = errorText errorLabel.surface = surface - errorLabel.disabled = disabled + errorLabel.isEnabled = isEnabled errorLabel.isHidden = false icon.name = .error icon.color = VDSColor.paletteBlack @@ -326,7 +326,7 @@ open class EntryField: Control, Changeable { if let helperText { helperLabel.text = helperText helperLabel.surface = surface - helperLabel.disabled = disabled + helperLabel.isEnabled = isEnabled helperLabel.isHidden = false } else { helperLabel.isHidden = true diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index f6df3da8..1a3862ac 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -175,7 +175,7 @@ open class InputField: EntryField, UITextFieldDelegate { } else if showSuccess, let successText { successLabel.text = successText successLabel.surface = surface - successLabel.disabled = disabled + successLabel.isEnabled = isEnabled successLabel.isHidden = false errorLabel.isHidden = true icon.name = .checkmarkAlt diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index cfdef454..445a8732 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -234,7 +234,7 @@ open class Toggle: Control, Changeable { label.textStyle = textStyle label.text = statusText label.surface = surface - label.disabled = disabled + label.isEnabled = isEnabled switch textPosition { case .left: NSLayoutConstraint.deactivate(rightConstraints) diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 4a1be607..32f255b1 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -71,7 +71,7 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.textPosition = labelTextPosition label.attributes = labelAttributes label.surface = surface - label.disabled = disabled + label.isEnabled = isEnabled //add tooltip if let labelText, !labelText.isEmpty { From e3f998de9f408d131a2010d8fcb22558ec806c44 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 16:12:50 -0500 Subject: [PATCH 52/54] Signed-off-by: Matt Bruce --- VDS/Classes/Control.swift | 19 +++++++------------ VDS/Classes/SelectorGroupHandlerBase.swift | 15 ++------------- VDS/Classes/SelectorItemBase.swift | 4 ++-- VDS/Classes/View.swift | 4 ++-- .../Buttons/Button/ButtonBase.swift | 2 +- VDS/Components/Checkbox/Checkbox.swift | 2 +- VDS/Components/Checkbox/CheckboxGroup.swift | 2 +- VDS/Components/Label/Label.swift | 2 +- VDS/Components/RadioBox/RadioBoxGroup.swift | 2 +- .../RadioButton/RadioButtonGroup.swift | 2 +- VDS/Components/RadioSwatch/RadioSwatch.swift | 8 ++++---- .../RadioSwatch/RadioSwatchGroup.swift | 11 +++++------ VDS/Components/Tabs/TabsContainer.swift | 2 +- .../TextFields/EntryField/EntryField.swift | 4 ++-- .../TextFields/InputField/InputField.swift | 4 ++-- .../TextFields/TextArea/TextArea.swift | 2 +- VDS/Components/Toggle/Toggle.swift | 2 +- VDS/Components/Toggle/ToggleView.swift | 2 +- 18 files changed, 36 insertions(+), 53 deletions(-) diff --git a/VDS/Classes/Control.swift b/VDS/Classes/Control.swift index 1acca2d5..cad40596 100644 --- a/VDS/Classes/Control.swift +++ b/VDS/Classes/Control.swift @@ -40,16 +40,6 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { /// Current Surface and this is used to pass down to child objects that implement Surfacable open var surface: Surface = .light { didSet { setNeedsUpdate() } } - /// Whether this object is disabled or not - open var disabled: Bool { - get { !isEnabled } - set { - if !isEnabled != newValue { - isEnabled = !newValue - } - } - } - /// Whether the Control is selected or not. open override var isSelected: Bool { didSet { setNeedsUpdate() } } @@ -79,7 +69,12 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { } /// Whether the Control is enabled or not. - open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open override var isEnabled: Bool { + didSet { + setNeedsUpdate() + //isUserInteractionEnabled = isEnabled + } + } //-------------------------------------------------- // MARK: - Initializers @@ -140,7 +135,7 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + isEnabled = true } //-------------------------------------------------- diff --git a/VDS/Classes/SelectorGroupHandlerBase.swift b/VDS/Classes/SelectorGroupHandlerBase.swift index 5a08d9a4..5d858bde 100644 --- a/VDS/Classes/SelectorGroupHandlerBase.swift +++ b/VDS/Classes/SelectorGroupHandlerBase.swift @@ -27,22 +27,11 @@ open class SelectorGroupHandlerBase: Control, Changeable { } } } - - /// Whether this object is disabled or not - override open var disabled: Bool { - didSet { - selectorViews.forEach { handler in - handler.disabled = disabled - } - } - } - + /// Whether this object is enabled or not override open var isEnabled: Bool { didSet { - selectorViews.forEach { handler in - handler.isEnabled = isEnabled - } + selectorViews.forEach { $0.isEnabled = isEnabled } } } diff --git a/VDS/Classes/SelectorItemBase.swift b/VDS/Classes/SelectorItemBase.swift index 9d90507f..e7942bdb 100644 --- a/VDS/Classes/SelectorItemBase.swift +++ b/VDS/Classes/SelectorItemBase.swift @@ -33,7 +33,7 @@ open class SelectorItemBase: Control, Errorable, // MARK: - Private Properties //-------------------------------------------------- private var shouldShowError: Bool { - guard showError && !disabled && errorText?.isEmpty == false else { return false } + guard showError && isEnabled && errorText?.isEmpty == false else { return false } return true } @@ -191,7 +191,7 @@ open class SelectorItemBase: Control, Errorable, selectorView.showError = showError selectorView.isSelected = isSelected selectorView.isHighlighted = isHighlighted - selectorView.disabled = disabled + selectorView.isEnabled = isEnabled selectorView.surface = surface } diff --git a/VDS/Classes/View.swift b/VDS/Classes/View.swift index 8f1e40a3..4697f88b 100644 --- a/VDS/Classes/View.swift +++ b/VDS/Classes/View.swift @@ -44,7 +44,7 @@ open class View: UIView, ViewProtocol, UserInfoable { } /// Whether the View is enabled or not. - open var isEnabled: Bool = true { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open var isEnabled: Bool = true { didSet { setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Initializers @@ -101,7 +101,7 @@ open class View: UIView, ViewProtocol, UserInfoable { open func reset() { backgroundColor = .clear surface = .light - disabled = false + isEnabled = true } } diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 8142b4da..58772cd4 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -85,7 +85,7 @@ open class ButtonBase: UIButton, Buttonable, ViewProtocol, UserInfoable, Clickab } /// Whether the Control is enabled or not. - open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open override var isEnabled: Bool { didSet { setNeedsUpdate() } } open var textStyle: TextStyle { .defaultStyle } diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index 9c22e616..1179e58e 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -99,7 +99,7 @@ open class Checkbox: SelectorBase { shapeLayer?.removeAllAnimations() - if isAnimated && !disabled && !isHighlighted { + if isAnimated && isEnabled && !isHighlighted { let animateStrokeEnd = CABasicAnimation(keyPath: "strokeEnd") animateStrokeEnd.timingFunction = CAMediaTimingFunction(name: .linear) animateStrokeEnd.duration = 0.3 diff --git a/VDS/Components/Checkbox/CheckboxGroup.swift b/VDS/Components/Checkbox/CheckboxGroup.swift index 763a18ab..56e0c0aa 100644 --- a/VDS/Components/Checkbox/CheckboxGroup.swift +++ b/VDS/Components/Checkbox/CheckboxGroup.swift @@ -40,7 +40,7 @@ open class CheckboxGroup: SelectorGroupHandlerBase { if let selectorModels { selectorViews = selectorModels.enumerated().map { index, model in return CheckboxItem().with { - $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 437eea9d..e552bb2e 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -56,7 +56,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { } /// Whether the View is enabled or not. - open override var isEnabled: Bool { didSet { setNeedsUpdate(); isUserInteractionEnabled = isEnabled } } + open override var isEnabled: Bool { didSet { setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Configuration Properties diff --git a/VDS/Components/RadioBox/RadioBoxGroup.swift b/VDS/Components/RadioBox/RadioBoxGroup.swift index 209a5769..19bdfd61 100644 --- a/VDS/Components/RadioBox/RadioBoxGroup.swift +++ b/VDS/Components/RadioBox/RadioBoxGroup.swift @@ -43,7 +43,7 @@ open class RadioBoxGroup: SelectorGroupSelectedHandlerBase { $0.subTextAttributes = model.subTextAttributes $0.subTextRight = model.subText $0.subTextRightAttributes = model.subTextAttributes - $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.inputId = model.inputId $0.isSelected = model.selected } diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 4298f827..29842ad2 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -35,7 +35,7 @@ open class RadioButtonGroup: SelectorGroupSelectedHandlerBase { if let selectorModels { selectorViews = selectorModels.enumerated().map { index, model in return RadioButtonItem().with { - $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 1658482d..9f61b4ec 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -176,13 +176,13 @@ open class RadioSwatch: Control { var fillColorBackground: UIColor = .clear if let fillImage { - fillView.image = disabled ? fillImage.image(alpha: disabledAlpha) : fillImage + fillView.image = !isEnabled ? fillImage.image(alpha: disabledAlpha) : fillImage } else { fillView.image = nil if let primary = primaryColor, let secondary = secondaryColor { - let firstColor = disabled ? primary.withAlphaComponent(disabledAlpha) : primary - let secondColor = disabled ? secondary.withAlphaComponent(disabledAlpha) : secondary + let firstColor = !isEnabled ? primary.withAlphaComponent(disabledAlpha) : primary + let secondColor = !isEnabled ? secondary.withAlphaComponent(disabledAlpha) : secondary let gradient = CAGradientLayer() gradientLayer = gradient gradient.frame = fillView.bounds @@ -195,7 +195,7 @@ open class RadioSwatch: Control { } } - fillView.backgroundColor = disabled ? fillColorBackground.withAlphaComponent(disabledAlpha) : fillColorBackground + fillView.backgroundColor = !isEnabled ? fillColorBackground.withAlphaComponent(disabledAlpha) : fillColorBackground fillView.layer.borderColor = fillBorderColor.cgColor fillView.layer.cornerRadius = fillView.bounds.width * 0.5 fillView.layer.borderWidth = selectorBorderWidth diff --git a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift index 6ee3e4b9..83789f04 100644 --- a/VDS/Components/RadioSwatch/RadioSwatchGroup.swift +++ b/VDS/Components/RadioSwatch/RadioSwatchGroup.swift @@ -32,7 +32,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo $0.primaryColor = model.primaryColor $0.secondaryColor = model.secondaryColor $0.strikethrough = model.strikethrough - $0.disabled = model.disabled + $0.isEnabled = !model.disabled $0.surface = model.surface $0.inputId = model.inputId $0.value = model.value @@ -72,14 +72,13 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo // MARK: - Overrides //-------------------------------------------------- /// Whether this object is disabled or not - override public var disabled: Bool { + override public var isEnabled: Bool { didSet { - for selector in selectorViews { - selector.disabled = disabled - } + selectorViews.forEach { $0.isEnabled = isEnabled } collectionView.reloadData() } } + /// Current Surface and this is used to pass down to child objects that implement Surfacable override public var surface: Surface { didSet { @@ -151,7 +150,7 @@ open class RadioSwatchGroup: SelectorGroupSelectedHandlerBase, UICo // MARK: - UICollectionViewDelegate //-------------------------------------------------- open func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool { - return !selectorViews[indexPath.row].disabled + return selectorViews[indexPath.row].isEnabled } open func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { diff --git a/VDS/Components/Tabs/TabsContainer.swift b/VDS/Components/Tabs/TabsContainer.swift index 58745a5b..0b8db53d 100644 --- a/VDS/Components/Tabs/TabsContainer.swift +++ b/VDS/Components/Tabs/TabsContainer.swift @@ -163,7 +163,7 @@ open class TabsContainer: View { contentViewWidthConstraint?.isActive = true tabMenu.surface = surface - tabMenu.disabled = disabled + tabMenu.isEnabled = isEnabled tabMenu.orientation = orientation tabMenu.borderLine = borderLine tabMenu.fillContainer = fillContainer diff --git a/VDS/Components/TextFields/EntryField/EntryField.swift b/VDS/Components/TextFields/EntryField/EntryField.swift index f581d54a..426e0fa8 100644 --- a/VDS/Components/TextFields/EntryField/EntryField.swift +++ b/VDS/Components/TextFields/EntryField/EntryField.swift @@ -283,7 +283,7 @@ open class EntryField: Control, Changeable { //dealing with the "Optional" addition to the text if let oldText = updatedLabelText, !required, !oldText.hasSuffix("Optional") { - if !disabled { + if isEnabled { let optionColorAttr = ColorLabelAttribute(location: oldText.count + 2, length: 8, color: VDSColor.elementsSecondaryOnlight) @@ -314,7 +314,7 @@ open class EntryField: Control, Changeable { icon.name = .error icon.color = VDSColor.paletteBlack icon.surface = surface - icon.isHidden = disabled + icon.isHidden = !isEnabled } else { icon.isHidden = true errorLabel.isHidden = true diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index 1a3862ac..eb7ca72a 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -165,7 +165,7 @@ open class InputField: EntryField, UITextFieldDelegate { open override func updateView() { super.updateView() - textField.isEnabled = !disabled + textField.isEnabled = isEnabled textField.textColor = textFieldTextColorConfiguration.getColor(self) //show error or success @@ -181,7 +181,7 @@ open class InputField: EntryField, UITextFieldDelegate { icon.name = .checkmarkAlt icon.color = VDSColor.paletteBlack icon.surface = surface - icon.isHidden = disabled + icon.isHidden = !isEnabled } else { icon.isHidden = true successLabel.isHidden = true diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index eb7e45e0..6d94399f 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -95,7 +95,7 @@ open class TextArea: EntryField { open override func updateView() { super.updateView() - textView.isEditable = !disabled + textView.isEditable = isEnabled textView.textColor = textViewTextColorConfiguration.getColor(self) //set the width constraints diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 445a8732..61ca1b95 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -199,7 +199,7 @@ open class Toggle: Control, Changeable { updateLabel() toggleView.surface = surface - toggleView.disabled = disabled + toggleView.isEnabled = isEnabled toggleView.isOn = isOn } diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 018c887d..58292cc4 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -215,7 +215,7 @@ open class ToggleView: Control, Changeable { shadowLayer1.backgroundColor = knobColor.cgColor shadowLayer2.backgroundColor = knobColor.cgColor - if disabled || !isAnimated { + if !isEnabled || !isAnimated { toggleView.backgroundColor = toggleColor knobView.backgroundColor = knobColor constrainKnob() From ad03637e41a4183e8b1a235a5af161a2d30db76e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 16:22:39 -0500 Subject: [PATCH 53/54] updated comments Signed-off-by: Matt Bruce --- VDS/Protocols/Enabling.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VDS/Protocols/Enabling.swift b/VDS/Protocols/Enabling.swift index de9fb3ef..b6e429ef 100644 --- a/VDS/Protocols/Enabling.swift +++ b/VDS/Protocols/Enabling.swift @@ -7,8 +7,8 @@ import Foundation -/// Any object that can be disabled, which may change the appearance +/// Any object that can be Enabled, which may change the appearance public protocol Enabling { - /// Whether this object is disabled or not + /// Whether this object is enabled or not var isEnabled: Bool { get set } } From 7e6b8094276ee9287cde1ea1e23289c0b7e213f0 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 25 Aug 2023 16:31:25 -0500 Subject: [PATCH 54/54] updated version Signed-off-by: Matt Bruce --- VDS.xcodeproj/project.pbxproj | 4 ++-- VDS/SupportingFiles/ReleaseNotes.txt | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/VDS.xcodeproj/project.pbxproj b/VDS.xcodeproj/project.pbxproj index 29d74e3e..db206376 100644 --- a/VDS.xcodeproj/project.pbxproj +++ b/VDS.xcodeproj/project.pbxproj @@ -1175,7 +1175,7 @@ BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 39; + CURRENT_PROJECT_VERSION = 40; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; @@ -1212,7 +1212,7 @@ BUILD_LIBRARY_FOR_DISTRIBUTION = YES; CODE_SIGN_IDENTITY = ""; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 39; + CURRENT_PROJECT_VERSION = 40; DEFINES_MODULE = YES; DEVELOPMENT_TEAM = ""; DYLIB_COMPATIBILITY_VERSION = 1; diff --git a/VDS/SupportingFiles/ReleaseNotes.txt b/VDS/SupportingFiles/ReleaseNotes.txt index 42e22558..a84fb8d4 100644 --- a/VDS/SupportingFiles/ReleaseNotes.txt +++ b/VDS/SupportingFiles/ReleaseNotes.txt @@ -1,3 +1,9 @@ +1.0.40 +======= +- Refactored a bit of code to remove "disabled" and move to "isEnabled" Apple Standard. +- Fixed Layout Constraint issues +- Added fixes for Accessibility + 1.0.39 ======= - CXTDT-423141 - Tabs - Selected Tab dark mode text color