added accessibility
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
3cc00e5260
commit
8cc87fd471
@ -7,9 +7,10 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import Combine
|
||||||
|
|
||||||
@objc(VDSTextField)
|
@objc(VDSTextField)
|
||||||
open class TextField: UITextField {
|
open class TextField: UITextField, ViewProtocol, Errorable {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
@ -29,8 +30,84 @@ open class TextField: UITextField {
|
|||||||
initialSetup()
|
initialSetup()
|
||||||
}
|
}
|
||||||
|
|
||||||
var horizontalPadding: CGFloat = 0
|
//--------------------------------------------------
|
||||||
|
// MARK: - Combine Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
/// Set of Subscribers for any Publishers for this Control.
|
||||||
|
open var subscribers = Set<AnyCancellable>()
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Private Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
private var initialSetupPerformed = false
|
||||||
|
|
||||||
|
private var horizontalPadding: CGFloat = 0
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
/// Key of whether or not updateView() is called in setNeedsUpdate()
|
||||||
|
open var shouldUpdateView: Bool = true
|
||||||
|
|
||||||
|
open var surface: Surface = .light { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
open var showError: Bool = false { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
open var errorText: String? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Lifecycle
|
||||||
|
//--------------------------------------------------
|
||||||
|
open func initialSetup() {
|
||||||
|
if !initialSetupPerformed {
|
||||||
|
initialSetupPerformed = true
|
||||||
|
backgroundColor = .clear
|
||||||
|
translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
setup()
|
||||||
|
setNeedsUpdate()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open func setup() {
|
||||||
|
let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44)))
|
||||||
|
accessView.backgroundColor = .white
|
||||||
|
accessView.addBorder(side: .top, width: 1, color: .lightGray)
|
||||||
|
let done = UIButton(type: .system)
|
||||||
|
done.setTitle("Done", for: .normal)
|
||||||
|
done.translatesAutoresizingMaskIntoConstraints = false
|
||||||
|
done.addTarget(self, action: #selector(doneButtonAction), for: .touchUpInside)
|
||||||
|
accessView.addSubview(done)
|
||||||
|
done.pinCenterY()
|
||||||
|
.pinTrailing(16)
|
||||||
|
inputAccessoryView = accessView
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func doneButtonAction() {
|
||||||
|
// Resigns the first responder status when 'Done' is tapped
|
||||||
|
resignFirstResponder()
|
||||||
|
}
|
||||||
|
|
||||||
|
open func updateView() {}
|
||||||
|
|
||||||
|
open func updateAccessibility() {
|
||||||
|
if let errorText, showError {
|
||||||
|
accessibilityLabel = "error, \(errorText)"
|
||||||
|
} else {
|
||||||
|
accessibilityLabel = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open func reset() {
|
||||||
|
shouldUpdateView = false
|
||||||
|
surface = .light
|
||||||
|
text = nil
|
||||||
|
shouldUpdateView = true
|
||||||
|
setNeedsUpdate()
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Overrides
|
||||||
|
//--------------------------------------------------
|
||||||
open override func textRect(forBounds bounds: CGRect) -> CGRect {
|
open override func textRect(forBounds bounds: CGRect) -> CGRect {
|
||||||
let rect = super.textRect(forBounds: bounds)
|
let rect = super.textRect(forBounds: bounds)
|
||||||
return rect.insetBy(dx: -horizontalPadding, dy: 0)
|
return rect.insetBy(dx: -horizontalPadding, dy: 0)
|
||||||
@ -54,25 +131,6 @@ open class TextField: UITextField {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open func initialSetup() {
|
|
||||||
let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44)))
|
|
||||||
accessView.backgroundColor = .white
|
|
||||||
accessView.addBorder(side: .top, width: 1, color: .lightGray)
|
|
||||||
let done = UIButton(type: .system)
|
|
||||||
done.setTitle("Done", for: .normal)
|
|
||||||
done.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
done.addTarget(self, action: #selector(doneButtonAction), for: .touchUpInside)
|
|
||||||
accessView.addSubview(done)
|
|
||||||
done.pinCenterY()
|
|
||||||
.pinTrailing(16)
|
|
||||||
inputAccessoryView = accessView
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc func doneButtonAction() {
|
|
||||||
// Resigns the first responder status when 'Done' is tapped
|
|
||||||
resignFirstResponder()
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func becomeFirstResponder() -> Bool {
|
open override func becomeFirstResponder() -> Bool {
|
||||||
let success = super.becomeFirstResponder()
|
let success = super.becomeFirstResponder()
|
||||||
if isSecureTextEntry, let text {
|
if isSecureTextEntry, let text {
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import Combine
|
|||||||
import VDSTokens
|
import VDSTokens
|
||||||
|
|
||||||
@objc(VDSTextView)
|
@objc(VDSTextView)
|
||||||
open class TextView: UITextView, ViewProtocol {
|
open class TextView: UITextView, ViewProtocol, Errorable {
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Initializers
|
// MARK: - Initializers
|
||||||
@ -66,6 +66,10 @@ open class TextView: UITextView, ViewProtocol {
|
|||||||
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
|
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
|
||||||
}.eraseToAnyColorable(){ didSet { setNeedsUpdate() }}
|
}.eraseToAnyColorable(){ didSet { setNeedsUpdate() }}
|
||||||
|
|
||||||
|
open var showError: Bool = false { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
|
open var errorText: String? { didSet { setNeedsUpdate() } }
|
||||||
|
|
||||||
open override var textColor: UIColor? {
|
open override var textColor: UIColor? {
|
||||||
get { textColorConfiguration.getColor(self) }
|
get { textColorConfiguration.getColor(self) }
|
||||||
set { }
|
set { }
|
||||||
@ -102,7 +106,6 @@ open class TextView: UITextView, ViewProtocol {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
open func setup() {
|
open func setup() {
|
||||||
let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44)))
|
let accessView = UIView(frame: .init(origin: .zero, size: .init(width: UIScreen.main.bounds.width, height: 44)))
|
||||||
accessView.backgroundColor = .white
|
accessView.backgroundColor = .white
|
||||||
@ -126,7 +129,13 @@ open class TextView: UITextView, ViewProtocol {
|
|||||||
updateLabel()
|
updateLabel()
|
||||||
}
|
}
|
||||||
|
|
||||||
open func updateAccessibility() {}
|
open func updateAccessibility() {
|
||||||
|
if let errorText, showError {
|
||||||
|
accessibilityLabel = "error, \(errorText)"
|
||||||
|
} else {
|
||||||
|
accessibilityLabel = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
open func reset() {
|
open func reset() {
|
||||||
shouldUpdateView = false
|
shouldUpdateView = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user