From 39107082e7b6e8501d6def6cd2335a72e85a2814 Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Mon, 29 Apr 2024 16:25:55 -0500 Subject: [PATCH] fixed bug with isSecureTextEntry Signed-off-by: Matt Bruce --- .../TextFields/InputField/InputField.swift | 38 +++++++++++++++---- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/VDS/Components/TextFields/InputField/InputField.swift b/VDS/Components/TextFields/InputField/InputField.swift index f43fc951..db722165 100644 --- a/VDS/Components/TextFields/InputField/InputField.swift +++ b/VDS/Components/TextFields/InputField/InputField.swift @@ -63,7 +63,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { } /// UITextField shown in the InputField. - open var textField = UITextField().with { + open var textField = TextField().with { $0.translatesAutoresizingMaskIntoConstraints = false $0.font = TextStyle.bodyLarge.font } @@ -88,6 +88,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { get { textField.text } set { textField.text = newValue + setNeedsUpdate() } } @@ -163,9 +164,9 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { textField .textPublisher .sink { [weak self] newText in + print("textPublisher newText: \(newText)") self?.text = newText self?.sendActions(for: .valueChanged) - if newText.isEmpty { self?.passwordActionType = .show } }.store(in: &subscribers) stackView.addArrangedSubview(successLabel) @@ -251,13 +252,13 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { } open func updateFieldType() { - textField.isSecureTextEntry = false var minWidth: CGFloat = 40.0 var leftIconName: Icon.Name? var actionModel: InputField.TextLinkModel? var toolTipModel: Tooltip.TooltipModel? - + var isSecureTextEntry = false + switch fieldType { case .text: break @@ -271,7 +272,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { case .password: let isHide = passwordActionType == .hide let buttonText = isHide ? hidePasswordButtonText : showPasswordButtonText - let isSecureTextEntry = !isHide + isSecureTextEntry = !isHide let nextPasswordActionType = passwordActionType.toggle() if let text, !text.isEmpty { actionModel = .init(text: buttonText, @@ -279,7 +280,8 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { guard let self else { return } self.passwordActionType = nextPasswordActionType }) - textField.isSecureTextEntry = isSecureTextEntry + } else { + passwordActionType = .show } minWidth = 62.0 @@ -297,6 +299,9 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { } + //textField + textField.isSecureTextEntry = isSecureTextEntry + //leftIcon leftIcon.surface = surface leftIcon.color = iconColorConfiguration.getColor(self) @@ -327,7 +332,7 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { } //tooltip - self.tooltipModel = toolTipModel + tooltipModel = toolTipModel } //-------------------------------------------------- @@ -347,3 +352,22 @@ open class InputField: EntryFieldBase, UITextFieldDelegate { open var showPasswordButtonText: String = "Show" { didSet { setNeedsUpdate() } } } +public class TextField: UITextField { + + open override var isSecureTextEntry: Bool { + didSet { + if isFirstResponder { + _ = becomeFirstResponder() + } + } + } + + public override func becomeFirstResponder() -> Bool { + let success = super.becomeFirstResponder() + if isSecureTextEntry, let text { + self.text?.removeAll() + insertText(text) + } + return success + } +}