CXTDT-565117 - Input Field - Overflow not clipped

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-06-04 14:00:32 -05:00
parent 772863ff73
commit 0207b70a20
3 changed files with 53 additions and 3 deletions

View File

@ -101,7 +101,7 @@ open class InputField: EntryFieldBase {
/// UITextField shown in the InputField.
open var textField = TextField().with {
$0.translatesAutoresizingMaskIntoConstraints = false
$0.font = TextStyle.bodyLarge.font
$0.textStyle = TextStyle.bodyLarge
}
/// Color configuration for the textField.

View File

@ -8,6 +8,7 @@
import Foundation
import UIKit
import Combine
import VDSTokens
@objc(VDSTextField)
open class TextField: UITextField, ViewProtocol, Errorable {
@ -46,6 +47,12 @@ open class TextField: UITextField, ViewProtocol, Errorable {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
/// TextStyle used on the titleLabel.
open var textStyle: TextStyle = .defaultStyle { didSet { setNeedsUpdate() } }
/// Will determine if a scaled font should be used for the titleLabel font.
open var useScaledFont: Bool = false { didSet { setNeedsUpdate() } }
/// Key of whether or not updateView() is called in setNeedsUpdate()
open var shouldUpdateView: Bool = true
@ -55,6 +62,22 @@ open class TextField: UITextField, ViewProtocol, Errorable {
open var errorText: String? { didSet { setNeedsUpdate() } }
open var lineBreakMode: NSLineBreakMode = .byClipping { didSet { setNeedsUpdate() } }
open override var isEnabled: Bool { didSet { setNeedsUpdate() } }
open var textColorConfiguration: AnyColorable = ViewColorConfiguration().with {
$0.setSurfaceColors(VDSColor.interactiveDisabledOnlight, VDSColor.interactiveDisabledOndark, forDisabled: true)
$0.setSurfaceColors(VDSColor.elementsPrimaryOnlight, VDSColor.elementsPrimaryOndark, forDisabled: false)
}.eraseToAnyColorable(){ didSet { setNeedsUpdate() }}
open override var textColor: UIColor? {
get { textColorConfiguration.getColor(self) }
set { }
}
override public var text: String! { didSet { setNeedsUpdate() } }
//--------------------------------------------------
// MARK: - Lifecycle
//--------------------------------------------------
@ -63,6 +86,8 @@ open class TextField: UITextField, ViewProtocol, Errorable {
initialSetupPerformed = true
backgroundColor = .clear
translatesAutoresizingMaskIntoConstraints = false
setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
clipsToBounds = true
setup()
setNeedsUpdate()
}
@ -84,10 +109,12 @@ open class TextField: UITextField, ViewProtocol, Errorable {
@objc func doneButtonAction() {
// Resigns the first responder status when 'Done' is tapped
resignFirstResponder()
let _ = resignFirstResponder()
}
open func updateView() {}
open func updateView() {
updateLabel()
}
open func updateAccessibility() {
if let errorText, showError {
@ -139,6 +166,28 @@ open class TextField: UITextField, ViewProtocol, Errorable {
}
return success
}
//--------------------------------------------------
// MARK: - Private Methods
//--------------------------------------------------
private func updateLabel() {
//clear the arrays holding actions
accessibilityCustomActions = []
if let text, !text.isEmpty {
//create the primary string
let mutableText = NSMutableAttributedString.mutableText(for: text,
textStyle: textStyle,
useScaledFont: useScaledFont,
textColor: textColor!,
alignment: .left,
lineBreakMode: lineBreakMode)
attributedText = mutableText
} else {
attributedText = nil
}
}
}
extension UITextField {

View File

@ -2,6 +2,7 @@
----------------
- CXTDT-565087 - Input Field - Text - OnDark colors
- CXTDT-565112 - Input Field - Credit Card icons
- CXTDT-565117 - Input Field - Overflow not clipped
1.0.65
----------------