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
|
// MARK: - Combine Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
/// Set of Subscribers for any Publishers for this Control
|
||||||
public var subscribers = Set<AnyCancellable>()
|
public var subscribers = Set<AnyCancellable>()
|
||||||
|
|
||||||
|
/// Sets the primary Subscriber used for the TouchUpInside
|
||||||
public var onClickSubscriber: AnyCancellable? {
|
public var onClickSubscriber: AnyCancellable? {
|
||||||
willSet {
|
willSet {
|
||||||
if let onClickSubscriber {
|
if let onClickSubscriber {
|
||||||
@ -29,29 +33,37 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
private var initialSetupPerformed = false
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
|
/// Key of whether or not updateView() is called in setNeedsUpdate()
|
||||||
open var shouldUpdateView: Bool = true
|
open var shouldUpdateView: Bool = true
|
||||||
|
|
||||||
|
/// Dictionary for keeping information for this Control use only Primitives
|
||||||
open var userInfo = [String: Primitive]()
|
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() } }
|
open var surface: Surface = .light { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
/// Control is disabled or not
|
||||||
open var disabled: Bool = false { didSet { isEnabled = !disabled } }
|
open var disabled: Bool = false { didSet { isEnabled = !disabled } }
|
||||||
|
|
||||||
|
/// Override for isSelected to handle setNeedsUpdate() on changes
|
||||||
open override var isSelected: Bool { didSet { setNeedsUpdate() } }
|
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
|
public var touchUpInsideCount: Int = 0
|
||||||
|
|
||||||
var isHighlightAnimating = false
|
var isHighlightAnimating = false
|
||||||
|
|
||||||
|
/// Override to deal with only calling setNeedsUpdate() if needed
|
||||||
open override var isHighlighted: Bool {
|
open override var isHighlighted: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
if isHighlightAnimating == false && touchUpInsideCount > 0 {
|
if isHighlightAnimating == false && touchUpInsideCount > 0 {
|
||||||
isHighlightAnimating = true
|
isHighlightAnimating = true
|
||||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||||
self?.updateView()
|
self?.setNeedsUpdate()
|
||||||
}) { [weak self] _ in
|
}) { [weak self] _ in
|
||||||
//you update the view since this is typically a quick change
|
//you update the view since this is typically a quick change
|
||||||
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
UIView.animate(withDuration: 0.1, animations: { [weak self] in
|
||||||
self?.updateView()
|
self?.setNeedsUpdate()
|
||||||
self?.isHighlightAnimating = false
|
self?.isHighlightAnimating = false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -59,6 +71,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Override to deal with setNeedsUpdate()
|
||||||
open override var isEnabled: Bool {
|
open override var isEnabled: Bool {
|
||||||
get { !disabled }
|
get { !disabled }
|
||||||
set {
|
set {
|
||||||
@ -92,6 +105,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
// MARK: - Setup
|
// MARK: - Setup
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
/// Executed on initialization for this Control
|
||||||
open func initialSetup() {
|
open func initialSetup() {
|
||||||
if !initialSetupPerformed {
|
if !initialSetupPerformed {
|
||||||
initialSetupPerformed = true
|
initialSetupPerformed = true
|
||||||
@ -100,6 +114,8 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///Override to deal with sending actions for accessibility
|
||||||
|
/// - Returns: Based on whether the userInteraction is enabled
|
||||||
override open func accessibilityActivate() -> Bool {
|
override open func accessibilityActivate() -> Bool {
|
||||||
// Hold state in case User wanted isAnimated to remain off.
|
// Hold state in case User wanted isAnimated to remain off.
|
||||||
guard isUserInteractionEnabled else { return false }
|
guard isUserInteractionEnabled else { return false }
|
||||||
@ -110,6 +126,8 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Overrides
|
// MARK: - Overrides
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
|
/// Update this view based off of property changes
|
||||||
open func updateView() {
|
open func updateView() {
|
||||||
updateAccessibilityLabel()
|
updateAccessibilityLabel()
|
||||||
}
|
}
|
||||||
@ -118,6 +136,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Resets to the Controls default values
|
||||||
open func reset() {
|
open func reset() {
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
surface = .light
|
surface = .light
|
||||||
@ -125,7 +144,7 @@ open class Control: UIControl, Handlerable, ViewProtocol, Resettable, UserInfoab
|
|||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - ViewProtocol
|
// 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() {
|
open func setup() {
|
||||||
backgroundColor = .clear
|
backgroundColor = .clear
|
||||||
translatesAutoresizingMaskIntoConstraints = false
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user