This commit is contained in:
Kevin G Christiano 2020-04-09 08:12:49 -04:00
parent 6e96be982b
commit 01ef563f70

View File

@ -18,43 +18,13 @@ import UIKit
private var initialSetupPerformed = false private var initialSetupPerformed = false
public var isShowingPlaceholder = true
/// Set to true to hide the blinking textField cursor. /// Set to true to hide the blinking textField cursor.
public var hideBlinkingCaret = false public var hideBlinkingCaret = false
private var textTraits: (color: UIColor, font: UIFont) = (color: .mvmBlack, font: MFStyler.fontRegularBodySmall()) private var textTraits: (color: UIColor, font: UIFont) = (color: .mvmBlack, font: MFStyler.fontRegularBodySmall())
private var placeholderTraits: (color: UIColor, font: UIFont) = (color: .mvmCoolGray3, font: MFStyler.fontRegularMicro() ) private var placeholderTraits: (text: String, color: UIColor, font: UIFont) = (text: "", color: .mvmCoolGray3, font: MFStyler.fontRegularMicro() )
public var placeholderFont: UIFont = MFStyler.fontRegularMicro() {
didSet {
if text.isEmpty {
font = placeholderFont
}
}
}
public var placeholder: String = "" {
didSet {
if text.isEmpty {
text = placeholder
}
}
}
public var placeholderTextColor: UIColor = .mvmCoolGray3
public var showsPlaceholder = true
public var isShowingPlaceholder = true {
didSet {
textColor = isShowingPlaceholder ? placeholderTextColor : .mvmBlack
font = isShowingPlaceholder ? placeholderFont : textFont
if isShowingPlaceholder {
text = placeholder
}
}
}
private(set) var textFont: UIFont = MFStyler.fontRegularBodySmall()
//-------------------------------------------------- //--------------------------------------------------
// MARK: - Delegate // MARK: - Delegate
@ -102,8 +72,7 @@ import UIKit
convenience init(placeholderText: String, delegate: UITextViewDelegate?) { convenience init(placeholderText: String, delegate: UITextViewDelegate?) {
self.init(frame: .zero, textContainer: nil) self.init(frame: .zero, textContainer: nil)
self.delegate = delegate self.delegate = delegate
showsPlaceholder = true self.placeholderTraits.text = placeholderText
self.placeholder = placeholderText
} }
public func initialSetup() { public func initialSetup() {
@ -128,12 +97,20 @@ import UIKit
open override func deleteBackward() { open override func deleteBackward() {
super.deleteBackward() super.deleteBackward()
didDeleteDelegate?.textFieldDidDelete() didDeleteDelegate?.textFieldDidDelete()
}
open func setTextViewState() {
if isShowingPlaceholder { if isShowingPlaceholder {
text = "" text = ""
font = textTraits.font
textColor = textTraits.color
isShowingPlaceholder = false isShowingPlaceholder = false
} else if text.isEmpty { } else if text.isEmpty {
isShowingPlaceholder = true isShowingPlaceholder = true
textColor = placeholderTraits.color
text = placeholderTraits.text
font = placeholderTraits.font
} }
} }
@ -141,12 +118,6 @@ import UIKit
// MARK: - UITextViewDelegate // MARK: - UITextViewDelegate
//-------------------------------------------------- //--------------------------------------------------
/// Executes on UITextView.textDidEndEditingNotification
@objc open func dismissFieldInput() {
resignFirstResponder()
}
//#pragma Mark UITextView Delegate methods forwarding //#pragma Mark UITextView Delegate methods forwarding
@objc public func textViewShouldBeginEditing(_ textView: UITextView) -> Bool { @objc public func textViewShouldBeginEditing(_ textView: UITextView) -> Bool {
@ -165,6 +136,8 @@ import UIKit
@objc public func textViewDidChange(_ textView: UITextView) { @objc public func textViewDidChange(_ textView: UITextView) {
setTextViewState()
proprietorTextDelegate?.textViewDidChange?(textView) proprietorTextDelegate?.textViewDidChange?(textView)
} }
@ -196,7 +169,7 @@ extension TextView: MVMCoreViewProtocol {
smartQuotesType = .no smartQuotesType = .no
smartDashesType = .no smartDashesType = .no
smartInsertDeleteType = .no smartInsertDeleteType = .no
font = textFont font = textTraits.font
layer.borderWidth = 1 layer.borderWidth = 1
layer.borderColor = UIColor.mvmBlack.cgColor layer.borderColor = UIColor.mvmBlack.cgColor
isEditable = true isEditable = true
@ -225,13 +198,12 @@ extension TextView: MoleculeViewProtocol {
textColor = model.textColor.uiColor textColor = model.textColor.uiColor
layer.borderColor = model.borderColor?.cgColor layer.borderColor = model.borderColor?.cgColor
layer.borderWidth = model.borderWidth layer.borderWidth = model.borderWidth
// font = model.fontStyle // font = model.fontStyle
// placeholderFont = model.placeholderFont
text = model.text text = model.text
isShowingPlaceholder = model.text.isEmpty isShowingPlaceholder = model.text.isEmpty
placeholder = model.placeholder placeholderTraits.text = model.placeholder
// placeholderFont = model.placeholderFont
uiTextViewDelegate = delegateObject?.uiTextViewDelegate uiTextViewDelegate = delegateObject?.uiTextViewDelegate
if let accessibilityText = model.accessibilityText { if let accessibilityText = model.accessibilityText {