From 01ef563f70190296cc171e8be900b7ca43063d14 Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Thu, 9 Apr 2020 08:12:49 -0400 Subject: [PATCH] txtv --- MVMCoreUI/BaseClasses/TextView.swift | 64 ++++++++-------------------- 1 file changed, 18 insertions(+), 46 deletions(-) diff --git a/MVMCoreUI/BaseClasses/TextView.swift b/MVMCoreUI/BaseClasses/TextView.swift index 6e80b623..bc1c2133 100644 --- a/MVMCoreUI/BaseClasses/TextView.swift +++ b/MVMCoreUI/BaseClasses/TextView.swift @@ -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 {