latest changes

This commit is contained in:
Kevin G Christiano 2020-05-12 15:30:32 -04:00
parent aabd39616f
commit 64a99da609
3 changed files with 25 additions and 32 deletions

View File

@ -30,7 +30,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
// 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
private var observingForChange: Bool = false
@ -55,7 +55,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
if self.textView.isShowingPlaceholder {
self.textView.textColor = self.textView.placeholderTextColor
} 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.
public var placeholder: String? {
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
//--------------------------------------------------
/// 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?
/// 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 {
if observingTextViewdDelegate != nil && !observingForChange {
if observingTextViewDelegate != 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)
} else if observingTextViewdDelegate == nil && observingForChange {
} else if observingTextViewDelegate == nil && observingForChange {
observingForChange = false
NotificationCenter.default.removeObserver(self, name: UITextView.textDidChangeNotification, 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)?) {
observingTextViewdDelegate = delegate
observingTextViewDelegate = delegate
uiTextViewDelegate = delegate
}
open func setupTextViewToolbar() {
let observingDelegate = observingTextViewdDelegate ?? self
let observingDelegate = observingTextViewDelegate ?? self
textView.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
action: #selector(observingDelegate.dismissFieldInput))
}
@ -161,17 +164,10 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
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() {
super.reset()
textView.font = Styler.Font.RegularBodyLarge.getFont()
textView.reset()
heightConstraint?.constant = 0
heightConstraint?.isActive = false
}
@ -181,27 +177,26 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
//--------------------------------------------------
/// Validates the text of the entry field.
@objc public func validateTextField() {
@objc public func validateTextView() {
text = textView.text
if let isValid = FormValidator.validate(delegate: delegateObject?.formHolderDelegate) {
self.isValid = isValid
}
}
/// Executes on UITextField.textDidBeginEditingNotification
/// Executes on UITextView.textDidBeginEditingNotification
@objc func startEditing() {
isSelected = true
textView.becomeFirstResponder()
_ = textView.becomeFirstResponder()
}
/// Executes on UITextField.textDidChangeNotification (each character entry)
/// Executes on UITextView.textDidChangeNotification (each character entry)
@objc func valueChanged() {
guard validateEachCharacter else { return }
isSelected = true
validateTextField()
validateTextView()
}
/// Executes on UITextField.textDidEndEditingNotification
/// Executes on UITextView.textDidEndEditingNotification
@objc func endInputing() {
resignFirstResponder()
if isValid {
@ -210,7 +205,6 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
}
}
//--------------------------------------------------
// MARK: - UITextViewDelegate
//--------------------------------------------------
@ -233,7 +227,7 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
@objc public func textViewDidChange(_ textView: UITextView) {
validateTextField()
validateTextView()
proprietorTextDelegate?.textViewDidChange?(textView)
}
@ -305,10 +299,9 @@ class TextViewEntryField: EntryField, UITextViewDelegate, ObservingTextFieldDele
textView.inputAccessoryView = UIToolbar.getToolbarWithDoneButton(delegate: observingDelegate,
action: #selector(textView.dismissFieldInput))
if (model.selected ?? false) && !model.wasInitiallySelected {
model.wasInitiallySelected = true
if isSelected {
DispatchQueue.main.async {
self.becomeFirstResponder()
_ = self.textView.becomeFirstResponder()
}
}
}

View File

@ -25,7 +25,7 @@ import UIKit
public var hideBlinkingCaret = false
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 placeholderTextColor: UIColor = .mvmCoolGray3
@ -181,6 +181,6 @@ import UIKit
@objc open func dismissFieldInput(_ sender: TextView) {
_ = resignFirstResponder()
resignFirstResponder()
}
}

View File

@ -17,7 +17,7 @@ import UIKit
public var manager: (UIViewController & MVMCoreViewManagerProtocol)?
/// 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)
}()