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:
parent
308e8c9738
commit
143d1bf717
@ -60,25 +60,21 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
|
|||||||
/// Whether the Control is selected or not.
|
/// Whether the Control is selected or not.
|
||||||
open override var isSelected: Bool { didSet { setNeedsUpdate() } }
|
open override var isSelected: Bool { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
/// Whether the Control can handle the isHighlighted state.
|
/// State of animating isHighlight.
|
||||||
open var canHighlight: Bool = true
|
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.
|
/// Whether the Control is highlighted or not.
|
||||||
open override var isHighlighted: Bool {
|
open override var isHighlighted: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
if canHighlight && isHighlightAnimating == false && onClickSubscriber != nil {
|
if shouldHighlight {
|
||||||
isHighlightAnimating = true
|
isHighlighting = true
|
||||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||||
self?.setNeedsUpdate()
|
self?.setNeedsUpdate()
|
||||||
}) { [weak self] _ in
|
self?.isHighlighting = false
|
||||||
//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
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,6 +86,8 @@ extension Tabs {
|
|||||||
///Minimum width for the tab
|
///Minimum width for the tab
|
||||||
open var minWidth: CGFloat = 44.0 { didSet { setNeedsUpdate() } }
|
open var minWidth: CGFloat = 44.0 { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
open override var shouldHighlight: Bool { false }
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Configuration
|
// 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.
|
/// Called once when a view is initialized and is used to Setup additional UI or other constants and configurations.
|
||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
canHighlight = false
|
|
||||||
|
|
||||||
addLayoutGuide(layoutGuide)
|
addLayoutGuide(layoutGuide)
|
||||||
addSubview(label)
|
addSubview(label)
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
|
|||||||
@ -165,6 +165,8 @@ open class Toggle: Control, Changeable, FormFieldable {
|
|||||||
return toggleContainerSize
|
return toggleContainerSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open override var shouldHighlight: Bool { false }
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
@ -181,7 +183,6 @@ open class Toggle: Control, Changeable, FormFieldable {
|
|||||||
open override func setup() {
|
open override func setup() {
|
||||||
super.setup()
|
super.setup()
|
||||||
|
|
||||||
canHighlight = false
|
|
||||||
isAccessibilityElement = true
|
isAccessibilityElement = true
|
||||||
accessibilityTraits = .button
|
accessibilityTraits = .button
|
||||||
addSubview(label)
|
addSubview(label)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user