From 0207b70a20d5ecbffa32bc564dd5cb0c83819ca7 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 4 Jun 2024 14:00:32 -0500 Subject: [PATCH] CXTDT-565117 - Input Field - Overflow not clipped Signed-off-by: Matt Bruce --- .../TextFields/InputField/InputField.swift | 2 +- .../TextFields/InputField/TextField.swift | 53 ++++++++++++++++++- VDS/SupportingFiles/ReleaseNotes.txt | 1 + 3 files changed, 53 insertions(+), 3 deletions(-) diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index c3daeb9a..516954cd 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -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. diff --git a/VDS/Components/TextFields/InputField/TextField.swift b/VDS/Components/TextFields/InputField/TextField.swift index 0488f0b2..b054741d 100644 --- a/VDS/Components/TextFields/InputField/TextField.swift +++ b/VDS/Components/TextFields/InputField/TextField.swift @@ -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 { diff --git a/VDS/SupportingFiles/ReleaseNotes.txt b/VDS/SupportingFiles/ReleaseNotes.txt index 99c924d9..e39df158 100644 --- a/VDS/SupportingFiles/ReleaseNotes.txt +++ b/VDS/SupportingFiles/ReleaseNotes.txt @@ -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 ----------------