latest state of text view

This commit is contained in:
Kevin G Christiano 2020-04-29 11:23:49 -04:00
parent 19f912512b
commit 8bb6a7fb1d
2 changed files with 25 additions and 7 deletions

View File

@ -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()

View File

@ -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)
}