From bd902434ef483ef2f89e2a059bfc51fc89a18742 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 8 May 2023 14:40:11 -0500 Subject: [PATCH] refactored reset methods Signed-off-by: Matt Bruce --- VDS/Components/Badge/Badge.swift | 6 ++++-- VDS/Components/Buttons/Button/Button.swift | 3 +++ .../Buttons/Button/ButtonBase.swift | 5 ++++- .../Buttons/TextLink/TextLink.swift | 4 ++++ .../Buttons/TextLinkCaret/TextLinkCaret.swift | 1 + VDS/Components/Checkbox/Checkbox.swift | 4 +++- VDS/Components/Label/Label.swift | 5 ++++- .../Notification/Notification.swift | 5 +++++ VDS/Components/RadioBox/RadioBox.swift | 4 +++- VDS/Components/RadioButton/RadioButton.swift | 5 ++++- VDS/Components/RadioSwatch/RadioSwatch.swift | 5 +++-- .../TileContainer/TileContainer.swift | 12 +++++++++++- VDS/Components/Tilelet/Tilelet.swift | 6 ++++-- VDS/Components/TitleLockup/TitleLockup.swift | 19 ++++++++++--------- VDS/Components/Toggle/Toggle.swift | 5 +++-- VDS/Components/Tooltip/Tooltip.swift | 3 +++ .../Tooltip/TrailingTooltipLabel.swift | 15 ++++++++++++++- 17 files changed, 83 insertions(+), 24 deletions(-) diff --git a/VDS/Components/Badge/Badge.swift b/VDS/Components/Badge/Badge.swift index 77f8d9ca..c7fed36f 100644 --- a/VDS/Components/Badge/Badge.swift +++ b/VDS/Components/Badge/Badge.swift @@ -66,16 +66,18 @@ open class Badge: View { } open override func reset() { - super.reset() + super.reset() + shouldUpdateView = false label.reset() label.lineBreakMode = .byTruncatingTail label.textPosition = .left label.textStyle = .boldBodySmall - fillColor = .red text = "" maxWidth = nil numberOfLines = 1 + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/Button/Button.swift b/VDS/Components/Buttons/Button/Button.swift index 70d70ab6..3ac084fa 100644 --- a/VDS/Components/Buttons/Button/Button.swift +++ b/VDS/Components/Buttons/Button/Button.swift @@ -132,9 +132,12 @@ open class Button: ButtonBase, Useable { open override func reset() { super.reset() + shouldUpdateView = false use = .primary width = nil size = .large + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/Button/ButtonBase.swift b/VDS/Components/Buttons/Button/ButtonBase.swift index 39c9f11a..1e403570 100644 --- a/VDS/Components/Buttons/Button/ButtonBase.swift +++ b/VDS/Components/Buttons/Button/ButtonBase.swift @@ -45,7 +45,7 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab //-------------------------------------------------- // MARK: - Properties //-------------------------------------------------- - open var shouldUpdateView: Bool = true + open var shouldUpdateView: Bool = true open var availableSizes: [ButtonSize] { [] } @@ -136,10 +136,13 @@ open class ButtonBase: UIButton, Buttonable, Handlerable, ViewProtocol, Resettab } open func reset() { + shouldUpdateView = false surface = .light disabled = false text = nil accessibilityCustomActions = [] + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/Components/Buttons/TextLink/TextLink.swift b/VDS/Components/Buttons/TextLink/TextLink.swift index 6799126f..f90f160f 100644 --- a/VDS/Components/Buttons/TextLink/TextLink.swift +++ b/VDS/Components/Buttons/TextLink/TextLink.swift @@ -88,10 +88,14 @@ open class TextLink: ButtonBase { 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 58e8f9b1..52864cf6 100644 --- a/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift +++ b/VDS/Components/Buttons/TextLinkCaret/TextLinkCaret.swift @@ -100,6 +100,7 @@ open class TextLinkCaret: ButtonBase { open override func reset() { super.reset() iconPosition = .right + text = nil } //-------------------------------------------------- diff --git a/VDS/Components/Checkbox/Checkbox.swift b/VDS/Components/Checkbox/Checkbox.swift index ec083053..b3430948 100644 --- a/VDS/Components/Checkbox/Checkbox.swift +++ b/VDS/Components/Checkbox/Checkbox.swift @@ -252,6 +252,7 @@ open class Checkbox: Control, Errorable, Changeable { open override func reset() { super.reset() + shouldUpdateView = false label.reset() childLabel.reset() errorLabel.reset() @@ -272,7 +273,8 @@ open class Checkbox: Control, Errorable, Changeable { value = nil isSelected = false - updateSelector() + shouldUpdateView = true + setNeedsUpdate() } /// This will checkbox the state of the Selector and execute the actionBlock if provided. diff --git a/VDS/Components/Label/Label.swift b/VDS/Components/Label/Label.swift index 3a554a63..2bab6ec6 100644 --- a/VDS/Components/Label/Label.swift +++ b/VDS/Components/Label/Label.swift @@ -23,7 +23,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { //-------------------------------------------------- private var initialSetupPerformed = false - open var shouldUpdateView: Bool = true + open var shouldUpdateView: Bool = true open var useAttributedText: Bool = false @@ -102,6 +102,7 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { open func setup() {} open func reset() { + shouldUpdateView = false surface = .light disabled = false attributes = nil @@ -111,6 +112,8 @@ open class Label: UILabel, Handlerable, ViewProtocol, Resettable, UserInfoable { attributedText = nil numberOfLines = 0 backgroundColor = .clear + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/Components/Notification/Notification.swift b/VDS/Components/Notification/Notification.swift index 734e0aad..eacb55d1 100644 --- a/VDS/Components/Notification/Notification.swift +++ b/VDS/Components/Notification/Notification.swift @@ -231,6 +231,8 @@ open class Notification: View { open override func reset() { super.reset() + shouldUpdateView = false + titleLabel.reset() titleLabel.text = "" titleLabel.textStyle = UIDevice.isIPad ? .boldBodyLarge : .boldBodySmall @@ -255,6 +257,9 @@ open class Notification: View { layout = .vertical hideCloseButton = false fullBleed = false + + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/Components/RadioBox/RadioBox.swift b/VDS/Components/RadioBox/RadioBox.swift index 71083a48..f27a8809 100644 --- a/VDS/Components/RadioBox/RadioBox.swift +++ b/VDS/Components/RadioBox/RadioBox.swift @@ -204,6 +204,7 @@ open class RadioBox: Control, Changeable { open override func reset() { super.reset() + shouldUpdateView = false textLabel.reset() subTextLabel.reset() subTextRightLabel.reset() @@ -227,7 +228,8 @@ open class RadioBox: Control, Changeable { isSelected = false - updateSelector() + shouldUpdateView = true + setNeedsUpdate() } /// This will radioBox the state of the Selector and execute the actionBlock if provided. diff --git a/VDS/Components/RadioButton/RadioButton.swift b/VDS/Components/RadioButton/RadioButton.swift index 03d58855..705af90e 100644 --- a/VDS/Components/RadioButton/RadioButton.swift +++ b/VDS/Components/RadioButton/RadioButton.swift @@ -240,6 +240,7 @@ open class RadioButton: Control, Errorable, Changeable { open override func reset() { super.reset() + shouldUpdateView = false label.reset() childLabel.reset() errorLabel.reset() @@ -261,7 +262,9 @@ open class RadioButton: Control, Errorable, Changeable { isSelected = false - updateSelector() + shouldUpdateView = true + setNeedsUpdate() + } /// This will checkbox the state of the Selector and execute the actionBlock if provided. diff --git a/VDS/Components/RadioSwatch/RadioSwatch.swift b/VDS/Components/RadioSwatch/RadioSwatch.swift index 2c556353..8178f971 100644 --- a/VDS/Components/RadioSwatch/RadioSwatch.swift +++ b/VDS/Components/RadioSwatch/RadioSwatch.swift @@ -91,7 +91,7 @@ open class RadioSwatch: Control { open override func reset() { super.reset() - + shouldUpdateView = false fillImage = nil text = "" primaryColor = nil @@ -99,7 +99,8 @@ open class RadioSwatch: Control { strikethrough = false inputId = nil value = nil - + shouldUpdateView = true + setNeedsUpdate() setNeedsDisplay() } diff --git a/VDS/Components/TileContainer/TileContainer.swift b/VDS/Components/TileContainer/TileContainer.swift index 97b48967..f5d284a1 100644 --- a/VDS/Components/TileContainer/TileContainer.swift +++ b/VDS/Components/TileContainer/TileContainer.swift @@ -191,7 +191,17 @@ open class TileContainer: Control { open override func reset() { super.reset() - + shouldUpdateView = false + color = .white + padding = .padding4X + aspectRatio = .ratio1x1 + imageFallbackColor = .light + width = nil + height = nil + showBorder = false + showDropShadows = false + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/Components/Tilelet/Tilelet.swift b/VDS/Components/Tilelet/Tilelet.swift index 70f2a06e..99bc633b 100644 --- a/VDS/Components/Tilelet/Tilelet.swift +++ b/VDS/Components/Tilelet/Tilelet.swift @@ -256,15 +256,17 @@ open class Tilelet: TileContainer { } open override func reset() { + shouldUpdateView = false aspectRatio = .none color = .black - //models badgeModel = nil titleModel = nil subTitleModel = nil descriptiveIconModel = nil - directionalIconModel = nil + directionalIconModel = nil + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- diff --git a/VDS/Components/TitleLockup/TitleLockup.swift b/VDS/Components/TitleLockup/TitleLockup.swift index 7461938e..b64132f4 100644 --- a/VDS/Components/TitleLockup/TitleLockup.swift +++ b/VDS/Components/TitleLockup/TitleLockup.swift @@ -176,7 +176,11 @@ open class TitleLockup: View { open var textPosition: TextPosition = .left { didSet { setNeedsUpdate() }} //style - open var otherTextStyle: OtherTextStyle = UIDevice.isIPad ? .bodyLarge : .bodyMedium { didSet { setNeedsUpdate() }} + open var otherTextStyle: OtherTextStyle = UIDevice.isIPad ? .bodyLarge : .bodyMedium { + didSet { + setNeedsUpdate() + } + } //first row open var eyebrowLabel = Label().with { @@ -218,17 +222,14 @@ open class TitleLockup: View { open override func reset() { super.reset() - titleLabel.reset() - eyebrowLabel.reset() - subTitleLabel.reset() - + shouldUpdateView = false textPosition = .left - eyebrowModel = nil titleModel = nil subTitleModel = nil - otherTextStyle = .bodyLarge - + otherTextStyle = UIDevice.isIPad ? .bodyLarge : .bodyMedium + shouldUpdateView = true + setNeedsUpdate() } //-------------------------------------------------- @@ -241,7 +242,7 @@ open class TitleLockup: View { var eyebrowTextIsEmpty = true var titleTextIsEmpty = true var subTitleTextIsEmpty = true - + if let eyebrowModel, !eyebrowModel.text.isEmpty { eyebrowTextIsEmpty = false eyebrowLabel.textPosition = allLabelsTextPosition diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index 4b3e8038..634fc192 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -272,9 +272,9 @@ open class Toggle: Control, Changeable { open override func reset() { super.reset() + shouldUpdateView = false label.reset() isOn = false - isAnimated = true showText = false onText = "On" @@ -284,9 +284,10 @@ open class Toggle: Control, Changeable { textPosition = .left inputId = nil value = nil - toggleView.backgroundColor = toggleColorConfiguration.getColor(self) knobView.backgroundColor = knobColorConfiguration.getColor(self) + shouldUpdateView = true + setNeedsUpdate() } /// This will toggle the state of the Toggle and execute the actionBlock if provided. diff --git a/VDS/Components/Tooltip/Tooltip.swift b/VDS/Components/Tooltip/Tooltip.swift index 7c4cf235..2ebb5247 100644 --- a/VDS/Components/Tooltip/Tooltip.swift +++ b/VDS/Components/Tooltip/Tooltip.swift @@ -138,12 +138,15 @@ open class Tooltip: Control, TooltipLaunchable { open override func reset() { super.reset() + shouldUpdateView = false size = .medium title = "" content = "" fillColor = .primary closeButtonText = "Close" imageView.image = nil + shouldUpdateView = true + setNeedsUpdate() } open override func updateView() { diff --git a/VDS/Components/Tooltip/TrailingTooltipLabel.swift b/VDS/Components/Tooltip/TrailingTooltipLabel.swift index 76555039..9c7fc628 100644 --- a/VDS/Components/Tooltip/TrailingTooltipLabel.swift +++ b/VDS/Components/Tooltip/TrailingTooltipLabel.swift @@ -40,7 +40,6 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { open var tooltipContent: String = "" { didSet { setNeedsUpdate() } } - open var tooltipYOffset: CGFloat = 0 { didSet { setNeedsUpdate() } } //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- @@ -75,6 +74,20 @@ open class TrailingTooltipLabel: View, TooltipLaunchable { label.addTooltip(model: .init(surface: surface, closeButtonText: tooltipCloseButtonText, title: tooltipTitle, content: tooltipContent)) } } + + open override func reset() { + super.reset() + shouldUpdateView = false + labelText = nil + labelAttributes = nil + labelTextStyle = .defaultStyle + labelTextPosition = .left + tooltipCloseButtonText = "Close" + tooltipTitle = "" + tooltipContent = "" + shouldUpdateView = true + setNeedsUpdate() + } }