made public/open

Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
Matt Bruce 2024-07-12 09:33:21 -05:00
parent 0abc903793
commit fedf1760ec
2 changed files with 47 additions and 22 deletions

View File

@ -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)
}
}
}

View File

@ -9,7 +9,7 @@
import UIKit
import VDS
class TextViewEntryFieldModel: TextEntryFieldModel {
public class TextViewEntryFieldModel: TextEntryFieldModel {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------