added comments to Control
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
b0788a85dd
commit
d358194b7d
@ -15,7 +15,11 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
//--------------------------------------------------
|
||||
// MARK: - Combine Properties
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Set of Subscribers for any Publishers for this Control
|
||||
public var subscribers = Set<AnyCancellable>()
|
||||
|
||||
/// Sets the primary Subscriber used for the TouchUpInside
|
||||
public var onClickSubscriber: AnyCancellable? {
|
||||
willSet {
|
||||
if let onClickSubscriber {
|
||||
@ -28,37 +32,46 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
private var initialSetupPerformed = false
|
||||
|
||||
|
||||
/// Key of whether or not updateView() is called in setNeedsUpdate()
|
||||
open var shouldUpdateView: Bool = true
|
||||
|
||||
/// Dictionary for keeping information for this Control use only Primitives
|
||||
open var userInfo = [String: Primitive]()
|
||||
|
||||
|
||||
/// Current Surface used within this Control and used to passdown to child views
|
||||
open var surface: Surface = .light { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// Control is disabled or not
|
||||
open var disabled: Bool = false { didSet { isEnabled = !disabled } }
|
||||
|
||||
|
||||
/// Override for isSelected to handle setNeedsUpdate() on changes
|
||||
open override var isSelected: Bool { didSet { setNeedsUpdate() } }
|
||||
|
||||
/// Reference count use to be used in isHighlighted when a subscriber is listening for TouchUpInside.
|
||||
public var touchUpInsideCount: Int = 0
|
||||
|
||||
var isHighlightAnimating = false
|
||||
|
||||
/// Override to deal with only calling setNeedsUpdate() if needed
|
||||
open override var isHighlighted: Bool {
|
||||
didSet {
|
||||
if isHighlightAnimating == false && touchUpInsideCount > 0 {
|
||||
isHighlightAnimating = true
|
||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||
self?.updateView()
|
||||
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?.updateView()
|
||||
self?.setNeedsUpdate()
|
||||
self?.isHighlightAnimating = false
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Override to deal with setNeedsUpdate()
|
||||
open override var isEnabled: Bool {
|
||||
get { !disabled }
|
||||
set {
|
||||
@ -92,6 +105,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
// MARK: - Setup
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Executed on initialization for this Control
|
||||
open func initialSetup() {
|
||||
if !initialSetupPerformed {
|
||||
initialSetupPerformed = true
|
||||
@ -99,7 +113,9 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
setNeedsUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
///Override to deal with sending actions for accessibility
|
||||
/// - Returns: Based on whether the userInteraction is enabled
|
||||
override open func accessibilityActivate() -> Bool {
|
||||
// Hold state in case User wanted isAnimated to remain off.
|
||||
guard isUserInteractionEnabled else { return false }
|
||||
@ -110,6 +126,8 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
//--------------------------------------------------
|
||||
// MARK: - Overrides
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Update this view based off of property changes
|
||||
open func updateView() {
|
||||
updateAccessibilityLabel()
|
||||
}
|
||||
@ -117,7 +135,8 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
open func updateAccessibilityLabel() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Resets to the Controls default values
|
||||
open func reset() {
|
||||
backgroundColor = .clear
|
||||
surface = .light
|
||||
@ -125,7 +144,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
||||
}
|
||||
|
||||
// MARK: - ViewProtocol
|
||||
/// Will be called only once.
|
||||
/// Will be called only once and should be overridden in subclasses to setup UI or defaults
|
||||
open func setup() {
|
||||
backgroundColor = .clear
|
||||
translatesAutoresizingMaskIntoConstraints = false
|
||||
|
||||
Loading…
Reference in New Issue
Block a user