added to base classes the new accessiblity implmenation
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
4b8d0d985a
commit
a2f7c03b8f
@ -53,6 +53,8 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
|
||||
|
||||
open var surface: Surface = .light { didSet { setNeedsUpdate() } }
|
||||
|
||||
open var accessibilityAction: ((Control) -> Void)?
|
||||
|
||||
/// Whether the Control is selected or not.
|
||||
open override var isSelected: Bool { didSet { setNeedsUpdate() } }
|
||||
|
||||
@ -123,9 +125,14 @@ open class Control: UIControl, ViewProtocol, UserInfoable, Clickable {
|
||||
//--------------------------------------------------
|
||||
/// Implement accessibilityActivate on an element in order to handle the default action.
|
||||
/// - Returns: Based on whether the userInteraction is enabled.
|
||||
override open func accessibilityActivate() -> Bool {
|
||||
open override func accessibilityActivate() -> Bool {
|
||||
// Hold state in case User wanted isAnimated to remain off.
|
||||
guard isUserInteractionEnabled else { return false }
|
||||
guard isEnabled, isUserInteractionEnabled else { return false }
|
||||
|
||||
if let accessibilityAction {
|
||||
accessibilityAction(self)
|
||||
}
|
||||
|
||||
sendActions(for: .touchUpInside)
|
||||
return true
|
||||
}
|
||||
|
||||
@ -55,6 +55,8 @@ open class View: UIView, ViewProtocol, UserInfoable {
|
||||
|
||||
open var isEnabled: Bool = true { didSet { setNeedsUpdate() } }
|
||||
|
||||
open var accessibilityAction: ((View) -> Void)?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Lifecycle
|
||||
//--------------------------------------------------
|
||||
@ -88,6 +90,14 @@ open class View: UIView, ViewProtocol, UserInfoable {
|
||||
isEnabled = true
|
||||
}
|
||||
|
||||
open override func accessibilityActivate() -> Bool {
|
||||
guard isEnabled, isUserInteractionEnabled else { return false }
|
||||
if let accessibilityAction {
|
||||
accessibilityAction(self)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
open override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
setNeedsUpdate()
|
||||
|
||||
@ -78,6 +78,8 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
|
||||
/// Whether the Button should handle the isHighlighted state.
|
||||
open var shouldHighlight: Bool { isHighlighting == false }
|
||||
|
||||
open var accessibilityAction: ((ButtonBase) -> Void)?
|
||||
|
||||
/// Whether the Control is highlighted or not.
|
||||
open override var isHighlighted: Bool {
|
||||
didSet {
|
||||
@ -142,6 +144,15 @@ open class ButtonBase: UIButton, ViewProtocol, UserInfoable, Clickable {
|
||||
setNeedsUpdate()
|
||||
}
|
||||
|
||||
open override func accessibilityActivate() -> Bool {
|
||||
guard isEnabled, isUserInteractionEnabled else { return false }
|
||||
if let accessibilityAction {
|
||||
accessibilityAction(self)
|
||||
}
|
||||
sendActions(for: .touchUpInside)
|
||||
return true
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -132,6 +132,8 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
||||
/// Line break mode for the label, default is set to word wrapping.
|
||||
open override var lineBreakMode: NSLineBreakMode { didSet { setNeedsUpdate() }}
|
||||
|
||||
open var accessibilityAction: ((Label) -> Void)?
|
||||
|
||||
/// Text that will be used in the label.
|
||||
private var _text: String!
|
||||
override open var text: String! {
|
||||
@ -455,7 +457,9 @@ open class Label: UILabel, ViewProtocol, UserInfoable {
|
||||
}
|
||||
|
||||
open override func accessibilityActivate() -> Bool {
|
||||
return false
|
||||
guard let accessibilityAction, isEnabled, isUserInteractionEnabled else { return false }
|
||||
accessibilityAction(self)
|
||||
return true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -77,6 +77,8 @@ open class TextField: UITextField, ViewProtocol, Errorable {
|
||||
|
||||
open var lineBreakMode: NSLineBreakMode = .byClipping { didSet { setNeedsUpdate() } }
|
||||
|
||||
open var accessibilityAction: ((TextField) -> Void)?
|
||||
|
||||
open override var isEnabled: Bool { didSet { setNeedsUpdate() } }
|
||||
|
||||
open var textColorConfiguration: AnyColorable = ViewColorConfiguration().with {
|
||||
@ -211,6 +213,17 @@ open class TextField: UITextField, ViewProtocol, Errorable {
|
||||
return success
|
||||
}
|
||||
|
||||
open override func accessibilityActivate() -> Bool {
|
||||
guard isEnabled, isUserInteractionEnabled else { return false }
|
||||
|
||||
if let accessibilityAction {
|
||||
accessibilityAction(self)
|
||||
return true
|
||||
} else {
|
||||
return super.accessibilityActivate()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -68,6 +68,8 @@ open class TextView: UITextView, ViewProtocol, Errorable {
|
||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
|
||||
}.eraseToAnyColorable(){ didSet { setNeedsUpdate() }}
|
||||
|
||||
open var accessibilityAction: ((TextView) -> Void)?
|
||||
|
||||
open var showError: Bool = false { didSet { setNeedsUpdate() } }
|
||||
|
||||
open var errorText: String? { didSet { setNeedsUpdate() } }
|
||||
@ -147,6 +149,17 @@ open class TextView: UITextView, ViewProtocol, Errorable {
|
||||
setNeedsUpdate()
|
||||
}
|
||||
|
||||
open override func accessibilityActivate() -> Bool {
|
||||
guard isEnabled, isUserInteractionEnabled else { return false }
|
||||
|
||||
if let accessibilityAction {
|
||||
accessibilityAction(self)
|
||||
return true
|
||||
} else {
|
||||
return super.accessibilityActivate()
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Private Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -20,7 +20,7 @@ public protocol ViewProtocol: AnyObject, Initable, Resettable, Enabling, Surface
|
||||
var shouldUpdateAccessibility: Bool { get set }
|
||||
|
||||
/// Used for setting an implementation for the default Accessible Action
|
||||
var accessibilityDefaultAction: ((Self) -> Void)? { get set }
|
||||
var accessibilityAction: ((Self) -> Void)? { get set }
|
||||
|
||||
/// Executed on initialization for this View.
|
||||
func initialSetup()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user