latest changes
This commit is contained in:
parent
aabd39616f
commit
64a99da609
@ -30,7 +30,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Validate on each entry in the textField. Default: true
|
/// Validate on each entry in the textView. Default: true
|
||||||
public var validateEachCharacter: Bool = true
|
public var validateEachCharacter: Bool = true
|
||||||
|
|
||||||
private var observingForChange: Bool = false
|
private var observingForChange: Bool = false
|
||||||
@ -55,7 +55,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
if self.textView.isShowingPlaceholder {
|
if self.textView.isShowingPlaceholder {
|
||||||
self.textView.textColor = self.textView.placeholderTextColor
|
self.textView.textColor = self.textView.placeholderTextColor
|
||||||
} else {
|
} else {
|
||||||
self.textView.textColor = enabled ? self.textViewEntryFieldModel?.enabledTextColor.uiColor : self.textViewEntryFieldModel?.disabledTextColor.uiColor
|
self.textView.textColor = (enabled ? self.textViewEntryFieldModel?.enabledTextColor : self.textViewEntryFieldModel?.disabledTextColor)?.uiColor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,7 +87,10 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
/// Placeholder access for the textView.
|
/// Placeholder access for the textView.
|
||||||
public var placeholder: String? {
|
public var placeholder: String? {
|
||||||
get { return textViewEntryFieldModel?.placeholder }
|
get { return textViewEntryFieldModel?.placeholder }
|
||||||
set { textViewEntryFieldModel?.placeholder = newValue }
|
set {
|
||||||
|
textViewEntryFieldModel?.placeholder = newValue
|
||||||
|
textView.placeholder = newValue ?? ""
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -100,19 +103,19 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
// MARK: - Delegate Properties
|
// MARK: - Delegate Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Holds a reference to the delegating class so this class can internally influence the TextField behavior as well.
|
/// Holds a reference to the delegating class so this class can internally influence the TextView behavior as well.
|
||||||
private weak var proprietorTextDelegate: UITextViewDelegate?
|
private weak var proprietorTextDelegate: UITextViewDelegate?
|
||||||
|
|
||||||
/// The delegate and block for validation. Validates if the text that the user has entered.
|
/// The delegate and block for validation. Validates if the text that the user has entered.
|
||||||
public weak var observingTextViewdDelegate: ObservingTextFieldDelegate? {
|
public weak var observingTextViewDelegate: ObservingTextFieldDelegate? {
|
||||||
didSet {
|
didSet {
|
||||||
if observingTextViewdDelegate != nil && !observingForChange {
|
if observingTextViewDelegate != nil && !observingForChange {
|
||||||
observingForChange = true
|
observingForChange = true
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(valueChanged), name: UITextView.textDidChangeNotification, 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(endInputing), name: UITextView.textDidEndEditingNotification, object: textView)
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextView.textDidBeginEditingNotification, object: textView)
|
NotificationCenter.default.addObserver(self, selector: #selector(startEditing), name: UITextView.textDidBeginEditingNotification, object: textView)
|
||||||
|
|
||||||
} else if observingTextViewdDelegate == nil && observingForChange {
|
} else if observingTextViewDelegate == nil && observingForChange {
|
||||||
observingForChange = false
|
observingForChange = false
|
||||||
NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, 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.textDidEndEditingNotification, object: textView)
|
||||||
@ -131,12 +134,12 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc public func setBothTextDelegates(to delegate: (UITextViewDelegate & ObservingTextFieldDelegate)?) {
|
@objc public func setBothTextDelegates(to delegate: (UITextViewDelegate & ObservingTextFieldDelegate)?) {
|
||||||
observingTextViewdDelegate = delegate
|
observingTextViewDelegate = delegate
|
||||||
uiTextViewDelegate = delegate
|
uiTextViewDelegate = delegate
|
||||||
}
|
}
|
||||||
|
|
||||||
open func setupTextViewToolbar() {
|
open func setupTextViewToolbar() {
|
||||||
let observingDelegate = observingTextViewdDelegate ?? self
|
let observingDelegate = observingTextViewDelegate ?? self
|
||||||
textView.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
|
textView.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
|
||||||
action: #selector(observingDelegate.dismissFieldInput))
|
action: #selector(observingDelegate.dismissFieldInput))
|
||||||
}
|
}
|
||||||
@ -161,17 +164,10 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
accessibilityElements = [titleLabel, textView, feedbackLabel]
|
accessibilityElements = [titleLabel, textView, feedbackLabel]
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc open override func updateView(_ size: CGFloat) {
|
|
||||||
super.updateView(size)
|
|
||||||
|
|
||||||
textView.font = Styler.Font.RegularBodyLarge.getFont()
|
|
||||||
layoutIfNeeded()
|
|
||||||
}
|
|
||||||
|
|
||||||
open override func reset() {
|
open override func reset() {
|
||||||
super.reset()
|
super.reset()
|
||||||
|
|
||||||
textView.font = Styler.Font.RegularBodyLarge.getFont()
|
textView.reset()
|
||||||
heightConstraint?.constant = 0
|
heightConstraint?.constant = 0
|
||||||
heightConstraint?.isActive = false
|
heightConstraint?.isActive = false
|
||||||
}
|
}
|
||||||
@ -181,27 +177,26 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|
||||||
/// Validates the text of the entry field.
|
/// Validates the text of the entry field.
|
||||||
@objc public func validateTextField() {
|
@objc public func validateTextView() {
|
||||||
text = textView.text
|
text = textView.text
|
||||||
if let isValid = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) {
|
if let isValid = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) {
|
||||||
self.isValid = isValid
|
self.isValid = isValid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextField.textDidBeginEditingNotification
|
/// Executes on UITextView.textDidBeginEditingNotification
|
||||||
@objc func startEditing() {
|
@objc func startEditing() {
|
||||||
isSelected = true
|
isSelected = true
|
||||||
textView.becomeFirstResponder()
|
_ = textView.becomeFirstResponder()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextField.textDidChangeNotification (each character entry)
|
/// Executes on UITextView.textDidChangeNotification (each character entry)
|
||||||
@objc func valueChanged() {
|
@objc func valueChanged() {
|
||||||
guard validateEachCharacter else { return }
|
guard validateEachCharacter else { return }
|
||||||
isSelected = true
|
validateTextView()
|
||||||
validateTextField()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Executes on UITextField.textDidEndEditingNotification
|
/// Executes on UITextView.textDidEndEditingNotification
|
||||||
@objc func endInputing() {
|
@objc func endInputing() {
|
||||||
resignFirstResponder()
|
resignFirstResponder()
|
||||||
if isValid {
|
if isValid {
|
||||||
@ -210,7 +205,6 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - UITextViewDelegate
|
// MARK: - UITextViewDelegate
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -233,7 +227,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
|
|
||||||
@objc public func textViewDidChange(_ textView: UITextView) {
|
@objc public func textViewDidChange(_ textView: UITextView) {
|
||||||
|
|
||||||
validateTextField()
|
validateTextView()
|
||||||
proprietorTextDelegate?.textViewDidChange?(textView)
|
proprietorTextDelegate?.textViewDidChange?(textView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,10 +299,9 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
|
|||||||
textView.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
|
textView.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
|
||||||
action: #selector(textView.dismissFieldInput))
|
action: #selector(textView.dismissFieldInput))
|
||||||
|
|
||||||
if (model.selected ?? false) && !model.wasInitiallySelected {
|
if isSelected {
|
||||||
model.wasInitiallySelected = true
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
self.becomeFirstResponder()
|
_ = self.textView.becomeFirstResponder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,7 +25,7 @@ import UIKit
|
|||||||
public var hideBlinkingCaret = false
|
public var hideBlinkingCaret = false
|
||||||
|
|
||||||
public var placeholder = ""
|
public var placeholder = ""
|
||||||
public var fontStyle: Styler.Font = Styler.Font.RegularBodySmall
|
public var fontStyle: Styler.Font = Styler.Font.RegularBodyLarge
|
||||||
public var placeholderFontStyle: Styler.Font = Styler.Font.RegularMicro
|
public var placeholderFontStyle: Styler.Font = Styler.Font.RegularMicro
|
||||||
public var placeholderTextColor: UIColor = .mvmCoolGray3
|
public var placeholderTextColor: UIColor = .mvmCoolGray3
|
||||||
|
|
||||||
@ -181,6 +181,6 @@ import UIKit
|
|||||||
|
|
||||||
@objc open func dismissFieldInput(_ sender: TextView) {
|
@objc open func dismissFieldInput(_ sender: TextView) {
|
||||||
|
|
||||||
_ = resignFirstResponder()
|
resignFirstResponder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,7 +17,7 @@ import UIKit
|
|||||||
public var manager: (UIViewController & MVMCoreViewManagerProtocol)?
|
public var manager: (UIViewController & MVMCoreViewManagerProtocol)?
|
||||||
|
|
||||||
/// A temporary iVar backer for delegateObject() until we change the protocol
|
/// A temporary iVar backer for delegateObject() until we change the protocol
|
||||||
public let delegateObjectIVar: MVMCoreUIDelegateObject = {
|
public lazy var delegateObjectIVar: MVMCoreUIDelegateObject = {
|
||||||
return MVMCoreUIDelegateObject.create(withDelegateForAll: self)
|
return MVMCoreUIDelegateObject.create(withDelegateForAll: self)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user