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