borders gone, observe validation
This commit is contained in:
parent
7f4360de3d
commit
f1466763b7
@ -246,6 +246,7 @@ import UIKit
|
||||
titleLabel.textColor = .mvmBlack
|
||||
feedbackLabel.font = Styler.Font.RegularMicro.getFont()
|
||||
feedbackLabel.textColor = .mvmBlack
|
||||
entryFieldContainer.disableAllBorders = false
|
||||
feedbackLabel.text = nil
|
||||
entryFieldContainer.reset()
|
||||
}
|
||||
@ -261,6 +262,7 @@ import UIKit
|
||||
title = model.title
|
||||
feedback = model.feedback
|
||||
isEnabled = model.enabled
|
||||
entryFieldContainer.disableAllBorders = model.hideBorders
|
||||
|
||||
if let isLocked = model.locked {
|
||||
self.isLocked = isLocked
|
||||
|
||||
@ -25,6 +25,7 @@ import Foundation
|
||||
public var errorTextColor: Color?
|
||||
public var enabled: Bool = true
|
||||
public var showError: Bool?
|
||||
public var hideBorders = false
|
||||
public var locked: Bool?
|
||||
public var selected: Bool?
|
||||
public var text: String?
|
||||
@ -55,6 +56,7 @@ import Foundation
|
||||
case locked
|
||||
case selected
|
||||
case showError
|
||||
case hideBorders
|
||||
case text
|
||||
case fieldKey
|
||||
case groupName
|
||||
@ -96,6 +98,7 @@ import Foundation
|
||||
locked = try typeContainer.decodeIfPresent(Bool.self, forKey: .locked)
|
||||
selected = try typeContainer.decodeIfPresent(Bool.self, forKey: .selected)
|
||||
text = try typeContainer.decodeIfPresent(String.self, forKey: .text)
|
||||
hideBorders = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideBorders) ?? false
|
||||
baseValue = text
|
||||
fieldKey = try typeContainer.decodeIfPresent(String.self, forKey: .fieldKey)
|
||||
|
||||
@ -117,6 +120,7 @@ import Foundation
|
||||
try container.encodeIfPresent(errorTextColor, forKey: .errorTextColor)
|
||||
try container.encodeIfPresent(errorMessage, forKey: .errorMessage)
|
||||
try container.encode(enabled, forKey: .enabled)
|
||||
try container.encode(hideBorders, forKey: .hideBorders)
|
||||
try container.encodeIfPresent(fieldKey, forKey: .fieldKey)
|
||||
try container.encodeIfPresent(groupName, forKey: .groupName)
|
||||
}
|
||||
|
||||
@ -104,15 +104,15 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
||||
didSet {
|
||||
if observingTextFieldDelegate != nil && !observingForChange {
|
||||
observingForChange = true
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(valueChanged), name: UITextView.textDidChangeNotification, object: textView)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(endInputing), name: UITextView.textDidEndEditingNotification, object: textView)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextView.textDidBeginEditingNotification, object: textView)
|
||||
// NotificationCenter.default.addObserver(self, selector: #selector(valueChanged), name: UITextView.textDidChangeNotification, object: textView)
|
||||
// NotificationCenter.default.addObserver(self, selector: #selector(endInputing), name: UITextView.textDidEndEditingNotification, object: textView)
|
||||
// NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextView.textDidBeginEditingNotification, object: textView)
|
||||
|
||||
} else if observingTextFieldDelegate == nil && observingForChange {
|
||||
observingForChange = false
|
||||
NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: textView)
|
||||
NotificationCenter.default.removeObserver(self, name: UITextView.textDidEndEditingNotification, object: textView)
|
||||
NotificationCenter.default.removeObserver(self, name: UITextView.textDidBeginEditingNotification, object: textView)
|
||||
// NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, object: textView)
|
||||
// NotificationCenter.default.removeObserver(self, name: UITextView.textDidEndEditingNotification, object: textView)
|
||||
// NotificationCenter.default.removeObserver(self, name: UITextView.textDidBeginEditingNotification, object: textView)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -153,10 +153,9 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
||||
])
|
||||
|
||||
heightConstraint = textView.heightAnchor.constraint(equalToConstant: 0)
|
||||
heightConstraint?.isActive = true
|
||||
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(startEditing))
|
||||
entryFieldContainer.addGestureRecognizer(tap)
|
||||
// let tap = UITapGestureRecognizer(target: self, action: #selector(startEditing))
|
||||
// entryFieldContainer.addGestureRecognizer(tap)
|
||||
|
||||
accessibilityElements = [titleLabel, textView, feedbackLabel]
|
||||
}
|
||||
@ -173,42 +172,43 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
||||
|
||||
textView.font = Styler.Font.RegularBodyLarge.getFont()
|
||||
heightConstraint?.constant = 0
|
||||
heightConstraint?.isActive = false
|
||||
}
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Methods
|
||||
//--------------------------------------------------
|
||||
|
||||
/// Executes on UITextField.textDidBeginEditingNotification
|
||||
@objc func startEditing() {
|
||||
textView.becomeFirstResponder()
|
||||
}
|
||||
|
||||
/// Executes on UITextField.textDidChangeNotification (each character entry)
|
||||
@objc func valueChanged() {
|
||||
guard validateEachCharacter else { return }
|
||||
isSelected = true
|
||||
validateTextField()
|
||||
}
|
||||
|
||||
/// Validates the text of the entry field.
|
||||
//
|
||||
// /// Executes on UITextField.textDidBeginEditingNotification
|
||||
// @objc func startEditing() {
|
||||
// textView.becomeFirstResponder()
|
||||
// }
|
||||
//
|
||||
// /// Executes on UITextField.textDidChangeNotification (each character entry)
|
||||
// @objc func valueChanged() {
|
||||
// guard validateEachCharacter else { return }
|
||||
// isSelected = true
|
||||
// validateTextField()
|
||||
// }
|
||||
//
|
||||
// /// Validates the text of the entry field.
|
||||
@objc public func validateTextField() {
|
||||
text = textView.text
|
||||
_ = FormValidator.validate(delegate: delegateObject?.formHolderDelegate)
|
||||
}
|
||||
|
||||
/// Executes on UITextField.textDidEndEditingNotification
|
||||
@objc func endInputing() {
|
||||
resignFirstResponder()
|
||||
if isValid {
|
||||
showError = false
|
||||
entryFieldContainer.bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor
|
||||
}
|
||||
}
|
||||
|
||||
@objc public func dismissFieldInput(_ sender: Any?) {
|
||||
resignFirstResponder()
|
||||
}
|
||||
//
|
||||
// /// Executes on UITextField.textDidEndEditingNotification
|
||||
// @objc func endInputing() {
|
||||
// resignFirstResponder()
|
||||
// if isValid {
|
||||
// showError = false
|
||||
// entryFieldContainer.bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @objc public func dismissFieldInput(_ sender: Any?) {
|
||||
// resignFirstResponder()
|
||||
// }
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - UITextViewDelegate
|
||||
@ -233,6 +233,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
||||
|
||||
@objc public func textViewDidChange(_ textView: UITextView) {
|
||||
|
||||
validateTextField()
|
||||
proprietorTextDelegate?.textViewDidChange?(textView)
|
||||
}
|
||||
|
||||
@ -245,6 +246,10 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
||||
|
||||
self.textView.setPlaceholderIfAvailable()
|
||||
isSelected = false
|
||||
if isValid {
|
||||
showError = false
|
||||
entryFieldContainer.bottomBar?.backgroundColor = UIColor.mvmBlack.cgColor
|
||||
}
|
||||
proprietorTextDelegate?.textViewDidEndEditing?(textView)
|
||||
}
|
||||
|
||||
@ -257,7 +262,11 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
||||
|
||||
guard let model = model as? TextViewEntryFieldModel else { return }
|
||||
|
||||
heightConstraint?.constant = model.height ?? 0
|
||||
if let height = model.height {
|
||||
heightConstraint?.constant = height
|
||||
heightConstraint?.isActive = true
|
||||
}
|
||||
|
||||
text = model.text
|
||||
uiTextViewDelegate = delegateObject?.uiTextViewDelegate
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user