diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift index 6d5a45d4..58c3cbc6 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryField.swift @@ -9,7 +9,7 @@ import UIKit import VDS -class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFieldDelegate { +open class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFieldDelegate, ViewMaskingProtocol { //------------------------------------------------------ // MARK: - Properties //------------------------------------------------------ @@ -18,9 +18,9 @@ class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFi open var additionalData: [AnyHashable : Any]? // Form Validation - var fieldKey: String? - var fieldValue: JSONValue? - var groupName: String? + open var fieldKey: String? + open var fieldValue: JSONValue? + open var groupName: String? //-------------------------------------------------- // MARK: - Stored Properties @@ -36,15 +36,12 @@ class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFi //-------------------------------------------------- // MARK: - Computed Properties //-------------------------------------------------- - /// The text of this textView. - open override var text: String? { - didSet { - viewModel?.text = text - } + open var shouldMaskWhileRecording: Bool { + return viewModel.shouldMaskRecordedView ?? false } - + /// Placeholder access for the textView. - public var placeholder: String? { + open var placeholder: String? { get { viewModel?.placeholder } set { textView.placeholder = newValue ?? "" @@ -52,26 +49,34 @@ class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFi } } - override var errorText: String? { + /// The text of this textView. + open override var text: String? { + didSet { + viewModel?.text = text + } + } + + open override var errorText: String? { get { viewModel.dynamicErrorMessage ?? viewModel.errorMessage } set {} } + //-------------------------------------------------- // MARK: - Delegate Properties //-------------------------------------------------- /// The delegate and block for validation. Validates if the text that the user has entered. - public weak var observingTextViewDelegate: ObservingTextFieldDelegate? + open weak var observingTextViewDelegate: ObservingTextFieldDelegate? /// If you're using a ViewController, you must set this to it - public weak var uiTextViewDelegate: UITextViewDelegate? { + open weak var uiTextViewDelegate: UITextViewDelegate? { get { textView.delegate } set { textView.delegate = newValue } } - @objc public func setBothTextDelegates(to delegate: (UITextViewDelegate & ObservingTextFieldDelegate)?) { + @objc open func setBothTextDelegates(to delegate: (UITextViewDelegate & ObservingTextFieldDelegate)?) { observingTextViewDelegate = delegate uiTextViewDelegate = delegate } @@ -79,7 +84,7 @@ class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFi //-------------------------------------------------- // MARK: - Lifecycle //-------------------------------------------------- - override func setup() { + open override func setup() { super.setup() //turn off internal required rule useRequiredRule = false @@ -135,29 +140,33 @@ class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFi uiTextViewDelegate = delegateObject?.uiTextViewDelegate observingTextViewDelegate = delegateObject?.observingTextFieldDelegate - if let accessibilityText = model.accessibilityText { + if let accessibilityText = viewModel.accessibilityText { accessibilityLabel = accessibilityText } - + containerView.accessibilityIdentifier = viewModel.accessibilityIdentifier textView.isEditable = viewModel.editable textView.textAlignment = viewModel.textAlignment - textView.accessibilityIdentifier = model.accessibilityIdentifier textView.placeholder = viewModel.placeholder ?? "" switch viewModel.type { case .secure, .password: textView.isSecureTextEntry = true - + textView.shouldMaskWhileRecording = true + case .numberSecure: textView.isSecureTextEntry = true textView.keyboardType = .numberPad - + textView.shouldMaskWhileRecording = true + case .number: textView.keyboardType = .numberPad case .email: textView.keyboardType = .emailAddress +// case .securityCode, .creditCard: +// textView.shouldMaskWhileRecording = true + default: break } @@ -218,3 +227,19 @@ class TextViewEntryField: VDS.TextArea, VDSMoleculeViewProtocol, ObservingTextFi } } } + +internal struct ViewMasking { + static var shouldMaskWhileRecording: UInt8 = 0 +} + +extension VDS.TextView: ViewMaskingProtocol { + public var shouldMaskWhileRecording: Bool { + get { + return (objc_getAssociatedObject(self, &ViewMasking.shouldMaskWhileRecording) as? Bool) ?? false + } + set { + objc_setAssociatedObject(self, &ViewMasking.shouldMaskWhileRecording, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + } +} + diff --git a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryFieldModel.swift b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryFieldModel.swift index fb1c2167..fc7dc46e 100644 --- a/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryFieldModel.swift +++ b/MVMCoreUI/Atomic/Atoms/FormFields/TextFields/TextViewEntryFieldModel.swift @@ -9,7 +9,7 @@ import UIKit import VDS -class TextViewEntryFieldModel: TextEntryFieldModel { +public class TextViewEntryFieldModel: TextEntryFieldModel { //-------------------------------------------------- // MARK: - Properties //--------------------------------------------------