refactored out canHighlight and added shouldHighlight to be able to override

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2023-09-14 16:43:55 -05:00
parent 308e8c9738
commit 143d1bf717
3 changed files with 13 additions and 16 deletions

View File

@ -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
})
}
}
}

View File

@ -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
//--------------------------------------------------
@ -129,8 +131,6 @@ extension Tabs {
open override func setup() {
super.setup()
canHighlight = false
addLayoutGuide(layoutGuide)
addSubview(label)
accessibilityTraits = .button

View File

@ -166,6 +166,8 @@ open class Toggle: Control, Changeable, FormFieldable {
}
}
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)