From 143d1bf7178a0645a7162b5432077b9173241140 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Thu, 14 Sep 2023 16:43:55 -0500 Subject: [PATCH] refactored out canHighlight and added shouldHighlight to be able to override Signed-off-by: Matt Bruce --- VDS/BaseClasses/Control.swift | 20 ++++++++------------ VDS/Components/Tabs/Tab.swift | 6 +++--- VDS/Components/Toggle/Toggle.swift | 3 ++- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/VDS/BaseClasses/Control.swift b/VDS/BaseClasses/Control.swift index e9535f1a..a8b62ed1 100644 --- a/VDS/BaseClasses/Control.swift +++ b/VDS/BaseClasses/Control.swift @@ -60,25 +60,21 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable { /// Whether the Control is selected or not. open override var isSelected: Bool { didSet { setNeedsUpdate() } } - /// Whether the Control can handle the isHighlighted state. - open var canHighlight: Bool = true + /// State of animating isHighlight. + public var isHighlighting = false - var isHighlightAnimating = false + /// Whether the Control should handle the isHighlighted state. + open var shouldHighlight: Bool { isHighlighting == false && onClickSubscriber != nil } /// Whether the Control is highlighted or not. open override var isHighlighted: Bool { didSet { - if canHighlight && isHighlightAnimating == false && onClickSubscriber != nil { - isHighlightAnimating = true + if shouldHighlight { + isHighlighting = true UIView.animate(withDuration: 0.1, animations: { [weak self] in self?.setNeedsUpdate() - }) { [weak self] _ in - //you update the view since this is typically a quick change - UIView.animate(withDuration: 0.1, animations: { [weak self] in - self?.setNeedsUpdate() - self?.isHighlightAnimating = false - }) - } + self?.isHighlighting = false + }) } } } diff --git a/VDS/Components/Tabs/Tab.swift b/VDS/Components/Tabs/Tab.swift index 0c061224..9164e29f 100644 --- a/VDS/Components/Tabs/Tab.swift +++ b/VDS/Components/Tabs/Tab.swift @@ -86,6 +86,8 @@ extension Tabs { ///Minimum width for the tab open var minWidth: CGFloat = 44.0 { didSet { setNeedsUpdate() } } + open override var shouldHighlight: Bool { false } + //-------------------------------------------------- // MARK: - Configuration //-------------------------------------------------- @@ -128,9 +130,7 @@ extension Tabs { /// 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() - - canHighlight = false - + addLayoutGuide(layoutGuide) addSubview(label) accessibilityTraits = .button diff --git a/VDS/Components/Toggle/Toggle.swift b/VDS/Components/Toggle/Toggle.swift index a13cfdb9..d4ac06a0 100644 --- a/VDS/Components/Toggle/Toggle.swift +++ b/VDS/Components/Toggle/Toggle.swift @@ -165,6 +165,8 @@ open class Toggle: Control, Changeable, FormFieldable { return toggleContainerSize } } + + open override var shouldHighlight: Bool { false } //-------------------------------------------------- // MARK: - Overrides @@ -181,7 +183,6 @@ open class Toggle: Control, Changeable, FormFieldable { open override func setup() { super.setup() - canHighlight = false isAccessibilityElement = true accessibilityTraits = .button addSubview(label)