From 8bb6a7fb1d078c4af10dbcce574e106c08164b7f Mon Sep 17 00:00:00 2001 From: Kevin G Christiano Date: Wed, 29 Apr 2020 11:23:49 -0400 Subject: [PATCH] latest state of text view --- MVMCoreUI/BaseClasses/TextView.swift | 26 +++++++++++++++++------ MVMCoreUI/BaseClasses/TextViewModel.swift | 6 ++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/MVMCoreUI/BaseClasses/TextView.swift b/MVMCoreUI/BaseClasses/TextView.swift index fc8695a1..9136424f 100644 --- a/MVMCoreUI/BaseClasses/TextView.swift +++ b/MVMCoreUI/BaseClasses/TextView.swift @@ -19,9 +19,8 @@ import UIKit private var initialSetupPerformed = false /// If true then text textView is currently displaying the stored placeholder text as there is not content to display. - public var isShowingPlaceholder: Bool { - get { return textViewModel?.showsPlaceholder ?? false } - set { textViewModel?.showsPlaceholder = newValue } + public var isShowingPlaceholder: Bool = false { + didSet { textViewModel?.showsPlaceholder = isShowingPlaceholder } } /// Set to true to hide the blinking textField cursor. @@ -183,6 +182,7 @@ import UIKit insetsLayoutMarginsFromSafeArea = false showsVerticalScrollIndicator = false showsHorizontalScrollIndicator = false + isSecureTextEntry = false textContainerInset = UIEdgeInsets(top: Padding.Three, left: Padding.Three, bottom: Padding.Three, right: Padding.Three) backgroundColor = .mvmWhite clipsToBounds = true @@ -219,12 +219,13 @@ import UIKit bottomPath.removeAllPoints() if !hideBorders { - // Brings the other half of the line inside the view to prevent cropping. + // Brings the other half of the line inside the view to prevent line cropping. let origin = bounds.origin let size = frame.size let insetLean: CGFloat = 0.5 borderPath.lineWidth = 1 + // Drawing begins and ends from the bottom left. borderPath.move(to: CGPoint(x: origin.x + insetLean, y: origin.y + size.height)) borderPath.addLine(to: CGPoint(x: origin.x + insetLean, y: origin.y + insetLean)) borderPath.addLine(to: CGPoint(x: origin.x + size.width - insetLean, y: origin.y + insetLean)) @@ -284,7 +285,7 @@ import UIKit hideBorders = textViewModel?.hideBorders ?? false borderStrokeColor = .mvmCoolGray3 bottomStrokeColor = .mvmBlack - textColor = textViewModel?.enabledTextColor.uiColor + textColor = isShowingPlaceholder ? textViewModel?.placeholderTextColor.uiColor : textViewModel?.enabledTextColor.uiColor } open func errorUI() { @@ -388,8 +389,8 @@ import UIKit @objc public func textViewDidBeginEditing(_ textView: UITextView) { - isSelected = true setTextAppearance() + isSelected = true proprietorTextDelegate?.textViewDidBeginEditing?(textView) } @@ -411,8 +412,8 @@ import UIKit @objc public func textViewDidEndEditing(_ textView: UITextView) { - isSelected = false setPlaceholderIfAvailable() + isSelected = false proprietorTextDelegate?.textViewDidEndEditing?(textView) } } @@ -447,6 +448,17 @@ extension TextView: MoleculeViewProtocol { accessibilityLabel = accessibilityText } + switch model.type { + case .secure, .password: + isSecureTextEntry = true + case .number: + keyboardType = .numberPad + case .email: + keyboardType = .emailAddress + default: + break + } + font = model.fontStyle.getFont() setPlaceholderIfAvailable() diff --git a/MVMCoreUI/BaseClasses/TextViewModel.swift b/MVMCoreUI/BaseClasses/TextViewModel.swift index 48b14754..3574d2b9 100644 --- a/MVMCoreUI/BaseClasses/TextViewModel.swift +++ b/MVMCoreUI/BaseClasses/TextViewModel.swift @@ -40,6 +40,7 @@ open class TextViewModel: TextEntryFieldModel { case height case hideBorders case placeholderFontStyle + case placeholderTextColor case isEditable = "editable" } @@ -55,6 +56,10 @@ open class TextViewModel: TextEntryFieldModel { self.placeholderFontStyle = placeholderFontStyle } + if let placeholderTextColor = try typeContainer.decodeIfPresent(Color.self, forKey: .placeholderTextColor) { + self.placeholderTextColor = placeholderTextColor + } + if let textAlignment = try typeContainer.decodeIfPresent(NSTextAlignment.self, forKey: .textAlignment) { self.textAlignment = textAlignment } @@ -83,6 +88,7 @@ open class TextViewModel: TextEntryFieldModel { try container.encodeIfPresent(hideBorders, forKey: .hideBorders) try container.encode(text, forKey: .text) try container.encode(placeholderFontStyle, forKey: .placeholderFontStyle) + try container.encode(placeholderTextColor, forKey: .placeholderTextColor) try container.encode(textAlignment, forKey: .textAlignment) try container.encode(isEditable, forKey: .isEditable) }