From 317cf89fb6b1fcb2ef7827b8c8052653162d0f09 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 11:21:51 -0500 Subject: [PATCH 01/13] ensure updateView() can't be called until setup() is run Signed-off-by: Matt Bruce --- VDS/BaseClasses/Control.swift | 2 ++ VDS/BaseClasses/View.swift | 2 ++ VDS/Components/Buttons/ButtonBase.swift | 2 ++ VDS/Components/Label/Label.swift | 2 ++ VDS/Components/TextFields/InputField/TextField.swift | 2 ++ VDS/Components/TextFields/TextArea/TextView.swift | 2 ++ 6 files changed, 12 insertions(+) diff --git a/VDS/BaseClasses/Control.swift b/VDS/BaseClasses/Control.swift index 472f0635..0dcaa3f1 100644 --- a/VDS/BaseClasses/Control.swift +++ b/VDS/BaseClasses/Control.swift @@ -81,7 +81,9 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { open func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true + shouldUpdateView = false setup() + shouldUpdateView = true setNeedsUpdate() } } diff --git a/VDS/BaseClasses/View.swift b/VDS/BaseClasses/View.swift index 88996ba6..b39afbf2 100644 --- a/VDS/BaseClasses/View.swift +++ b/VDS/BaseClasses/View.swift @@ -60,7 +60,9 @@ open class View: UIView, ViewProtocol, UserInfoable { open func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true + shouldUpdateView = false setup() + shouldUpdateView = true setNeedsUpdate() } } diff --git a/VDS/Components/Buttons/ButtonBase.swift b/VDS/Components/Buttons/ButtonBase.swift index c764b89b..b210560a 100644 --- a/VDS/Components/Buttons/ButtonBase.swift +++ b/VDS/Components/Buttons/ButtonBase.swift @@ -103,7 +103,9 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false accessibilityCustomActions = [] + shouldUpdateView = false setup() + shouldUpdateView = true setNeedsUpdate() } } diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index f420be7d..3d56470b 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -209,7 +209,9 @@ open class Label: UILabel, ViewProtocol, UserInfoable { isAccessibilityElement = true accessibilityTraits = .staticText textAlignment = .left + shouldUpdateView = false setup() + shouldUpdateView = true setNeedsUpdate() } } diff --git a/VDS/Components/TextFields/InputField/TextField.swift b/VDS/Components/TextFields/InputField/TextField.swift index 3fdf308f..7adf1aa0 100644 --- a/VDS/Components/TextFields/InputField/TextField.swift +++ b/VDS/Components/TextFields/InputField/TextField.swift @@ -105,7 +105,9 @@ open class TextField: UITextField, ViewProtocol, Errorable { translatesAutoresizingMaskIntoConstraints = false setContentCompressionResistancePriority(.defaultLow, for: .horizontal) clipsToBounds = true + shouldUpdateView = false setup() + shouldUpdateView = true setNeedsUpdate() } } diff --git a/VDS/Components/TextFields/TextArea/TextView.swift b/VDS/Components/TextFields/TextArea/TextView.swift index 63356635..526911c4 100644 --- a/VDS/Components/TextFields/TextArea/TextView.swift +++ b/VDS/Components/TextFields/TextArea/TextView.swift @@ -112,7 +112,9 @@ open class TextView: UITextView, ViewProtocol, Errorable { initialSetupPerformed = true backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false + shouldUpdateView = false setup() + shouldUpdateView = true setNeedsUpdate() } } From f713cc0659c1d6330ff67847ba1779bdcc443c77 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 11:22:26 -0500 Subject: [PATCH 02/13] CXTDT-599736 - Unable to turn off the Toggles for Privacy preferences Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 19 +++++++++---------- VDS/Components/Toggle/ToggleView.swift | 15 +++++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index c147739b..e4390683 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -153,19 +153,18 @@ open class Toggle: Control, Changeable, FormFieldable { //-------------------------------------------------- // MARK: - Overrides - //-------------------------------------------------- - /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() - onClick = { control in - control.toggle() - } - } - + //-------------------------------------------------- /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() - + + publisher(for: .touchUpInside) + .sink(receiveValue: { [weak self] _ in + guard let self else { return } + toggle() + }) + .store(in: &subscribers) + isAccessibilityElement = true if #available(iOS 17.0, *) { accessibilityTraits = .toggleButton diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 9274be1a..a0dbcda4 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -105,17 +105,16 @@ open class ToggleView: Control, Changeable, FormFieldable { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() - onClick = { control in - control.toggle() - } - } - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() + + publisher(for: .touchUpInside) + .sink(receiveValue: { [weak self] _ in + guard let self else { return } + toggle() + }) + .store(in: &subscribers) isAccessibilityElement = true if #available(iOS 17.0, *) { From 9f6a83f8ce6c978900417c11f56b2c90349013ae Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 11:23:53 -0500 Subject: [PATCH 03/13] ensure isEnabled Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 2 +- VDS/Components/Toggle/ToggleView.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index e4390683..29f7dd6d 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -160,7 +160,7 @@ open class Toggle: Control, Changeable, FormFieldable { publisher(for: .touchUpInside) .sink(receiveValue: { [weak self] _ in - guard let self else { return } + guard let self, isEnabled else { return } toggle() }) .store(in: &subscribers) diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index a0dbcda4..fb663e99 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -111,7 +111,7 @@ open class ToggleView: Control, Changeable, FormFieldable { publisher(for: .touchUpInside) .sink(receiveValue: { [weak self] _ in - guard let self else { return } + guard let self, isEnabled else { return } toggle() }) .store(in: &subscribers) From eb8edd2acd7b95a4787cb9273e130a0a847b4bca Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 11:51:40 -0500 Subject: [PATCH 04/13] removed initialSetup so as devs won't use this method anymore, this will now be private to the base classes Signed-off-by: Matt Bruce --- VDS/Protocols/ViewProtocol.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index c7cba091..695386cb 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -19,9 +19,6 @@ public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surface /// Used for setting an implementation for the default Accessible Action var accessibilityAction: ((Self) -> Void)? { get set } - /// Executed on initialization for this View. - func initialSetup() - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. func setup() From 760433243eb04db671a6488fd81329abaeedec36 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 11:52:25 -0500 Subject: [PATCH 05/13] updated to private methods Signed-off-by: Matt Bruce --- VDS/BaseClasses/Control.swift | 2 +- VDS/BaseClasses/View.swift | 2 +- VDS/Components/Buttons/ButtonBase.swift | 8 ++--- VDS/Components/Label/Label.swift | 30 +++++++++---------- .../TextFields/InputField/TextField.swift | 11 +++---- .../TextFields/TextArea/TextView.swift | 7 +++-- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/VDS/BaseClasses/Control.swift b/VDS/BaseClasses/Control.swift index 0dcaa3f1..ad138db9 100644 --- a/VDS/BaseClasses/Control.swift +++ b/VDS/BaseClasses/Control.swift @@ -78,7 +78,7 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open func initialSetup() { + private func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true shouldUpdateView = false diff --git a/VDS/BaseClasses/View.swift b/VDS/BaseClasses/View.swift index b39afbf2..b8acb096 100644 --- a/VDS/BaseClasses/View.swift +++ b/VDS/BaseClasses/View.swift @@ -57,7 +57,7 @@ open class View: UIView, ViewProtocol, UserInfoable { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open func initialSetup() { + private func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true shouldUpdateView = false diff --git a/VDS/Components/Buttons/ButtonBase.swift b/VDS/Components/Buttons/ButtonBase.swift index b210560a..8af0ee68 100644 --- a/VDS/Components/Buttons/ButtonBase.swift +++ b/VDS/Components/Buttons/ButtonBase.swift @@ -97,12 +97,9 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open func initialSetup() { + private func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true - backgroundColor = .clear - translatesAutoresizingMaskIntoConstraints = false - accessibilityCustomActions = [] shouldUpdateView = false setup() shouldUpdateView = true @@ -112,8 +109,9 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { open func setup() { + backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false - + accessibilityCustomActions = [] titleLabel?.adjustsFontSizeToFitWidth = false titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.numberOfLines = 1 diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 3d56470b..5930dea7 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -192,23 +192,9 @@ open class Label: UILabel, ViewProtocol, UserInfoable { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open func initialSetup() { + private func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true - //register for ContentSizeChanges - NotificationCenter - .Publisher(center: .default, name: UIContentSizeCategory.didChangeNotification) - .sink { [weak self] notification in - self?.setNeedsUpdate() - }.store(in: &subscribers) - backgroundColor = .clear - numberOfLines = 0 - lineBreakMode = .byTruncatingTail - translatesAutoresizingMaskIntoConstraints = false - accessibilityCustomActions = [] - isAccessibilityElement = true - accessibilityTraits = .staticText - textAlignment = .left shouldUpdateView = false setup() shouldUpdateView = true @@ -217,6 +203,20 @@ open class Label: UILabel, ViewProtocol, UserInfoable { } open func setup() { + //register for ContentSizeChanges + NotificationCenter + .Publisher(center: .default, name: UIContentSizeCategory.didChangeNotification) + .sink { [weak self] notification in + self?.setNeedsUpdate() + }.store(in: &subscribers) + backgroundColor = .clear + numberOfLines = 0 + lineBreakMode = .byTruncatingTail + translatesAutoresizingMaskIntoConstraints = false + accessibilityCustomActions = [] + isAccessibilityElement = true + accessibilityTraits = .staticText + textAlignment = .left } open func reset() { diff --git a/VDS/Components/TextFields/InputField/TextField.swift b/VDS/Components/TextFields/InputField/TextField.swift index 7adf1aa0..2f6ddb1a 100644 --- a/VDS/Components/TextFields/InputField/TextField.swift +++ b/VDS/Components/TextFields/InputField/TextField.swift @@ -98,13 +98,9 @@ open class TextField: UITextField, ViewProtocol, Errorable { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open func initialSetup() { + private func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true - backgroundColor = .clear - translatesAutoresizingMaskIntoConstraints = false - setContentCompressionResistancePriority(.defaultLow, for: .horizontal) - clipsToBounds = true shouldUpdateView = false setup() shouldUpdateView = true @@ -113,6 +109,11 @@ open class TextField: UITextField, ViewProtocol, Errorable { } open func setup() { + backgroundColor = .clear + translatesAutoresizingMaskIntoConstraints = false + setContentCompressionResistancePriority(.defaultLow, for: .horizontal) + clipsToBounds = true + let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44))) accessView.backgroundColor = .white accessView.addBorder(side: .top, width: 1, color: .lightGray) diff --git a/VDS/Components/TextFields/TextArea/TextView.swift b/VDS/Components/TextFields/TextArea/TextView.swift index 526911c4..575c2da8 100644 --- a/VDS/Components/TextFields/TextArea/TextView.swift +++ b/VDS/Components/TextFields/TextArea/TextView.swift @@ -107,11 +107,9 @@ open class TextView: UITextView, ViewProtocol, Errorable { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open func initialSetup() { + private func initialSetup() { if !initialSetupPerformed { initialSetupPerformed = true - backgroundColor = .clear - translatesAutoresizingMaskIntoConstraints = false shouldUpdateView = false setup() shouldUpdateView = true @@ -120,6 +118,9 @@ open class TextView: UITextView, ViewProtocol, Errorable { } open func setup() { + backgroundColor = .clear + translatesAutoresizingMaskIntoConstraints = false + let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44))) accessView.backgroundColor = .white accessView.addBorder(side: .top, width: 1, color: .lightGray) From c2c88c7b90d2bc34780e33383348c3e7d0727887 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 11:57:28 -0500 Subject: [PATCH 06/13] moved to setup Signed-off-by: Matt Bruce --- VDS/Components/Breadcrumbs/Breadcrumbs.swift | 4 ++-- VDS/Components/Calendar/Calendar.swift | 4 ---- VDS/Components/Carousel/Carousel.swift | 5 ----- VDS/Components/CarouselScrollbar/CarouselScrollbar.swift | 4 ---- VDS/Components/Pagination/Pagination.swift | 4 ++-- VDS/Components/Pagination/PaginationButton.swift | 4 ++-- VDS/Components/Table/Table.swift | 4 ++-- 7 files changed, 8 insertions(+), 21 deletions(-) diff --git a/VDS/Components/Breadcrumbs/Breadcrumbs.swift b/VDS/Components/Breadcrumbs/Breadcrumbs.swift index 5a2de7d0..6c45383d 100644 --- a/VDS/Components/Breadcrumbs/Breadcrumbs.swift +++ b/VDS/Components/Breadcrumbs/Breadcrumbs.swift @@ -109,8 +109,8 @@ open class Breadcrumbs: View { // MARK: - Overrides //-------------------------------------------------- /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() + open override func setup() { + super.setup() containerView.addSubview(collectionView) collectionView.pinToSuperView() addSubview(containerView) diff --git a/VDS/Components/Calendar/Calendar.swift b/VDS/Components/Calendar/Calendar.swift index bed772d8..e7c2cb20 100644 --- a/VDS/Components/Calendar/Calendar.swift +++ b/VDS/Components/Calendar/Calendar.swift @@ -125,10 +125,6 @@ open class CalendarBase: Control, Changeable { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - open override func initialSetup() { - super.initialSetup() - } - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() diff --git a/VDS/Components/Carousel/Carousel.swift b/VDS/Components/Carousel/Carousel.swift index d1624253..766a7a70 100644 --- a/VDS/Components/Carousel/Carousel.swift +++ b/VDS/Components/Carousel/Carousel.swift @@ -196,11 +196,6 @@ open class Carousel: View { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() - } - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() diff --git a/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift b/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift index f171c395..8a4d4a50 100644 --- a/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift +++ b/VDS/Components/CarouselScrollbar/CarouselScrollbar.swift @@ -235,10 +235,6 @@ open class CarouselScrollbar: View { //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - open override func initialSetup() { - super.initialSetup() - } - open override func setup() { super.setup() isAccessibilityElement = false diff --git a/VDS/Components/Pagination/Pagination.swift b/VDS/Components/Pagination/Pagination.swift index 02c1e85e..6234e155 100644 --- a/VDS/Components/Pagination/Pagination.swift +++ b/VDS/Components/Pagination/Pagination.swift @@ -95,8 +95,8 @@ open class Pagination: View { // MARK: - Overrides //-------------------------------------------------- /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() + open override func setup() { + super.setup() collectionContainerView.addSubview(collectionView) containerView.addSubview(previousButton) diff --git a/VDS/Components/Pagination/PaginationButton.swift b/VDS/Components/Pagination/PaginationButton.swift index d5de6e3f..14f399b9 100644 --- a/VDS/Components/Pagination/PaginationButton.swift +++ b/VDS/Components/Pagination/PaginationButton.swift @@ -60,8 +60,8 @@ open class PaginationButton: ButtonBase { // MARK: - Overrides //-------------------------------------------------- /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() + open override func setup() { + super.setup() if #available(iOS 15.0, *) { configuration = buttonConfiguration } else { diff --git a/VDS/Components/Table/Table.swift b/VDS/Components/Table/Table.swift index bb599545..95873d33 100644 --- a/VDS/Components/Table/Table.swift +++ b/VDS/Components/Table/Table.swift @@ -92,8 +92,8 @@ open class Table: View { //-------------------------------------------------- ///Called upon initializing the table view - open override func initialSetup() { - super.initialSetup() + open override func setup() { + super.setup() addSubview(matrixView) matrixView.pinToSuperView() } From 0decdb5a1685189f0fc9f5435ebec1015ba2f8b2 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 13:19:33 -0500 Subject: [PATCH 07/13] add the touchUpInside since this is the only one using this Signed-off-by: Matt Bruce --- .../Icon/ButtonIcon/ButtonIcon.swift | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift index bf8a50f7..95406fb4 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift @@ -402,17 +402,15 @@ open class ButtonIcon: Control, Changeable { centerXConstraint?.activate() centerYConstraint = icon.centerYAnchor.constraint(equalTo: iconLayoutGuide.centerYAnchor, constant: 0) centerYConstraint?.activate() - } - - /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() - onClick = { control in - guard control.isEnabled else { return } - if control.selectedIconName != nil && control.selectable { - control.toggle() - } - } + + publisher(for: .touchUpInside) + .sink(receiveValue: { [weak self] _ in + guard let self, isEnabled, + selectedIconName != nil, + selectable else { return } + toggle() + }) + .store(in: &subscribers) } /// This will change the state of the Selector and execute the actionBlock if provided. From 09886ffe26efec41de21a7c76f9cda091820f055 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 14:35:51 -0500 Subject: [PATCH 08/13] added setDefaults() into protocol and implemented Signed-off-by: Matt Bruce --- VDS/BaseClasses/Control.swift | 23 ++++++++++++------- VDS/BaseClasses/View.swift | 16 +++++++++---- VDS/Components/Buttons/ButtonBase.swift | 18 +++++++++------ VDS/Components/Label/Label.swift | 20 ++++++++-------- .../TextFields/InputField/TextField.swift | 16 ++++++++++--- .../TextFields/TextArea/TextView.swift | 14 ++++++++--- VDS/Protocols/ViewProtocol.swift | 5 +++- 7 files changed, 77 insertions(+), 35 deletions(-) diff --git a/VDS/BaseClasses/Control.swift b/VDS/BaseClasses/Control.swift index ad138db9..7ebe3824 100644 --- a/VDS/BaseClasses/Control.swift +++ b/VDS/BaseClasses/Control.swift @@ -83,17 +83,25 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { initialSetupPerformed = true shouldUpdateView = false setup() + setDefaults() shouldUpdateView = true setNeedsUpdate() } } open func setup() { - backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } - + + open func setDefaults() { + backgroundColor = .clear + surface = .light + isEnabled = true + onClick = nil + userInfo.removeAll() + } + open func updateView() { } open func updateAccessibility() { @@ -110,13 +118,12 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { } } - + open func reset() { - backgroundColor = .clear - surface = .light - isEnabled = true - onClick = nil - userInfo.removeAll() + shouldUpdateView = false + setDefaults() + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/BaseClasses/View.swift b/VDS/BaseClasses/View.swift index b8acb096..911daa69 100644 --- a/VDS/BaseClasses/View.swift +++ b/VDS/BaseClasses/View.swift @@ -62,17 +62,24 @@ open class View: UIView, ViewProtocol, UserInfoable { initialSetupPerformed = true shouldUpdateView = false setup() + setDefaults() shouldUpdateView = true setNeedsUpdate() } } open func setup() { - backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false insetsLayoutMarginsFromSafeArea = false } + open func setDefaults() { + backgroundColor = .clear + surface = .light + isEnabled = true + userInfo.removeAll() + } + open func updateView() { } open func updateAccessibility() { @@ -84,9 +91,10 @@ open class View: UIView, ViewProtocol, UserInfoable { } open func reset() { - backgroundColor = .clear - surface = .light - isEnabled = true + shouldUpdateView = false + setDefaults() + shouldUpdateView = true + setNeedsUpdate() } open override func layoutSubviews() { diff --git a/VDS/Components/Buttons/ButtonBase.swift b/VDS/Components/Buttons/ButtonBase.swift index 8af0ee68..b555218d 100644 --- a/VDS/Components/Buttons/ButtonBase.swift +++ b/VDS/Components/Buttons/ButtonBase.swift @@ -102,6 +102,7 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { initialSetupPerformed = true shouldUpdateView = false setup() + setDefaults() shouldUpdateView = true setNeedsUpdate() } @@ -109,12 +110,20 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { open func setup() { - backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false + } + + open func setDefaults() { + backgroundColor = .clear accessibilityCustomActions = [] titleLabel?.adjustsFontSizeToFitWidth = false titleLabel?.lineBreakMode = .byTruncatingTail titleLabel?.numberOfLines = 1 + surface = .light + isEnabled = true + text = nil + onClick = nil + userInfo.removeAll() } open func updateView() { @@ -131,12 +140,7 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable { open func reset() { shouldUpdateView = false - surface = .light - isEnabled = true - text = nil - accessibilityCustomActions = [] - onClick = nil - userInfo.removeAll() + setDefaults() shouldUpdateView = true setNeedsUpdate() } diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 5930dea7..245dcf81 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -197,6 +197,7 @@ open class Label: UILabel, ViewProtocol, UserInfoable { initialSetupPerformed = true shouldUpdateView = false setup() + setDefaults() shouldUpdateView = true setNeedsUpdate() } @@ -209,27 +210,28 @@ open class Label: UILabel, ViewProtocol, UserInfoable { .sink { [weak self] notification in self?.setNeedsUpdate() }.store(in: &subscribers) - backgroundColor = .clear - numberOfLines = 0 - lineBreakMode = .byTruncatingTail translatesAutoresizingMaskIntoConstraints = false - accessibilityCustomActions = [] isAccessibilityElement = true - accessibilityTraits = .staticText - textAlignment = .left } - open func reset() { - shouldUpdateView = false + open func setDefaults() { + backgroundColor = .clear + accessibilityTraits = .staticText + accessibilityCustomActions = [] surface = .light isEnabled = true attributes = nil textStyle = .defaultStyle + lineBreakMode = .byTruncatingTail textAlignment = .left text = nil attributedText = nil numberOfLines = 0 - backgroundColor = .clear + } + + open func reset() { + shouldUpdateView = false + setDefaults() shouldUpdateView = true setNeedsUpdate() } diff --git a/VDS/Components/TextFields/InputField/TextField.swift b/VDS/Components/TextFields/InputField/TextField.swift index 2f6ddb1a..9fb8d7f6 100644 --- a/VDS/Components/TextFields/InputField/TextField.swift +++ b/VDS/Components/TextFields/InputField/TextField.swift @@ -103,13 +103,13 @@ open class TextField: UITextField, ViewProtocol, Errorable { initialSetupPerformed = true shouldUpdateView = false setup() + setDefaults() shouldUpdateView = true setNeedsUpdate() } } open func setup() { - backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false setContentCompressionResistancePriority(.defaultLow, for: .horizontal) clipsToBounds = true @@ -127,6 +127,17 @@ open class TextField: UITextField, ViewProtocol, Errorable { inputAccessoryView = accessView } + open func setDefaults() { + backgroundColor = .clear + surface = .light + text = nil + formatText = nil + useScaledFont = false + showError = false + errorText = nil + textStyle = .defaultStyle + } + @objc func doneButtonAction() { // Resigns the first responder status when 'Done' is tapped let _ = resignFirstResponder() @@ -177,8 +188,7 @@ open class TextField: UITextField, ViewProtocol, Errorable { open func reset() { shouldUpdateView = false - surface = .light - text = nil + setDefaults() shouldUpdateView = true setNeedsUpdate() } diff --git a/VDS/Components/TextFields/TextArea/TextView.swift b/VDS/Components/TextFields/TextArea/TextView.swift index 575c2da8..b8098a49 100644 --- a/VDS/Components/TextFields/TextArea/TextView.swift +++ b/VDS/Components/TextFields/TextArea/TextView.swift @@ -112,13 +112,13 @@ open class TextView: UITextView, ViewProtocol, Errorable { initialSetupPerformed = true shouldUpdateView = false setup() + setDefaults() shouldUpdateView = true setNeedsUpdate() } } open func setup() { - backgroundColor = .clear translatesAutoresizingMaskIntoConstraints = false let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44))) @@ -137,6 +137,15 @@ open class TextView: UITextView, ViewProtocol, Errorable { placeholderLabel.pinToSuperView() } + open func setDefaults() { + backgroundColor = .clear + surface = .light + text = nil + placeholder = nil + errorText = nil + showError = false + } + @objc func doneButtonAction() { // Resigns the first responder status when 'Done' is tapped resignFirstResponder() @@ -156,8 +165,7 @@ open class TextView: UITextView, ViewProtocol, Errorable { open func reset() { shouldUpdateView = false - surface = .light - text = nil + setDefaults() shouldUpdateView = true setNeedsUpdate() } diff --git a/VDS/Protocols/ViewProtocol.swift b/VDS/Protocols/ViewProtocol.swift index 695386cb..9a509dc1 100644 --- a/VDS/Protocols/ViewProtocol.swift +++ b/VDS/Protocols/ViewProtocol.swift @@ -21,7 +21,10 @@ public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surface /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. func setup() - + + /// Default configurations for values and properties. This is called in the setup() and reset(). + func setDefaults() + /// Used to make changes to the View based off a change events or from local properties. func updateView() From 973e25034e1b404e2d0cb72984c73740a6647714 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 14:37:08 -0500 Subject: [PATCH 09/13] reverted back to onClick() since I found the issue in reset() Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 12 +++++------- VDS/Components/Toggle/ToggleView.swift | 10 ++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 29f7dd6d..260fdc31 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -157,13 +157,11 @@ open class Toggle: Control, Changeable, FormFieldable { /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() - - publisher(for: .touchUpInside) - .sink(receiveValue: { [weak self] _ in - guard let self, isEnabled else { return } - toggle() - }) - .store(in: &subscribers) + + onClick = { [weak self] _ in + guard let self else { return } + toggle() + } isAccessibilityElement = true if #available(iOS 17.0, *) { diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index fb663e99..1ba5d605 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -109,12 +109,10 @@ open class ToggleView: Control, Changeable, FormFieldable { open override func setup() { super.setup() - publisher(for: .touchUpInside) - .sink(receiveValue: { [weak self] _ in - guard let self, isEnabled else { return } - toggle() - }) - .store(in: &subscribers) + onClick = { [weak self] _ in + guard let self else { return } + toggle() + } isAccessibilityElement = true if #available(iOS 17.0, *) { From 59294ebd511803b2926dba88223536fde8f76ed8 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 14:37:36 -0500 Subject: [PATCH 10/13] using setup() now Signed-off-by: Matt Bruce --- VDS/BaseClasses/Selector/SelectorBase.swift | 16 +++++++--------- VDS/BaseClasses/Selector/SelectorItemBase.swift | 16 ++++++---------- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/VDS/BaseClasses/Selector/SelectorBase.swift b/VDS/BaseClasses/Selector/SelectorBase.swift index 1e2f5fba..fd794479 100644 --- a/VDS/BaseClasses/Selector/SelectorBase.swift +++ b/VDS/BaseClasses/Selector/SelectorBase.swift @@ -100,9 +100,11 @@ open class SelectorBase: Control, SelectorControlable { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() + + /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. + open override func setup() { + super.setup() + onClick = { control in control.toggle() } @@ -116,14 +118,10 @@ open class SelectorBase: Control, SelectorControlable { guard let self else { return "" } return !isEnabled ? "" : "Double tap to activate." } - } - - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. - open override func setup() { - super.setup() - + isAccessibilityElement = true accessibilityTraits = .button + } open override func updateView() { diff --git a/VDS/BaseClasses/Selector/SelectorItemBase.swift b/VDS/BaseClasses/Selector/SelectorItemBase.swift index 44ed01b1..e27a9f94 100644 --- a/VDS/BaseClasses/Selector/SelectorItemBase.swift +++ b/VDS/BaseClasses/Selector/SelectorItemBase.swift @@ -157,9 +157,11 @@ open class SelectorItemBase: Control, Errorable, Changea //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() + + /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. + open override func setup() { + super.setup() + onClick = { [weak self] control in guard let self, isEnabled else { return } toggle() @@ -204,13 +206,7 @@ open class SelectorItemBase: Control, Errorable, Changea return !isEnabled ? "" : "Double tap to activate." } - } - - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. - open override func setup() { - super.setup() - - selectorView.isAccessibilityElement = true + selectorView.isAccessibilityElement = true isAccessibilityElement = false addSubview(mainStackView) From ac1957d1c3ef71f2dc5488cee23e687abcade1f1 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 14:38:32 -0500 Subject: [PATCH 11/13] using submit now Signed-off-by: Matt Bruce --- VDS/Components/RadioBox/RadioBoxItem.swift | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index 1da80c0a..4ea010e6 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -165,11 +165,13 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Executed on initialization for this View. - open override func initialSetup() { - super.initialSetup() - onClick = { control in - control.toggle() + /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. + open override func setup() { + super.setup() + + onClick = { [weak self] _ in + guard let self, isEnabled else { return } + toggle() } selectorView.bridge_accessibilityLabelBlock = { [weak self] in @@ -205,12 +207,6 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { return accessibilityLabels.joined(separator: ", ") } - } - - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. - open override func setup() { - super.setup() - isAccessibilityElement = false selectorView.isAccessibilityElement = true selectorView.accessibilityTraits = .button From fc7650f7d9f08b091d6c8ea7e3a8b7995fecb178 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 16:45:18 -0500 Subject: [PATCH 12/13] refactor toggle with setDefaults Signed-off-by: Matt Bruce --- VDS/Components/Toggle/Toggle.swift | 31 ++++++++++++++------------ VDS/Components/Toggle/ToggleView.swift | 22 ++++++++---------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 260fdc31..304b18ce 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -158,11 +158,6 @@ open class Toggle: Control, Changeable, FormFieldable { open override func setup() { super.setup() - onClick = { [weak self] _ in - guard let self else { return } - toggle() - } - isAccessibilityElement = true if #available(iOS 17.0, *) { accessibilityTraits = .toggleButton @@ -237,6 +232,16 @@ open class Toggle: Control, Changeable, FormFieldable { label.trailingAnchor.constraint(equalTo: trailingAnchor) ] + } + + open override func setDefaults() { + super.setDefaults() + + onClick = { [weak self] _ in + guard let self else { return } + toggle() + } + bridge_accessibilityValueBlock = { [weak self] in guard let self else { return "" } if showText { @@ -245,13 +250,7 @@ open class Toggle: Control, Changeable, FormFieldable { return isSelected ? "On" : "Off" } } - } - - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - label.reset() + isEnabled = true isOn = false isAnimated = true @@ -263,8 +262,12 @@ open class Toggle: Control, Changeable, FormFieldable { textPosition = .left inputId = nil onChange = nil - shouldUpdateView = true - setNeedsUpdate() + } + + /// Resets to default settings. + open override func reset() { + label.reset() + super.reset() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/Toggle/ToggleView.swift b/VDS/Components/Toggle/ToggleView.swift index 1ba5d605..2ecfd44a 100644 --- a/VDS/Components/Toggle/ToggleView.swift +++ b/VDS/Components/Toggle/ToggleView.swift @@ -109,11 +109,6 @@ open class ToggleView: Control, Changeable, FormFieldable { open override func setup() { super.setup() - onClick = { [weak self] _ in - guard let self else { return } - toggle() - } - isAccessibilityElement = true if #available(iOS 17.0, *) { accessibilityTraits = .toggleButton @@ -154,20 +149,21 @@ open class ToggleView: Control, Changeable, FormFieldable { accessibilityLabel = "Toggle" } - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false + open override func setDefaults() { + super.setDefaults() isOn = false isAnimated = true inputId = nil toggleView.backgroundColor = toggleColorConfiguration.getColor(self) knobView.backgroundColor = knobColorConfiguration.getColor(self) - onChange = nil - shouldUpdateView = true - setNeedsUpdate() + onChange = nil + + onClick = { [weak self] _ in + guard let self else { return } + toggle() + } } - + /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() From bf4ff94933014b3b42e093614f2bdd53dabd87f1 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Fri, 9 Aug 2024 16:45:35 -0500 Subject: [PATCH 13/13] moved default values into setDefaults() Signed-off-by: Matt Bruce --- VDS/BaseClasses/Selector/SelectorBase.swift | 12 +-- .../Selector/SelectorGroupBase.swift | 36 +++++---- .../Selector/SelectorItemBase.swift | 73 ++++++++++--------- VDS/Components/Badge/Badge.swift | 21 +++--- .../BadgeIndicator/BadgeIndicator.swift | 28 +++++-- .../Breadcrumbs/BreadcrumbItem.swift | 25 ++----- VDS/Components/Breadcrumbs/Breadcrumbs.swift | 5 +- VDS/Components/Buttons/Button/Button.swift | 10 +-- .../Buttons/ButtonGroup/ButtonGroup.swift | 12 +-- .../Buttons/TextLink/TextLink.swift | 33 +++------ .../Buttons/TextLinkCaret/TextLinkCaret.swift | 18 ++--- VDS/Components/Calendar/Calendar.swift | 24 +++--- VDS/Components/Carousel/Carousel.swift | 26 +++---- VDS/Components/DatePicker/DatePicker.swift | 14 ++-- .../DropdownSelect/DropdownSelect.swift | 22 +++--- .../Icon/ButtonIcon/ButtonIcon.swift | 41 ++++++----- VDS/Components/Icon/Icon.swift | 27 +++---- VDS/Components/Line/Line.swift | 9 +-- .../Notification/Notification.swift | 23 +++--- VDS/Components/RadioBox/RadioBoxItem.swift | 66 ++++++++--------- .../RadioButton/RadioButtonGroup.swift | 9 ++- VDS/Components/Table/Table.swift | 8 +- VDS/Components/Tabs/Tabs.swift | 15 ++-- .../TextFields/EntryFieldBase.swift | 66 +++++++++-------- .../TextFields/InputField/InputField.swift | 30 ++++---- .../TextFields/TextArea/TextArea.swift | 13 +++- .../TileContainer/TileContainer.swift | 13 ++-- VDS/Components/Tilelet/Tilelet.swift | 11 ++- VDS/Components/TitleLockup/TitleLockup.swift | 9 +-- VDS/Components/Tooltip/Tooltip.swift | 18 ++--- .../Tooltip/TrailingTooltipLabel.swift | 8 +- 31 files changed, 361 insertions(+), 364 deletions(-) diff --git a/VDS/BaseClasses/Selector/SelectorBase.swift b/VDS/BaseClasses/Selector/SelectorBase.swift index fd794479..05c8a1e8 100644 --- a/VDS/BaseClasses/Selector/SelectorBase.swift +++ b/VDS/BaseClasses/Selector/SelectorBase.swift @@ -104,11 +104,17 @@ open class SelectorBase: Control, SelectorControlable { /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() + isAccessibilityElement = true + accessibilityTraits = .button + } + + open override func setDefaults() { + super.setDefaults() onClick = { control in control.toggle() } - + bridge_accessibilityLabelBlock = { [weak self] in guard let self else { return "" } return "\(Self.self)\(showError ? ", error" : "")" @@ -118,10 +124,6 @@ open class SelectorBase: Control, SelectorControlable { guard let self else { return "" } return !isEnabled ? "" : "Double tap to activate." } - - isAccessibilityElement = true - accessibilityTraits = .button - } open override func updateView() { diff --git a/VDS/BaseClasses/Selector/SelectorGroupBase.swift b/VDS/BaseClasses/Selector/SelectorGroupBase.swift index 4df1ca5c..5cda9c82 100644 --- a/VDS/BaseClasses/Selector/SelectorGroupBase.swift +++ b/VDS/BaseClasses/Selector/SelectorGroupBase.swift @@ -65,25 +65,30 @@ open class SelectorGroupBase: Control, SelectorGrou } didSet { + setItemsActions() for selector in items { - selector.onClick = { [weak self] handler in - self?.didSelect(handler) - self?.setNeedsUpdate() - } - - selector.accessibilityAction = { [weak self] handler in - guard let handler = handler as? SelectorItemType else { return } - self?.didSelect(handler) - self?.setNeedsUpdate() - } - mainStackView.addArrangedSubview(selector) } } } open var onChangeSubscriber: AnyCancellable? - + + private func setItemsActions() { + for selector in items { + selector.onClick = { [weak self] handler in + self?.didSelect(handler) + self?.setNeedsUpdate() + } + + selector.accessibilityAction = { [weak self] handler in + guard let handler = handler as? SelectorItemType else { return } + self?.didSelect(handler) + self?.setNeedsUpdate() + } + } + } + /// Whether the Control is enabled or not. override open var isEnabled: Bool { didSet { @@ -115,6 +120,11 @@ open class SelectorGroupBase: Control, SelectorGrou .pinBottom(0, .defaultHigh) } + open override func setDefaults() { + super.setDefaults() + onChange = nil + } + /// Handler for the Group to override on a select event. /// - Parameter selectedControl: Selected Control the user interacted. open func didSelect(_ selectedControl: SelectorItemType) { @@ -131,8 +141,8 @@ open class SelectorGroupBase: Control, SelectorGrou /// Resets to default settings. open override func reset() { super.reset() - onChange = nil items.forEach{ $0.reset() } + setItemsActions() } } diff --git a/VDS/BaseClasses/Selector/SelectorItemBase.swift b/VDS/BaseClasses/Selector/SelectorItemBase.swift index e27a9f94..90aaed14 100644 --- a/VDS/BaseClasses/Selector/SelectorItemBase.swift +++ b/VDS/BaseClasses/Selector/SelectorItemBase.swift @@ -161,6 +161,27 @@ open class SelectorItemBase: Control, Errorable, Changea /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() + + selectorView.isAccessibilityElement = true + isAccessibilityElement = false + addSubview(mainStackView) + + mainStackView.isUserInteractionEnabled = false + mainStackView.addArrangedSubview(selectorStackView) + mainStackView.addArrangedSubview(errorLabel) + selectorStackView.addArrangedSubview(selectorView) + selectorStackView.addArrangedSubview(selectorLabelStackView) + selectorLabelStackView.addArrangedSubview(label) + selectorLabelStackView.addArrangedSubview(childLabel) + mainStackView + .pinTop() + .pinLeading() + .pinTrailing() + .pinBottom(0, .defaultHigh) + } + + open override func setDefaults() { + super.setDefaults() onClick = { [weak self] control in guard let self, isEnabled else { return } @@ -205,23 +226,23 @@ open class SelectorItemBase: Control, Errorable, Changea guard let self else { return "" } return !isEnabled ? "" : "Double tap to activate." } + + label.textStyle = .boldBodyLarge + childLabel.textStyle = .bodyLarge + errorLabel.textStyle = .bodyMedium - selectorView.isAccessibilityElement = true - isAccessibilityElement = false - addSubview(mainStackView) + labelText = nil + labelTextAttributes = nil + labelAttributedText = nil + childText = nil + childTextAttributes = nil + childAttributedText = nil + showError = false + errorText = nil + inputId = nil + isSelected = false - mainStackView.isUserInteractionEnabled = false - mainStackView.addArrangedSubview(selectorStackView) - mainStackView.addArrangedSubview(errorLabel) - selectorStackView.addArrangedSubview(selectorView) - selectorStackView.addArrangedSubview(selectorLabelStackView) - selectorLabelStackView.addArrangedSubview(label) - selectorLabelStackView.addArrangedSubview(childLabel) - mainStackView - .pinTop() - .pinLeading() - .pinTrailing() - .pinBottom(0, .defaultHigh) + onChange = nil } /// Used to make changes to the View based off a change events or from local properties. @@ -277,30 +298,10 @@ open class SelectorItemBase: Control, Errorable, Changea /// Resets to default settings. open override func reset() { - super.reset() - shouldUpdateView = false label.reset() childLabel.reset() errorLabel.reset() - - label.textStyle = .boldBodyLarge - childLabel.textStyle = .bodyLarge - errorLabel.textStyle = .bodyMedium - - labelText = nil - labelTextAttributes = nil - labelAttributedText = nil - childText = nil - childTextAttributes = nil - childAttributedText = nil - showError = false - errorText = nil - inputId = nil - isSelected = false - - onChange = nil - shouldUpdateView = true - setNeedsUpdate() + super.reset() } //-------------------------------------------------- diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 07477f5f..1c47133f 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -149,25 +149,28 @@ open class Badge: View { maxWidthConstraint = label.widthLessThanEqualTo(constant: 0).with { $0.isActive = false } clipsToBounds = true + } + + open override func setDefaults() { + super.setDefaults() + bridge_accessibilityLabelBlock = { [weak self] in guard let self else { return "" } return text } - } - - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - label.reset() + label.lineBreakMode = .byTruncatingTail label.textStyle = .boldBodySmall fillColor = .red text = "" maxWidth = nil numberOfLines = 1 - shouldUpdateView = true - setNeedsUpdate() + } + + /// Resets to default settings. + open override func reset() { + label.reset() + super.reset() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/BadgeIndicator/BadgeIndicator.swift b/VDS/Components/BadgeIndicator/BadgeIndicator.swift index 13a6cb21..dc200cd8 100644 --- a/VDS/Components/BadgeIndicator/BadgeIndicator.swift +++ b/VDS/Components/BadgeIndicator/BadgeIndicator.swift @@ -305,17 +305,31 @@ open class BadgeIndicator: View { } } - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - label.reset() + open override func setDefaults() { + super.setDefaults() label.lineBreakMode = .byTruncatingTail label.textAlignment = .center fillColor = .red number = nil - shouldUpdateView = true - setNeedsUpdate() + kind = .simple + leadingCharacter = nil + trailingText = nil + size = .xxlarge + dotSize = nil + verticalPadding = nil + horizontalPadding = nil + hideDot = false + hideBorder = false + width = nil + height = nil + accessibilityText = nil + maximumDigits = .two + } + + /// Resets to default settings. + open override func reset() { + label.reset() + super.reset() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/Breadcrumbs/BreadcrumbItem.swift b/VDS/Components/Breadcrumbs/BreadcrumbItem.swift index 66f62989..cdb6011e 100644 --- a/VDS/Components/Breadcrumbs/BreadcrumbItem.swift +++ b/VDS/Components/Breadcrumbs/BreadcrumbItem.swift @@ -72,17 +72,15 @@ open class BreadcrumbItem: ButtonBase { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. - open override func setup() { - super.setup() - + open override func setDefaults() { + super.setDefaults() + isAccessibilityElement = true + accessibilityTraits = .link + titleLabel?.numberOfLines = 0 titleLabel?.lineBreakMode = .byWordWrapping contentHorizontalAlignment = .left - isAccessibilityElement = true - accessibilityTraits = .link - bridge_accessibilityHintBlock = { [weak self] in guard let self else { return "" } return !isEnabled ? "" : "Double tap to open." @@ -131,17 +129,4 @@ open class BreadcrumbItem: ButtonBase { } } - - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - text = nil - accessibilityCustomActions = [] - isAccessibilityElement = true - accessibilityTraits = .button - shouldUpdateView = true - setNeedsUpdate() - } - } diff --git a/VDS/Components/Breadcrumbs/Breadcrumbs.swift b/VDS/Components/Breadcrumbs/Breadcrumbs.swift index 6c45383d..1179807d 100644 --- a/VDS/Components/Breadcrumbs/Breadcrumbs.swift +++ b/VDS/Components/Breadcrumbs/Breadcrumbs.swift @@ -116,14 +116,11 @@ open class Breadcrumbs: View { addSubview(containerView) containerView.pinToSuperView() } - + /// Resets to default settings. open override func reset() { super.reset() - shouldUpdateView = false breadcrumbs.forEach { $0.reset() } - shouldUpdateView = true - setNeedsUpdate() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index 0b9d13f1..9569e3e7 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -223,16 +223,12 @@ open class Button: ButtonBase, Useable { isAccessibilityElement = true accessibilityTraits = .button } - - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false + + open override func setDefaults() { + super.setDefaults() use = .primary width = nil size = .large - shouldUpdateView = true - setNeedsUpdate() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift index 8b662070..486301c7 100644 --- a/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift +++ b/VDS/Components/Buttons/ButtonGroup/ButtonGroup.swift @@ -167,15 +167,17 @@ open class ButtonGroup: View { collectionView.reloadData() } - open override func reset() { - super.reset() - shouldUpdateView = false + open override func setDefaults() { + super.setDefaults() rowQuantityPhone = 0 rowQuantityTablet = 0 alignment = .center + childWidth = nil + } + + open override func reset() { buttons.forEach { $0.reset() } - shouldUpdateView = true - setNeedsUpdate() + super.reset() } open override func layoutSubviews() { diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 70f2840b..b002c712 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -91,12 +91,7 @@ open class TextLink: ButtonBase { open override func setup() { super.setup() isAccessibilityElement = true - accessibilityTraits = .link - - //left align titleLabel in case this is pinned leading/trailing - //default is always set to center - contentHorizontalAlignment = .left - + if let titleLabel { addSubview(line) line.pinLeading(titleLabel.leadingAnchor) @@ -106,12 +101,21 @@ open class TextLink: ButtonBase { lineHeightConstraint = line.height(constant: 1) lineHeightConstraint?.isActive = true } + } + + open override func setDefaults() { + super.setDefaults() + size = .large + accessibilityTraits = .link + //left align titleLabel in case this is pinned leading/trailing + //default is always set to center + contentHorizontalAlignment = .left + bridge_accessibilityHintBlock = { [weak self] in guard let self else { return "" } return !isEnabled ? "" : "Double tap to open." } - } /// Used to make changes to the View based off a change events or from local properties. @@ -123,18 +127,5 @@ open class TextLink: ButtonBase { //always call last so the label is rendered super.updateView() } - - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - text = nil - size = .large - accessibilityCustomActions = [] - isAccessibilityElement = true - accessibilityTraits = .link - shouldUpdateView = true - setNeedsUpdate() - } - + } diff --git a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift index f8c86a44..e8806daa 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -76,10 +76,8 @@ open class TextLinkCaret: ButtonBase { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. - open override func setup() { - super.setup() - + open override func setDefaults() { + super.setDefaults() //left align titleLabel in case this is pinned leading/trailing //default is always set to center contentHorizontalAlignment = .left @@ -88,11 +86,12 @@ open class TextLinkCaret: ButtonBase { titleLabel?.numberOfLines = 0 titleLabel?.lineBreakMode = .byWordWrapping + iconPosition = .right + bridge_accessibilityHintBlock = { [weak self] in guard let self else { return "" } return !isEnabled ? "" : "Double tap to open." } - } /// Used to make changes to the View based off a change events or from local properties. @@ -100,14 +99,7 @@ open class TextLinkCaret: ButtonBase { imageAttribute = CaretLabelAttribute(tintColor: textColor, position: iconPosition) super.updateView() } - - /// Resets to default settings. - open override func reset() { - super.reset() - iconPosition = .right - text = nil - } - + /// The natural size for the receiving view, considering only properties of the view itself. open override var intrinsicContentSize: CGSize { guard let titleLabel else { return super.intrinsicContentSize } diff --git a/VDS/Components/Calendar/Calendar.swift b/VDS/Components/Calendar/Calendar.swift index e7c2cb20..0a6ba18c 100644 --- a/VDS/Components/Calendar/Calendar.swift +++ b/VDS/Components/Calendar/Calendar.swift @@ -150,6 +150,19 @@ open class CalendarBase: Control, Changeable { collectionView.pinCenterX(anchor: containerView.centerXAnchor) } + + open override func setDefaults() { + super.setDefaults() + hideContainerBorder = false + hideCurrentDateIndicator = false + transparentBackground = false + activeDates = [] + inactiveDates = [] + indicators = [] + minDate = Date() + maxDate = Date() + selectedDate = Date() + } open override func updateView() { super.updateView() @@ -170,17 +183,6 @@ open class CalendarBase: Control, Changeable { containerView.layer.borderWidth = VDSFormControls.borderWidth } } - - /// Resets to default settings. - open override func reset() { - super.reset() - hideContainerBorder = false - hideCurrentDateIndicator = false - transparentBackground = false - activeDates = [] - inactiveDates = [] - indicators = [] - } //-------------------------------------------------- // MARK: - Private Methods diff --git a/VDS/Components/Carousel/Carousel.swift b/VDS/Components/Carousel/Carousel.swift index 766a7a70..f8d62520 100644 --- a/VDS/Components/Carousel/Carousel.swift +++ b/VDS/Components/Carousel/Carousel.swift @@ -244,6 +244,18 @@ open class Carousel: View { updatePaginationInset() } + open override func setDefaults() { + super.setDefaults() + gutter = UIDevice.isIPad ? .gutter6X : .gutter3X + layout = UIDevice.isIPad ? .threeUP : .oneUP + onChange = nil + pagination = .init(kind: .lowContrast, floating: true) + paginationDisplay = .none + paginationInset = UIDevice.isIPad ? VDSLayout.space3X : VDSLayout.space2X + peek = .standard + groupIndex = 0 + } + /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() @@ -274,19 +286,7 @@ open class Carousel: View { updatePaginationControls() addCarouselSlots() } - - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - layout = UIDevice.isIPad ? .threeUP : .oneUP - pagination = .init(kind: .lowContrast, floating: true) - paginationDisplay = .none - paginationInset = UIDevice.isIPad ? VDSLayout.space3X : VDSLayout.space2X - gutter = UIDevice.isIPad ? .gutter6X : .gutter3X - peek = .standard - } - + //-------------------------------------------------- // MARK: - Private Methods //-------------------------------------------------- diff --git a/VDS/Components/DatePicker/DatePicker.swift b/VDS/Components/DatePicker/DatePicker.swift index df7cc7c9..9a95124c 100644 --- a/VDS/Components/DatePicker/DatePicker.swift +++ b/VDS/Components/DatePicker/DatePicker.swift @@ -174,6 +174,14 @@ open class DatePicker: EntryFieldBase { popoverOverlayView.isHidden = true } + open override func setDefaults() { + super.setDefaults() + selectedDate = nil + calendarModel = .init() + dateFormat = .shortNumeric + selectedDateLabel.textStyle = .bodyLarge + } + open override func getFieldContainer() -> UIView { // stackview for controls in EntryFieldBase.controlContainerView let controlStackView = UIStackView().with { @@ -200,12 +208,6 @@ open class DatePicker: EntryFieldBase { calendarIcon.color = iconColorConfiguration.getColor(self) } - /// Resets to default settings. - open override func reset() { - super.reset() - selectedDateLabel.textStyle = .bodyLarge - } - internal func formatDate(_ date: Date) { let formatter = DateFormatter() formatter.dateFormat = dateFormat.format diff --git a/VDS/Components/DropdownSelect/DropdownSelect.swift b/VDS/Components/DropdownSelect/DropdownSelect.swift index 947210f4..ab2c1195 100644 --- a/VDS/Components/DropdownSelect/DropdownSelect.swift +++ b/VDS/Components/DropdownSelect/DropdownSelect.swift @@ -162,6 +162,17 @@ open class DropdownSelect: EntryFieldBase { containerView.height(44) } + open override func setDefaults() { + super.setDefaults() + showInlineLabel = false + selectId = nil + inlineDisplayLabel.textStyle = .boldBodyLarge + selectedOptionLabel.textStyle = .bodyLarge + showInlineLabel = false + options = [] + selectId = nil + } + open override func getFieldContainer() -> UIView { let controlStackView = UIStackView().with { $0.translatesAutoresizingMaskIntoConstraints = false @@ -188,17 +199,6 @@ open class DropdownSelect: EntryFieldBase { selectedOptionLabel.surface = surface selectedOptionLabel.isEnabled = isEnabled } - - /// Resets to default settings. - open override func reset() { - super.reset() - - inlineDisplayLabel.textStyle = .boldBodyLarge - selectedOptionLabel.textStyle = .bodyLarge - showInlineLabel = false - options = [] - selectId = nil - } //-------------------------------------------------- // MARK: - Public Methods diff --git a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift index 95406fb4..b6b51601 100644 --- a/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift +++ b/VDS/Components/Icon/ButtonIcon/ButtonIcon.swift @@ -413,6 +413,27 @@ open class ButtonIcon: Control, Changeable { .store(in: &subscribers) } + open override func setDefaults() { + super.setDefaults() + badgeIndicatorModel = nil + kind = .ghost + surfaceType = .colorFill + iconName = nil + selectedIconName = nil + selectedIconColorConfiguration = nil + size = .large + floating = false + fitToIcon = false + hideBorder = true + showBadgeIndicator = false + selectable = false + iconOffset = .init(x: 0, y: 0) + customContainerSize = nil + customIconSize = nil + customBadgeIndicatorOffset = nil + onChange = nil + } + /// This will change the state of the Selector and execute the actionBlock if provided. open func toggle() { //removed error @@ -420,26 +441,6 @@ open class ButtonIcon: Control, Changeable { sendActions(for: .valueChanged) } - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - kind = .ghost - surfaceType = .colorFill - size = .large - floating = false - hideBorder = true - iconOffset = .init(x: 0, y: 0) - iconName = nil - selectedIconName = nil - showBadgeIndicator = false - selectable = false - badgeIndicatorModel = nil - onChange = nil - shouldUpdateView = true - setNeedsUpdate() - } - /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() diff --git a/VDS/Components/Icon/Icon.swift b/VDS/Components/Icon/Icon.swift index fd5c5fb2..8e19bf5c 100644 --- a/VDS/Components/Icon/Icon.swift +++ b/VDS/Components/Icon/Icon.swift @@ -90,22 +90,29 @@ open class Icon: View { addSubview(imageView) imageView.pinToSuperView() - - backgroundColor = .clear - + isAccessibilityElement = true accessibilityTraits = .none - accessibilityHint = "image" + + } + + open override func setDefaults() { + super.setDefaults() + backgroundColor = .clear + color = VDSColor.paletteBlack + size = .medium + name = nil + customSize = nil + imageView.image = nil + accessibilityHint = "image" bridge_accessibilityLabelBlock = { [weak self] in guard let self else { return "" } return name?.rawValue ?? "icon" } - - - } + /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() @@ -123,12 +130,6 @@ open class Icon: View { invalidateIntrinsicContentSize() } - /// Resets to default settings. - open override func reset() { - super.reset() - color = VDSColor.paletteBlack - imageView.image = nil - } } extension UIImage { diff --git a/VDS/Components/Line/Line.swift b/VDS/Components/Line/Line.swift index 627210f9..06accf07 100644 --- a/VDS/Components/Line/Line.swift +++ b/VDS/Components/Line/Line.swift @@ -81,11 +81,6 @@ open class Line: View { //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- - /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. - open override func setup() { - super.setup() - } - /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { super.updateView() @@ -94,8 +89,8 @@ open class Line: View { } /// Resets to default settings. - open override func reset() { - super.reset() + open override func setDefaults() { + super.setDefaults() style = .primary orientation = .horizontal } diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index 6df7da68..e188faf7 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -274,20 +274,13 @@ open class Notification: View { } } - /// Resets to default settings. - open override func reset() { - super.reset() - - shouldUpdateView = false - - titleLabel.reset() + open override func setDefaults() { + super.setDefaults() titleLabel.text = "" titleLabel.textStyle = UIDevice.isIPad ? .boldBodyLarge : .boldBodySmall - subTitleLabel.reset() subTitleLabel.textStyle = UIDevice.isIPad ? .bodyLarge : .bodySmall - buttonGroup.reset() buttonGroup.alignment = .left primaryButtonModel = nil @@ -302,9 +295,15 @@ open class Notification: View { closeButton.name = .close hideCloseButton = false - - shouldUpdateView = true - setNeedsUpdate() + + } + + /// Resets to default settings. + open override func reset() { + titleLabel.reset() + subTitleLabel.reset() + buttonGroup.reset() + super.reset() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/RadioBox/RadioBoxItem.swift b/VDS/Components/RadioBox/RadioBoxItem.swift index 4ea010e6..a5ca1d8b 100644 --- a/VDS/Components/RadioBox/RadioBoxItem.swift +++ b/VDS/Components/RadioBox/RadioBoxItem.swift @@ -168,6 +168,31 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { /// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations. open override func setup() { super.setup() + + isAccessibilityElement = false + selectorView.isAccessibilityElement = true + selectorView.accessibilityTraits = .button + addSubview(selectorView) + selectorView.isUserInteractionEnabled = false + + selectorView.addSubview(selectorStackView) + + selectorStackView.addArrangedSubview(selectorLeftLabelStackView) + selectorStackView.addArrangedSubview(subTextRightLabel) + selectorLeftLabelStackView.addArrangedSubview(textLabel) + selectorLeftLabelStackView.addArrangedSubview(subTextLabel) + + selectorView + .pinTop() + .pinLeading() + .pinTrailing(0, .defaultHigh) + .pinBottom(0, .defaultHigh) + + selectorStackView.pinToSuperView(.uniform(VDSLayout.space3X)) + } + + open override func setDefaults() { + super.setDefaults() onClick = { [weak self] _ in guard let self, isEnabled else { return } @@ -206,37 +231,7 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { return accessibilityLabels.joined(separator: ", ") } - - isAccessibilityElement = false - selectorView.isAccessibilityElement = true - selectorView.accessibilityTraits = .button - addSubview(selectorView) - selectorView.isUserInteractionEnabled = false - - selectorView.addSubview(selectorStackView) - - selectorStackView.addArrangedSubview(selectorLeftLabelStackView) - selectorStackView.addArrangedSubview(subTextRightLabel) - selectorLeftLabelStackView.addArrangedSubview(textLabel) - selectorLeftLabelStackView.addArrangedSubview(subTextLabel) - - selectorView - .pinTop() - .pinLeading() - .pinTrailing(0, .defaultHigh) - .pinBottom(0, .defaultHigh) - - selectorStackView.pinToSuperView(.uniform(VDSLayout.space3X)) - } - - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - textLabel.reset() - subTextLabel.reset() - subTextRightLabel.reset() - + textLabel.textStyle = .boldBodyLarge subTextLabel.textStyle = .bodyLarge subTextRightLabel.textStyle = .bodyLarge @@ -256,9 +251,14 @@ open class RadioBoxItem: Control, Changeable, FormFieldable, Groupable { isSelected = false onChange = nil + } - shouldUpdateView = true - setNeedsUpdate() + /// Resets to default settings. + open override func reset() { + textLabel.reset() + subTextLabel.reset() + subTextRightLabel.reset() + super.reset() } /// This will change the state of the Selector and execute the actionBlock if provided. diff --git a/VDS/Components/RadioButton/RadioButtonGroup.swift b/VDS/Components/RadioButton/RadioButtonGroup.swift index 13adf080..5d323997 100644 --- a/VDS/Components/RadioButton/RadioButtonGroup.swift +++ b/VDS/Components/RadioButton/RadioButtonGroup.swift @@ -77,12 +77,13 @@ open class RadioButtonGroup: SelectorGroupBase, SelectorGroupSi } } - open override func reset() { - super.reset() + open override func setDefaults() { + super.setDefaults() + inputId = nil showError = false } - - public override func didSelect(_ selectedControl: RadioButtonItem) { + + open override func didSelect(_ selectedControl: RadioButtonItem) { if let selectedItem { updateToggle(selectedItem) } diff --git a/VDS/Components/Table/Table.swift b/VDS/Components/Table/Table.swift index 95873d33..21fe00a4 100644 --- a/VDS/Components/Table/Table.swift +++ b/VDS/Components/Table/Table.swift @@ -109,18 +109,16 @@ open class Table: View { matrixView.collectionViewLayout.invalidateLayout() } - /// Resets to default settings. - open override func reset() { - super.reset() + open override func setDefaults() { + super.setDefaults() striped = false padding = .standard tableHeader = [] tableRows = [] fillContainer = true columnWidths = nil - setNeedsUpdate() } - + func calculateColumnWidths() -> [CGFloat] { guard let noOfColumns = tableData.first?.columnsCount else { return [] } let itemWidth = floor(matrixView.safeAreaLayoutGuide.layoutFrame.width / CGFloat(noOfColumns)) diff --git a/VDS/Components/Tabs/Tabs.swift b/VDS/Components/Tabs/Tabs.swift index e909d43b..ac9e7269 100644 --- a/VDS/Components/Tabs/Tabs.swift +++ b/VDS/Components/Tabs/Tabs.swift @@ -221,10 +221,11 @@ open class Tabs: View { super.layoutSubviews() updateContentView() } - - open override func reset() { - super.reset() - shouldUpdateView = false + + open override func setDefaults() { + super.setDefaults() + onTabDidSelect = nil + onTabShouldSelect = nil orientation = .horizontal borderLine = true fillContainer = false @@ -235,11 +236,9 @@ open class Tabs: View { selectedIndex = 0 size = .medium sticky = false - tabViews.forEach{ $0.reset() } - shouldUpdateView = true - setNeedsUpdate() + tabModels = [] } - + //-------------------------------------------------- // MARK: - Private Methods //-------------------------------------------------- diff --git a/VDS/Components/TextFields/EntryFieldBase.swift b/VDS/Components/TextFields/EntryFieldBase.swift index 481318b6..a3a2918e 100644 --- a/VDS/Components/TextFields/EntryFieldBase.swift +++ b/VDS/Components/TextFields/EntryFieldBase.swift @@ -316,6 +316,41 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { errorLabel.textColorConfiguration = primaryColorConfiguration.eraseToAnyColorable() helperLabel.textColorConfiguration = secondaryColorConfiguration.eraseToAnyColorable() + } + + /// Updates the UI + open override func updateView() { + super.updateView() + updateRules() + updateContainerView() + updateContainerWidth() + updateTitleLabel() + updateErrorLabel() + updateHelperLabel() + } + + open override func setDefaults() { + super.setDefaults() + + titleLabel.textStyle = .bodySmall + errorLabel.textStyle = .bodySmall + helperLabel.textStyle = .bodySmall + + labelText = nil + helperText = nil + showError = false + errorText = nil + tooltipModel = nil + transparentBackground = false + width = nil + inputId = nil + defaultValue = nil + isRequired = false + isReadOnly = false + helperTextPlacement = .bottom + rules = [] + onChange = nil + containerView.bridge_accessibilityLabelBlock = { [weak self] in guard let self else { return "" } var accessibilityLabels = [String]() @@ -350,42 +385,15 @@ open class EntryFieldBase: Control, Changeable, FormFieldInternalValidatable { guard let self else { return "" } return showError || hasInternalError ? "error" : nil } - } - - /// Updates the UI - open override func updateView() { - super.updateView() - updateRules() - updateContainerView() - updateContainerWidth() - updateTitleLabel() - updateErrorLabel() - updateHelperLabel() + } /// Resets to default settings. open override func reset() { - super.reset() titleLabel.reset() errorLabel.reset() helperLabel.reset() - - titleLabel.textStyle = .bodySmall - errorLabel.textStyle = .bodySmall - helperLabel.textStyle = .bodySmall - - labelText = nil - helperText = nil - showError = false - errorText = nil - tooltipModel = nil - transparentBackground = false - width = nil - inputId = nil - defaultValue = nil - isRequired = false - isReadOnly = false - onChange = nil + super.reset() } open override var canBecomeFirstResponder: Bool { diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index a65df78e..92d4c873 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -205,6 +205,22 @@ open class InputField: EntryFieldBase { textField.textColorConfiguration = textFieldTextColorConfiguration + } + + open override func getFieldContainer() -> UIView { + return textField + } + + open override func setDefaults() { + super.setDefaults() + textField.text = "" + + successLabel.textStyle = .bodySmall + + fieldType = .text + showSuccess = false + successText = nil + containerView.bridge_accessibilityLabelBlock = { [weak self] in guard let self else { return "" } var accessibilityLabels = [String]() @@ -259,22 +275,10 @@ open class InputField: EntryFieldBase { } } - open override func getFieldContainer() -> UIView { - return textField - } - /// Resets to default settings. open override func reset() { - super.reset() - textField.text = "" - successLabel.reset() - successLabel.textStyle = .bodySmall - - fieldType = .text - showSuccess = false - successText = nil - helperTextPlacement = .bottom + super.reset() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/TextFields/TextArea/TextArea.swift b/VDS/Components/TextFields/TextArea/TextArea.swift index 07c79ca6..5be37d05 100644 --- a/VDS/Components/TextFields/TextArea/TextArea.swift +++ b/VDS/Components/TextFields/TextArea/TextArea.swift @@ -166,14 +166,19 @@ open class TextArea: EntryFieldBase { bottomContainerStackView.spacing = VDSLayout.space2X } + + open override func setDefaults() { + super.setDefaults() + minHeight = .twoX + maxLength = nil + textView.text = "" + characterCounterLabel.textStyle = .bodySmall + } /// Resets to default settings. open override func reset() { - super.reset() - textView.text = "" characterCounterLabel.reset() - characterCounterLabel.textStyle = .bodySmall - setNeedsUpdate() + super.reset() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index f35d2614..c2ec56ef 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -279,19 +279,18 @@ open class TileContainerBase: Control where Padding return view } - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false + open override func setDefaults() { + super.setDefaults() + backgroundImage = nil color = .white - aspectRatio = .none + backgroundEffect = .none + padding = .defaultValue + aspectRatio = .ratio1x1 imageFallbackColor = .light width = nil height = nil showBorder = false showDropShadow = false - shouldUpdateView = true - setNeedsUpdate() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index 4391bfb3..263d6b77 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -390,20 +390,19 @@ open class Tilelet: TileContainerBase { } } - /// Resets to default settings. - open override func reset() { - shouldUpdateView = false - super.reset() + open override func setDefaults() { + super.setDefaults() aspectRatio = .none color = .black + textWidth = nil + textPostion = .top + //models badgeModel = nil titleModel = nil subTitleModel = nil descriptiveIconModel = nil directionalIconModel = nil - shouldUpdateView = true - setNeedsUpdate() } /// Used to make changes to the View based off a change events or from local properties. diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 47ae5421..25aaf248 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -280,15 +280,12 @@ open class TitleLockup: View { set {} } - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false + open override func setDefaults() { + super.setDefaults() + textAlignment = .left eyebrowModel = nil titleModel = nil subTitleModel = nil - shouldUpdateView = true - setNeedsUpdate() } var labelViews = [UIView]() diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index 6eaf7ef4..effafa07 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -159,18 +159,16 @@ open class Tooltip: Control, TooltipLaunchable { } } - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false - size = .medium - title = "" - content = "" - fillColor = .primary + open override func setDefaults() { + super.setDefaults() closeButtonText = "Close" - shouldUpdateView = true - setNeedsUpdate() + fillColor = .primary + size = .medium + title = nil + content = nil + contentView = nil } + /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index f1f26abc..8b5011ef 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -84,17 +84,13 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { } } - /// Resets to default settings. - open override func reset() { - super.reset() - shouldUpdateView = false + open override func setDefaults() { + super.setDefaults() labelText = nil labelAttributes = nil labelTextStyle = .defaultStyle labelTextAlignment = .left tooltipModel = nil - shouldUpdateView = true - setNeedsUpdate() } }