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()